Module: Rodauth::Rails

Defined in:
lib/rodauth/rails.rb,
lib/rodauth/rails/app.rb,
lib/rodauth/rails/auth.rb,
lib/rodauth/rails/test.rb,
lib/rodauth/rails/mailer.rb,
lib/rodauth/rails/railtie.rb,
lib/rodauth/rails/version.rb,
lib/rodauth/rails/middleware.rb,
lib/rodauth/rails/feature/base.rb,
lib/rodauth/rails/feature/csrf.rb,
lib/rodauth/rails/tasks/routes.rb,
lib/rodauth/rails/feature/email.rb,
lib/rodauth/rails/feature/render.rb,
lib/rodauth/rails/test/controller.rb,
lib/rodauth/rails/feature/callbacks.rb,
lib/rodauth/rails/controller_methods.rb,
lib/generators/rodauth/views_generator.rb,
lib/generators/rodauth/mailer_generator.rb,
lib/generators/rodauth/install_generator.rb,
lib/rodauth/rails/feature/instrumentation.rb,
lib/generators/rodauth/migration_generator.rb,
lib/rodauth/rails/feature/internal_request.rb

Defined Under Namespace

Modules: ControllerMethods, Feature, Generators, Tasks, Test Classes: App, Auth, Error, Mailer, Middleware, Railtie

Constant Summary collapse

VERSION =
"2.2.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.appObject



72
73
74
75
76
# File 'lib/rodauth/rails.rb', line 72

def app
  fail Rodauth::Rails::Error, "app was not configured" unless @app

  @app.constantize
end

.middleware=(value) ⇒ Object (writeonly)

Sets the attribute middleware

Parameters:

  • value

    the value to set the attribute middleware to.



69
70
71
# File 'lib/rodauth/rails.rb', line 69

def middleware=(value)
  @middleware = value
end

.tilt=(value) ⇒ Object (writeonly)

Sets the attribute tilt

Parameters:

  • value

    the value to set the attribute tilt to.



70
71
72
# File 'lib/rodauth/rails.rb', line 70

def tilt=(value)
  @tilt = value
end

Class Method Details

.authenticate(name = nil, &condition) ⇒ Object

Routing constraint that requires authenticated account.



56
57
58
59
60
61
62
# File 'lib/rodauth/rails.rb', line 56

def authenticate(name = nil, &condition)
  lambda do |request|
    rodauth = request.env.fetch ["rodauth", *name].join(".")
    rodauth.
    condition.nil? || condition.call(rodauth)
  end
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



64
65
66
# File 'lib/rodauth/rails.rb', line 64

def configure
  yield self
end

.lib(**options, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/rodauth/rails.rb', line 20

def lib(**options, &block)
  c = Class.new(Rodauth::Rails::App)
  c.configure(json: false, **options) do
    enable :internal_request
    instance_exec(&block)
  end
  c.freeze
  c.rodauth
end

.middleware?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/rodauth/rails.rb', line 78

def middleware?
  @middleware
end

.model(name = nil, **options) ⇒ Object



51
52
53
# File 'lib/rodauth/rails.rb', line 51

def model(name = nil, **options)
  Rodauth::Model.new(app.rodauth!(name), **options)
end

.rodauth(name = nil, account: nil, **options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rodauth/rails.rb', line 30

def rodauth(name = nil, account: nil, **options)
  auth_class = app.rodauth!(name)

  unless auth_class.features.include?(:internal_request)
    fail Rodauth::Rails::Error, "Rodauth::Rails.rodauth requires internal_request feature to be enabled"
  end

  if 
    options[:account_id] = .id
  end

  auth_class.internal_request_eval(options) do
    if defined?(ActiveRecord::Base) && .is_a?(ActiveRecord::Base)
      @account = .attributes_before_type_cast.symbolize_keys
    elsif defined?(Sequel::Model) && .is_a?(Sequel::Model)
      @account = .values
    end
    self
  end
end

.tilt?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/rodauth/rails.rb', line 82

def tilt?
  @tilt
end