Class: Trackets::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/trackets/configuration.rb

Constant Summary collapse

DEFAULT_WHITELISTED_ENV_KEYS =
[
  "REQUEST_METHOD",
  "PATH_INFO",
  "QUERY_STRING",
  "SCRIPT_NAME",
  "REMOTE_ADDR",
  "SERVER_ADDR",
  "SERVER_NAME",
  "SERVER_PORT",
  "HTTP_HOST",
  "HTTP_CONNECTION",
  "CONTENT_LENGTH",
  "HTTP_ACCEPT",
  "HTTP_ORIGIN",
  "HTTP_USER_AGENT",
  "CONTENT_TYPE",
  "HTTP_REFERER",
  "HTTP_ACCEPT_ENCODING",
  "HTTP_ACCEPT_LANGUAGE",
  "REMOTE_PORT",
  "ORIGINAL_FULLPATH"
].freeze
DEFAULT_BLACKLISTED_PARAMS =
["password", "password_confirmation", "card_number", "cvv"].freeze
DEFAULT_API_URL =
"https://trackets.com"
DEFAULT_LOAD_PLUGINS =
[:sidekiq]
DEFAULT_ENABLED_ENV =
[:production]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



37
38
39
40
41
42
43
44
45
# File 'lib/trackets/configuration.rb', line 37

def initialize
  @api_url = DEFAULT_API_URL
  @whitelisted_env = DEFAULT_WHITELISTED_ENV_KEYS
  @blacklisted_params = DEFAULT_BLACKLISTED_PARAMS
  @async = false
  @load_plugins = DEFAULT_LOAD_PLUGINS
  @enabled_env = DEFAULT_ENABLED_ENV
  @force = false
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def api_url
  @api_url
end

#asyncObject Also known as: async?

Returns the value of attribute async.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def async
  @async
end

#blacklisted_paramsObject

Returns the value of attribute blacklisted_params.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def blacklisted_params
  @blacklisted_params
end

#enabled_envObject

Returns the value of attribute enabled_env.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def enabled_env
  @enabled_env
end

#environment_nameObject

Returns the value of attribute environment_name.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def environment_name
  @environment_name
end

#forceObject Also known as: force?

Returns the value of attribute force.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def force
  @force
end

#frameworkObject

Returns the value of attribute framework.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def framework
  @framework
end

#load_pluginsObject

Returns the value of attribute load_plugins.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def load_plugins
  @load_plugins
end

#private_api_keyObject

Returns the value of attribute private_api_key.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def private_api_key
  @private_api_key
end

#project_rootObject

Returns the value of attribute project_root.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def project_root
  @project_root
end

#public_api_keyObject

Returns the value of attribute public_api_key.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def public_api_key
  @public_api_key
end

#whitelisted_envObject

Returns the value of attribute whitelisted_env.



31
32
33
# File 'lib/trackets/configuration.rb', line 31

def whitelisted_env
  @whitelisted_env
end

Instance Method Details

#blacklisted_key?(key, rack_env = nil) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/trackets/configuration.rb', line 55

def blacklisted_key?(key, rack_env = nil)
  blacklisted_keys.include?(key)
end

#blacklisted_keys(rack_env = nil) ⇒ Object



51
52
53
# File 'lib/trackets/configuration.rb', line 51

def blacklisted_keys(rack_env = nil)
  @blacklisted_keys ||= (blacklisted_params + rack_filter_keys).map(&:to_s)
end

#enabled?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/trackets/configuration.rb', line 59

def enabled?
  enabled_env.include?(environment_name.to_sym) || force?
end

#rack_filter_keys(rack_env = nil) ⇒ Object



47
48
49
# File 'lib/trackets/configuration.rb', line 47

def rack_filter_keys(rack_env = nil)
  @rack_filter_keys ||= rack_env ? Array(rack_env["action_dispatch.parameter_filter"]) : []
end