Class: Rodauth::Model

Inherits:
Module
  • Object
show all
Defined in:
lib/rodauth/model.rb,
lib/rodauth/model/sequel.rb,
lib/rodauth/model/active_record.rb

Defined Under Namespace

Modules: ActiveRecord, Sequel

Constant Summary collapse

Error =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_class, association_options: {}) ⇒ Model

Returns a new instance of Model.



23
24
25
26
# File 'lib/rodauth/model.rb', line 23

def initialize(auth_class, association_options: {})
  @auth_class = auth_class
  @association_options = association_options
end

Class Method Details

.associationsObject



14
15
16
# File 'lib/rodauth/model.rb', line 14

def self.associations
  @associations ||= {}
end

.register_association(feature, &block) ⇒ Object



18
19
20
21
# File 'lib/rodauth/model.rb', line 18

def self.register_association(feature, &block)
  associations[feature] ||= []
  associations[feature] << block
end

Instance Method Details

#included(model) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rodauth/model.rb', line 28

def included(model)
  if defined?(::ActiveRecord::Base) && model < ::ActiveRecord::Base
    extend Rodauth::Model::ActiveRecord
  elsif defined?(::Sequel::Model) && model < ::Sequel::Model
    extend Rodauth::Model::Sequel
  else
    raise Error, "must be an Active Record or Sequel model"
  end

  define_associations(model)
  define_methods(model)
end

#inspectObject



41
42
43
# File 'lib/rodauth/model.rb', line 41

def inspect
  "#<#{self.class}(#{@auth_class.inspect})>"
end