Class: BetterAuthy::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
10
11
12
13
14
# File 'lib/better_authy/configuration.rb', line 7

def initialize
  @scopes = {}
  @cookie_config = {
    secure: ENV.fetch("BETTER_AUTHY_SECURE_COOKIES", "false") == "true",
    httponly: true,
    same_site: :lax
  }
end

Instance Attribute Details

Returns the value of attribute cookie_config.



5
6
7
# File 'lib/better_authy/configuration.rb', line 5

def cookie_config
  @cookie_config
end

#scopes ⇒ Object (readonly)

Returns the value of attribute scopes.



5
6
7
# File 'lib/better_authy/configuration.rb', line 5

def scopes
  @scopes
end

Instance Method Details

#scope(name) {|scope_config| ... } ⇒ Object

Yields:

  • (scope_config)

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
# File 'lib/better_authy/configuration.rb', line 20

def scope(name, &block)
  raise ArgumentError, "scope requires a block" unless block_given?

  name = name.to_sym
  raise ConfigurationError, "Scope :#{name} is already registered" if @scopes.key?(name)

  scope_config = ScopeConfiguration.new(name)
  yield(scope_config)
  @scopes[name] = scope_config
end

#scope_for(name) ⇒ Object



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

def scope_for(name)
  @scopes[name.to_sym]
end

#scope_for!(name) ⇒ Object



35
36
37
# File 'lib/better_authy/configuration.rb', line 35

def scope_for!(name)
  scope_for(name) || raise(ConfigurationError, "Scope :#{name} is not registered")
end

#validate! ⇒ Object



39
40
41
# File 'lib/better_authy/configuration.rb', line 39

def validate!
  @scopes.each_value(&:validate!)
end