Module: Sequel::Plugins::ActiveModel::InstanceMethods
- Defined in:
- lib/sequel/plugins/active_model.rb
Instance Method Summary collapse
-
#after_destroy ⇒ Object
Record that an object was destroyed, for later use by destroyed?.
-
#model_name ⇒ Object
Return ::ActiveModel::Name instance for the class.
-
#persisted? ⇒ Boolean
False if the object is new? or has been destroyed, true otherwise.
-
#to_key ⇒ Object
An array of primary key values, or nil if the object is not persisted.
-
#to_model ⇒ Object
With the active_model plugin, Sequel model objects are already compliant, so this returns self.
-
#to_param ⇒ Object
An string representing the object’s primary key.
-
#to_partial_path ⇒ Object
Returns a string identifying the path associated with the object.
Instance Method Details
#after_destroy ⇒ Object
Record that an object was destroyed, for later use by destroyed?
49 50 51 52 |
# File 'lib/sequel/plugins/active_model.rb', line 49 def after_destroy super @destroyed = true end |
#model_name ⇒ Object
Return ::ActiveModel::Name instance for the class.
55 56 57 |
# File 'lib/sequel/plugins/active_model.rb', line 55 def model_name model.model_name end |
#persisted? ⇒ Boolean
False if the object is new? or has been destroyed, true otherwise.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sequel/plugins/active_model.rb', line 60 def persisted? return false if new? return false if defined?(@destroyed) if defined?(@rollback_checker) if @rollback_checker.call return false end end true end |
#to_key ⇒ Object
An array of primary key values, or nil if the object is not persisted.
74 75 76 77 78 79 80 |
# File 'lib/sequel/plugins/active_model.rb', line 74 def to_key if primary_key.is_a?(Symbol) [pk] if pk else pk if pk.all? end end |
#to_model ⇒ Object
With the active_model plugin, Sequel model objects are already compliant, so this returns self.
84 85 86 |
# File 'lib/sequel/plugins/active_model.rb', line 84 def to_model self end |
#to_param ⇒ Object
An string representing the object’s primary key. For composite primary keys, joins them with to_param_joiner.
90 91 92 93 94 |
# File 'lib/sequel/plugins/active_model.rb', line 90 def to_param if persisted? and k = to_key k.join(to_param_joiner) end end |
#to_partial_path ⇒ Object
Returns a string identifying the path associated with the object.
97 98 99 |
# File 'lib/sequel/plugins/active_model.rb', line 97 def to_partial_path model._to_partial_path end |