module Sequel::Plugins::ActiveModel::InstanceMethods
Constants
- DEFAULT_TO_PARAM_JOINER
The default string to join composite primary keys with in to_param.
Public Instance Methods
Record that an object was destroyed, for later use by destroyed?
# File lib/sequel/plugins/active_model.rb, line 42 def after_destroy super @destroyed = true end
Mark current instance as destroyed if the transaction in which this instance is created is rolled back.
# File lib/sequel/plugins/active_model.rb, line 49 def before_create db.after_rollback{@destroyed = true} super end
Return ::ActiveModel::Name instance for the class.
# File lib/sequel/plugins/active_model.rb, line 55 def model_name model.model_name end
False if the object is new? or has been destroyed, true otherwise.
# File lib/sequel/plugins/active_model.rb, line 60 def persisted? !new? && @destroyed != true end
An array of primary key values, or nil if the object is not persisted.
# File lib/sequel/plugins/active_model.rb, line 65 def to_key if primary_key.is_a?(Symbol) [pk] if pk else pk if pk.all? end end
With the ActiveModel plugin, Sequel model objects are already compliant, so this returns self.
# File lib/sequel/plugins/active_model.rb, line 75 def to_model self 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 81 def to_param if persisted? and k = to_key k.join(to_param_joiner) end end
Returns a string identifying the path associated with the object.
# File lib/sequel/plugins/active_model.rb, line 88 def to_partial_path model._to_partial_path end
Private Instance Methods
Use ActiveModel compliant errors class.
# File lib/sequel/plugins/active_model.rb, line 95 def errors_class Errors end
The string to use to join composite primary key param strings.
# File lib/sequel/plugins/active_model.rb, line 100 def to_param_joiner DEFAULT_TO_PARAM_JOINER end