Class: Shugoi::Config
- Inherits:
-
Object
- Object
- Shugoi::Config
- Defined in:
- lib/shugoi/config.rb
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: 14, pow_ttl_ms: 60_000 }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #allowlist ⇒ Object
- #allowlisted?(path) ⇒ Boolean
- #auto_inject ⇒ Object
- #base_url ⇒ Object
- #block_page ⇒ Object
- #block_status ⇒ Object
- #bot_whitelist ⇒ Object
- #csp_enabled ⇒ Object
- #debug ⇒ Object
- #extra_directives ⇒ Object
- #headless?(ua) ⇒ Boolean
- #headless_patterns ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #internal_url ⇒ Object
- #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
- #whitelisted_bot?(ua) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
29 30 31 32 |
# File 'lib/shugoi/config.rb', line 29 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.
27 28 29 |
# File 'lib/shugoi/config.rb', line 27 def @options end |
Instance Method Details
#allowlist ⇒ Object
37 |
# File 'lib/shugoi/config.rb', line 37 def allowlist = @options[:allowlist] |
#allowlisted?(path) ⇒ Boolean
56 57 58 |
# File 'lib/shugoi/config.rb', line 56 def allowlisted?(path) allowlist.any? { |p| path == p || path.start_with?("#{p}/") } end |
#auto_inject ⇒ Object
43 |
# File 'lib/shugoi/config.rb', line 43 def auto_inject = @options[:auto_inject] |
#base_url ⇒ Object
40 |
# File 'lib/shugoi/config.rb', line 40 def base_url = @options[:base_url] |
#block_page ⇒ Object
49 |
# File 'lib/shugoi/config.rb', line 49 def block_page = @options[:block_page] |
#block_status ⇒ Object
47 |
# File 'lib/shugoi/config.rb', line 47 def block_status = @options[:block_status] |
#bot_whitelist ⇒ Object
39 |
# File 'lib/shugoi/config.rb', line 39 def bot_whitelist = @options[:bot_whitelist] |
#csp_enabled ⇒ Object
46 |
# File 'lib/shugoi/config.rb', line 46 def csp_enabled = @options[:csp] |
#debug ⇒ Object
42 |
# File 'lib/shugoi/config.rb', line 42 def debug = @options[:debug] |
#extra_directives ⇒ Object
45 |
# File 'lib/shugoi/config.rb', line 45 def extra_directives = @options[:extra_directives] |
#headless?(ua) ⇒ Boolean
64 65 66 |
# File 'lib/shugoi/config.rb', line 64 def headless?(ua) headless_patterns.any? { |p| p.match?(ua) } end |
#headless_patterns ⇒ Object
38 |
# File 'lib/shugoi/config.rb', line 38 def headless_patterns = @options[:headless_patterns] |
#internal_url ⇒ Object
41 |
# File 'lib/shugoi/config.rb', line 41 def internal_url = @options[:internal_url] || @options[:base_url] |
#locale ⇒ Object
48 |
# File 'lib/shugoi/config.rb', line 48 def locale = @options[:locale] |
#multi_process ⇒ Object
51 |
# File 'lib/shugoi/config.rb', line 51 def multi_process = @options[:multi_process] |
#pow_difficulty ⇒ Object
53 |
# File 'lib/shugoi/config.rb', line 53 def pow_difficulty = @options[:pow_difficulty] |
#pow_ttl_ms ⇒ Object
54 |
# File 'lib/shugoi/config.rb', line 54 def pow_ttl_ms = @options[:pow_ttl_ms] |
#restricted_access ⇒ Object
44 |
# File 'lib/shugoi/config.rb', line 44 def restricted_access = @options[:restricted_access] |
#secret ⇒ Object
35 |
# File 'lib/shugoi/config.rb', line 35 def secret = @options[:secret] |
#signing_secret ⇒ Object
36 |
# File 'lib/shugoi/config.rb', line 36 def signing_secret = @options[:signing_secret] || @options[:secret] |
#site_key ⇒ Object
34 |
# File 'lib/shugoi/config.rb', line 34 def site_key = @options[:site_key] |
#split_render ⇒ Object
50 |
# File 'lib/shugoi/config.rb', line 50 def split_render = @options[:split_render] |
#verify_bots ⇒ Object
52 |
# File 'lib/shugoi/config.rb', line 52 def verify_bots = @options[:verify_bots] |
#whitelisted_bot?(ua) ⇒ Boolean
60 61 62 |
# File 'lib/shugoi/config.rb', line 60 def whitelisted_bot?(ua) bot_whitelist.any? { |p| p.match?(ua) } end |