Class: Overule::Configuration

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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_procObject

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_authObject

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_passwordObject

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_usernameObject

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

#ormObject

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

Returns:

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

Returns:

  • (Boolean)


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