Class: Mongoid::Userstamps::Config::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/userstamps/config/model.rb

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Model

Returns a new instance of Model.



5
6
7
8
# File 'lib/mongoid/userstamps/config/model.rb', line 5

def initialize(model)
  @model = model
  @user_model = nil
end

Instance Method Details

#configObject



10
11
12
# File 'lib/mongoid/userstamps/config/model.rb', line 10

def config
  Mongoid::Userstamps::Config
end

#set_user_model!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mongoid/userstamps/config/model.rb', line 23

def set_user_model!
  if Mongoid::VERSION.to_f < 7.0
    %i[created_name updated_name deleted_name].each do |attr|
      @model.relations[config.send(attr).to_s].try(:[]=, :class_name, user_model)
    end
  else
    %i[created_name updated_name deleted_name].each do |attr|
      if @model.relations[config.send(attr).to_s]
        @model.relations[config.send(attr).to_s].instance_variable_set :@class_name, user_model
        @model.relations[config.send(attr).to_s].options[:class_name] = user_model
      end
    end
  end
end

#user_modelObject



14
15
16
# File 'lib/mongoid/userstamps/config/model.rb', line 14

def user_model
  @user_model || config.user_classes.first.to_s
end

#user_model=(value) ⇒ Object



18
19
20
21
# File 'lib/mongoid/userstamps/config/model.rb', line 18

def user_model=(value)
  @user_model = value.to_s if value
  set_user_model!
end