Class: Shugoi::Config
- Inherits:
-
Object
- Object
- Shugoi::Config
- Defined in:
- lib/shugoi/config.rb
Overview
Options du middleware — parité avec ShugoiCoreOptions (module Node).
Constant Summary collapse
- DEFAULTS =
{ site_key: nil, secret: nil, signing_secret: nil, allowlist: ["/api", "/legal"], headless_patterns: Shugoi::DEFAULT_HEADLESS_PATTERNS, bot_whitelist: Shugoi::DEFAULT_BOT_WHITELIST, base_url: "https://shugoi.com/api/v1", internal_url: nil, debug: false, auto_inject: true, restricted_access: false, extra_directives: {}, csp: true, block_status: 403, locale: nil, block_page: nil, split_render: true, multi_process: false, verify_bots: true, pow_difficulty: 10, pow_ttl_ms: 120_000 }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #allowlist ⇒ Object
- #auto_inject ⇒ Object
- #base_url ⇒ Object
- #block_page ⇒ Object
- #block_status ⇒ Object
- #bot_whitelist ⇒ Object
- #csp_enabled ⇒ Object
- #debug ⇒ Object
- #extra_directives ⇒ Object
- #headless_patterns ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #internal_url ⇒ Object
- #is_allowlisted?(path) ⇒ Boolean
- #is_headless?(ua) ⇒ Boolean
- #is_whitelisted_bot?(ua) ⇒ Boolean
- #locale ⇒ Object
- #multi_process ⇒ Object
- #pow_difficulty ⇒ Object
- #pow_ttl_ms ⇒ Object
- #restricted_access ⇒ Object
- #secret ⇒ Object
- #signing_secret ⇒ Object
- #site_key ⇒ Object
- #split_render ⇒ Object
- #verify_bots ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
32 33 34 35 |
# File 'lib/shugoi/config.rb', line 32 def initialize( = {}) @options = DEFAULTS.merge(symbolize()) raise ConfigError, "site_key is required" if @options[:site_key].nil? end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
30 31 32 |
# File 'lib/shugoi/config.rb', line 30 def @options end |
Instance Method Details
#allowlist ⇒ Object
40 |
# File 'lib/shugoi/config.rb', line 40 def allowlist = @options[:allowlist] |
#auto_inject ⇒ Object
46 |
# File 'lib/shugoi/config.rb', line 46 def auto_inject = @options[:auto_inject] |
#base_url ⇒ Object
43 |
# File 'lib/shugoi/config.rb', line 43 def base_url = @options[:base_url] |
#block_page ⇒ Object
52 |
# File 'lib/shugoi/config.rb', line 52 def block_page = @options[:block_page] |
#block_status ⇒ Object
50 |
# File 'lib/shugoi/config.rb', line 50 def block_status = @options[:block_status] |
#bot_whitelist ⇒ Object
42 |
# File 'lib/shugoi/config.rb', line 42 def bot_whitelist = @options[:bot_whitelist] |
#csp_enabled ⇒ Object
49 |
# File 'lib/shugoi/config.rb', line 49 def csp_enabled = @options[:csp] |
#debug ⇒ Object
45 |
# File 'lib/shugoi/config.rb', line 45 def debug = @options[:debug] |
#extra_directives ⇒ Object
48 |
# File 'lib/shugoi/config.rb', line 48 def extra_directives = @options[:extra_directives] |
#headless_patterns ⇒ Object
41 |
# File 'lib/shugoi/config.rb', line 41 def headless_patterns = @options[:headless_patterns] |
#internal_url ⇒ Object
44 |
# File 'lib/shugoi/config.rb', line 44 def internal_url = @options[:internal_url] || @options[:base_url] |
#is_allowlisted?(path) ⇒ Boolean
59 60 61 |
# File 'lib/shugoi/config.rb', line 59 def is_allowlisted?(path) allowlist.any? { |p| path == p || path.start_with?("#{p}/") } end |
#is_headless?(ua) ⇒ Boolean
67 68 69 |
# File 'lib/shugoi/config.rb', line 67 def is_headless?(ua) headless_patterns.any? { |p| p.match?(ua) } end |
#is_whitelisted_bot?(ua) ⇒ Boolean
63 64 65 |
# File 'lib/shugoi/config.rb', line 63 def is_whitelisted_bot?(ua) bot_whitelist.any? { |p| p.match?(ua) } end |
#locale ⇒ Object
51 |
# File 'lib/shugoi/config.rb', line 51 def locale = @options[:locale] |
#multi_process ⇒ Object
54 |
# File 'lib/shugoi/config.rb', line 54 def multi_process = @options[:multi_process] |
#pow_difficulty ⇒ Object
56 |
# File 'lib/shugoi/config.rb', line 56 def pow_difficulty = @options[:pow_difficulty] |
#pow_ttl_ms ⇒ Object
57 |
# File 'lib/shugoi/config.rb', line 57 def pow_ttl_ms = @options[:pow_ttl_ms] |
#restricted_access ⇒ Object
47 |
# File 'lib/shugoi/config.rb', line 47 def restricted_access = @options[:restricted_access] |
#secret ⇒ Object
38 |
# File 'lib/shugoi/config.rb', line 38 def secret = @options[:secret] |
#signing_secret ⇒ Object
39 |
# File 'lib/shugoi/config.rb', line 39 def signing_secret = @options[:signing_secret] || @options[:secret] |
#site_key ⇒ Object
37 |
# File 'lib/shugoi/config.rb', line 37 def site_key = @options[:site_key] |
#split_render ⇒ Object
53 |
# File 'lib/shugoi/config.rb', line 53 def split_render = @options[:split_render] |
#verify_bots ⇒ Object
55 |
# File 'lib/shugoi/config.rb', line 55 def verify_bots = @options[:verify_bots] |