Module | Sequel::Plugins::ActiveModel::InstanceMethods |
In: |
lib/sequel/plugins/active_model.rb
|
DEFAULT_TO_PARAM_JOINER | = | '-'.freeze | The default string to join composite primary keys with in to_param. |
Record that an object was destroyed, for later use by destroyed?
# File lib/sequel/plugins/active_model.rb, line 42 42: def after_destroy 43: super 44: @destroyed = true 45: end
False if the object is new? or has been destroyed, true otherwise.
# File lib/sequel/plugins/active_model.rb, line 48 48: def persisted? 49: !new? && @destroyed != true 50: end
An array of primary key values, or nil if the object is not persisted.
# File lib/sequel/plugins/active_model.rb, line 53 53: def to_key 54: if primary_key.is_a?(Symbol) 55: [pk] if pk 56: else 57: pk if pk.all? 58: end 59: end
With the ActiveModel plugin, Sequel model objects are already compliant, so this returns self.
# File lib/sequel/plugins/active_model.rb, line 63 63: def to_model 64: self 65: end
An string representing the object‘s primary key. For composite primary keys, joins them with to_param_joiner.
# File lib/sequel/plugins/active_model.rb, line 69 69: def to_param 70: if persisted? and k = to_key 71: k.join(to_param_joiner) 72: end 73: end