Class: Shugoi::Config

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.

Raises:



29
30
31
32
# File 'lib/shugoi/config.rb', line 29

def initialize(options = {})
  @options = DEFAULTS.merge(symbolize(options))
  raise ConfigError, "site_key is required" if @options[:site_key].nil?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



27
28
29
# File 'lib/shugoi/config.rb', line 27

def options
  @options
end

Instance Method Details

#allowlistObject



37
# File 'lib/shugoi/config.rb', line 37

def allowlist = @options[:allowlist]

#allowlisted?(path) ⇒ Boolean

Returns:

  • (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_injectObject



43
# File 'lib/shugoi/config.rb', line 43

def auto_inject = @options[:auto_inject]

#base_urlObject



40
# File 'lib/shugoi/config.rb', line 40

def base_url = @options[:base_url]

#block_pageObject



49
# File 'lib/shugoi/config.rb', line 49

def block_page = @options[:block_page]

#block_statusObject



47
# File 'lib/shugoi/config.rb', line 47

def block_status = @options[:block_status]

#bot_whitelistObject



39
# File 'lib/shugoi/config.rb', line 39

def bot_whitelist = @options[:bot_whitelist]

#csp_enabledObject



46
# File 'lib/shugoi/config.rb', line 46

def csp_enabled = @options[:csp]

#debugObject



42
# File 'lib/shugoi/config.rb', line 42

def debug = @options[:debug]

#extra_directivesObject



45
# File 'lib/shugoi/config.rb', line 45

def extra_directives = @options[:extra_directives]

#headless?(ua) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/shugoi/config.rb', line 64

def headless?(ua)
  headless_patterns.any? { |p| p.match?(ua) }
end

#headless_patternsObject



38
# File 'lib/shugoi/config.rb', line 38

def headless_patterns = @options[:headless_patterns]

#internal_urlObject



41
# File 'lib/shugoi/config.rb', line 41

def internal_url = @options[:internal_url] || @options[:base_url]

#localeObject



48
# File 'lib/shugoi/config.rb', line 48

def locale = @options[:locale]

#multi_processObject



51
# File 'lib/shugoi/config.rb', line 51

def multi_process = @options[:multi_process]

#pow_difficultyObject



53
# File 'lib/shugoi/config.rb', line 53

def pow_difficulty = @options[:pow_difficulty]

#pow_ttl_msObject



54
# File 'lib/shugoi/config.rb', line 54

def pow_ttl_ms = @options[:pow_ttl_ms]

#restricted_accessObject



44
# File 'lib/shugoi/config.rb', line 44

def restricted_access = @options[:restricted_access]

#secretObject



35
# File 'lib/shugoi/config.rb', line 35

def secret = @options[:secret]

#signing_secretObject



36
# File 'lib/shugoi/config.rb', line 36

def signing_secret = @options[:signing_secret] || @options[:secret]

#site_keyObject



34
# File 'lib/shugoi/config.rb', line 34

def site_key = @options[:site_key]

#split_renderObject



50
# File 'lib/shugoi/config.rb', line 50

def split_render = @options[:split_render]

#verify_botsObject



52
# File 'lib/shugoi/config.rb', line 52

def verify_bots = @options[:verify_bots]

#whitelisted_bot?(ua) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/shugoi/config.rb', line 60

def whitelisted_bot?(ua)
  bot_whitelist.any? { |p| p.match?(ua) }
end