Module: Sequel::Plugins::ActiveModel::InstanceMethods
- Defined in:
- lib/sequel/plugins/active_model.rb
Constant Summary collapse
- DEFAULT_TO_PARAM_JOINER =
The default string to join composite primary keys with in to_param.
'-'.freeze
Instance Method Summary collapse
-
#after_destroy ⇒ Object
Record that an object was destroyed, for later use by destroyed?.
-
#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 ActiveModel plugin, Sequel model objects are already compliant, so this returns self.
-
#to_param ⇒ Object
An string representing the object’s primary key.
Instance Method Details
#after_destroy ⇒ Object
Record that an object was destroyed, for later use by destroyed?
19 20 21 22 |
# File 'lib/sequel/plugins/active_model.rb', line 19 def after_destroy super @destroyed = true end |
#persisted? ⇒ Boolean
False if the object is new? or has been destroyed, true otherwise.
25 26 27 |
# File 'lib/sequel/plugins/active_model.rb', line 25 def persisted? !new? && @destroyed != true end |
#to_key ⇒ Object
An array of primary key values, or nil if the object is not persisted.
30 31 32 33 34 |
# File 'lib/sequel/plugins/active_model.rb', line 30 def to_key if persisted? primary_key.is_a?(Symbol) ? [pk] : pk end end |
#to_model ⇒ Object
With the ActiveModel plugin, Sequel model objects are already compliant, so this returns self.
38 39 40 |
# File 'lib/sequel/plugins/active_model.rb', line 38 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.
44 45 46 47 48 |
# File 'lib/sequel/plugins/active_model.rb', line 44 def to_param if k = to_key k.join(to_param_joiner) end end |