Module: Auth

Defined in:
lib/auth.rb,
lib/auth/engine.rb,
lib/auth/behavior/core.rb,
lib/auth/configuration.rb,
lib/auth/configuration/keys.rb,
lib/auth/behavior/remember_me.rb

Defined Under Namespace

Modules: Behavior, BehaviorLookup Classes: Configuration, Engine, Model, Observer, TargetList, Token

Class Method Summary collapse

Class Method Details

.configurationObject



36
37
38
# File 'lib/auth.rb', line 36

def configuration
  @configuration ||= Auth::Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



40
41
42
# File 'lib/auth.rb', line 40

def configure
  yield configuration
end

.configure!Object Also known as: kick!

Applies all configuration settings. This is done by the Auth system after it has been configured but before it processes any requests.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/auth.rb', line 62

def configure!
  begin
    configuration.apply!
  rescue NameError
    puts
    puts "WARNING: #{$!.message}"
    puts
    puts "This happened while trying to configure Sparkly Authentication."
    puts "You should verify that /config/initializers/sparkly_authentication.rb"
    puts "is set up properly. It could be that you just haven't created the"
    puts "model yet. If so, this error will disappear when the model exists."
    puts
    if ENV['AUTH_BACKTRACE']
      puts $!.backtrace
    else
      puts "(Run with AUTH_BACKTRACE=true to see a full bactrace.)"
    end
    puts
  end
end

.defer_kickstart=(a) ⇒ Object



48
49
50
# File 'lib/auth.rb', line 48

def defer_kickstart=(a)
  @defer_kickstart = !!a
end

.defer_kickstart?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/auth.rb', line 44

def defer_kickstart?
  @defer_kickstart ||= !!ENV['DEFER_SPARKLY']
end

.pathObject



52
53
54
55
56
57
58
# File 'lib/auth.rb', line 52

def path
  if @configuration
    @configuration.path
  else
    File.dirname(__FILE__)
  end
end

.reset_configuration!Object

Useful for cleaning up after tests, but probably not much else.



84
85
86
# File 'lib/auth.rb', line 84

def reset_configuration!
  @configuration = Auth::Configuration.new
end

.routing_procObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/auth.rb', line 14

def routing_proc
  proc do
    Auth.configuration.authenticated_models.each do |model|
      catch :missing do
        begin
          model.name # if an error is going to occur due to missing model, it'll happen here.
        rescue NameError
          # we rescue silently because the user's already been warned (during startup).
          throw :missing
        end

        resource model.name.underscore, :model => model.name,
                 :controller => model.accounts_controller do
          resource :session, :controller => model.sessions_controller, :model => model.name
          match '/login', :to => "#{model.sessions_controller}#new", :as => "login"
          match '/logout', :to => "#{model.sessions_controller}#destroy", :as => "logout"
        end
      end
    end
  end
end