Class: Overule::Configuration
- Inherits:
-
Object
- Object
- Overule::Configuration
- Defined in:
- lib/overule/configuration.rb
Overview
Host-app configuration for the Overule gem. Populate via the initializer the install generator drops at ‘config/initializers/overule.rb`, or call `Overule.configure { |c| … }` directly from non-Rails code.
Constant Summary collapse
- SUPPORTED_ORMS =
%i[active_record mongoid].freeze
Instance Attribute Summary collapse
-
#actor_proc ⇒ Object
Returns the value of attribute actor_proc.
-
#http_basic_auth ⇒ Object
Returns the value of attribute http_basic_auth.
-
#http_basic_auth_password ⇒ Object
Returns the value of attribute http_basic_auth_password.
-
#http_basic_auth_username ⇒ Object
Returns the value of attribute http_basic_auth_username.
-
#orm ⇒ Object
Returns the value of attribute orm.
Instance Method Summary collapse
- #actor_for(controller) ⇒ Object
- #http_basic_auth_configured? ⇒ Boolean
-
#http_basic_auth_matches?(username, password) ⇒ Boolean
Returns true iff the given credentials match the configured username and password.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
16 17 18 19 20 21 22 |
# File 'lib/overule/configuration.rb', line 16 def initialize @orm = :active_record @actor_proc = nil @http_basic_auth = false @http_basic_auth_username = nil @http_basic_auth_password = nil end |
Instance Attribute Details
#actor_proc ⇒ Object
Returns the value of attribute actor_proc.
11 12 13 |
# File 'lib/overule/configuration.rb', line 11 def actor_proc @actor_proc end |
#http_basic_auth ⇒ Object
Returns the value of attribute http_basic_auth.
11 12 13 |
# File 'lib/overule/configuration.rb', line 11 def http_basic_auth @http_basic_auth end |
#http_basic_auth_password ⇒ Object
Returns the value of attribute http_basic_auth_password.
11 12 13 |
# File 'lib/overule/configuration.rb', line 11 def http_basic_auth_password @http_basic_auth_password end |
#http_basic_auth_username ⇒ Object
Returns the value of attribute http_basic_auth_username.
11 12 13 |
# File 'lib/overule/configuration.rb', line 11 def http_basic_auth_username @http_basic_auth_username end |
#orm ⇒ Object
Returns the value of attribute orm.
10 11 12 |
# File 'lib/overule/configuration.rb', line 10 def orm @orm end |
Instance Method Details
#actor_for(controller) ⇒ Object
54 55 56 57 58 |
# File 'lib/overule/configuration.rb', line 54 def actor_for(controller) return nil unless actor_proc.respond_to?(:call) actor_proc.call(controller) end |
#http_basic_auth_configured? ⇒ Boolean
24 25 26 |
# File 'lib/overule/configuration.rb', line 24 def http_basic_auth_configured? !!http_basic_auth end |
#http_basic_auth_matches?(username, password) ⇒ Boolean
Returns true iff the given credentials match the configured username and password. Uses constant-time comparison on both fields (always evaluating both with bitwise ‘&`) so the response time can’t reveal which side mismatched. Raises if auth is toggled on but credentials weren’t set.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/overule/configuration.rb', line 32 def http_basic_auth_matches?(username, password) return true unless http_basic_auth_configured? if http_basic_auth_username.nil? || http_basic_auth_password.nil? raise ArgumentError, "Overule.config.http_basic_auth is true but http_basic_auth_username " \ "and/or http_basic_auth_password are not set" end ActiveSupport::SecurityUtils.secure_compare(username.to_s, http_basic_auth_username.to_s) & ActiveSupport::SecurityUtils.secure_compare(password.to_s, http_basic_auth_password.to_s) end |