Class: Mongoid::Userstamps::Config::Model
- Inherits:
-
Object
- Object
- Mongoid::Userstamps::Config::Model
- Defined in:
- lib/mongoid/userstamps/config/model.rb
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(model) ⇒ Model
constructor
A new instance of Model.
- #set_user_model! ⇒ Object
- #user_model ⇒ Object
- #user_model=(value) ⇒ Object
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
#config ⇒ Object
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].[:class_name] = user_model end end end end |
#user_model ⇒ Object
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 |