Class: Entrance::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/entrance/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/entrance/config.rb', line 12

def initialize
  @model                      = 'User'
  @local_auth                 = true
  @remote_auth                = false

  # strategies
  @cipher                     = Entrance::Ciphers::BCrypt # or Entrance::Ciphers::SHA1
  @secret                     = nil
  @stretches                  = 10

  # access denied
  @access_denied_redirect_to  = '/login'
  @access_denied_message_key  = nil # e.g. 'messages.access_denied'

  # reset password
  @reset_password_mailer      = 'UserMailer'
  @reset_password_method      = 'reset_password_request'
  @reset_password_window      = 60 * 60 # 1.hour

  # remember me & cookies
  @remember_for               = 60 * 24 * 14 # 2.weeks
  @cookie_domain              = nil
  @cookie_secure              = true
  @cookie_path                = '/'
  @cookie_httponly            = false
end

Instance Method Details

#can?(what, val = nil) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/entrance/config.rb', line 45

def can?(what, val = nil)
  if val
    instance_variable_set("@can_#{what}", val)
  else
    !!instance_variable_get("@can_#{what}")
  end
end

#permit!(option) ⇒ Object



53
54
55
# File 'lib/entrance/config.rb', line 53

def permit!(option)
  raise "#{option} is disabled!" unless can?(option)
end

#validate!Object



39
40
41
42
43
# File 'lib/entrance/config.rb', line 39

def validate!
  if cipher == Ciphers::SHA1 && secret.nil?
    raise "The SHA1 cipher requires a valid config.secret to be set."
  end
end