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?
27 28 29 30 |
# File 'lib/sequel/plugins/active_model.rb', line 27 def after_destroy super @destroyed = true end |
#persisted? ⇒ Boolean
False if the object is new? or has been destroyed, true otherwise.
33 34 35 |
# File 'lib/sequel/plugins/active_model.rb', line 33 def persisted? !new? && @destroyed != true end |
#to_key ⇒ Object
An array of primary key values, or nil if the object is not persisted.
38 39 40 41 42 |
# File 'lib/sequel/plugins/active_model.rb', line 38 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.
46 47 48 |
# File 'lib/sequel/plugins/active_model.rb', line 46 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.
52 53 54 55 56 |
# File 'lib/sequel/plugins/active_model.rb', line 52 def to_param if k = to_key k.join(to_param_joiner) end end |