module Sequel::Plugins::ActiveModel::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/active_model.rb 51 def after_destroy 52 super 53 @destroyed = true 54 end
Record that an object was destroyed, for later use by destroyed?
Source
# File lib/sequel/plugins/active_model.rb 57 def model_name 58 model.model_name 59 end
Return ::ActiveModel::Name instance for the class.
Source
# File lib/sequel/plugins/active_model.rb 62 def persisted? 63 return false if new? || @destroyed 64 65 if @rollback_checker && @rollback_checker.call 66 return false 67 end 68 69 true 70 end
False if the object is new? or has been destroyed, true otherwise.
Source
# File lib/sequel/plugins/active_model.rb 73 def to_key 74 if primary_key.is_a?(Symbol) 75 [pk] if pk 76 else 77 pk if pk.all? 78 end 79 end
An array of primary key values, or nil if the object is not persisted.
Source
# File lib/sequel/plugins/active_model.rb 83 def to_model 84 self 85 end
With the active_model plugin, Sequel model objects are already compliant, so this returns self.
Source
# File lib/sequel/plugins/active_model.rb 89 def to_param 90 if persisted? and k = to_key 91 k.join(to_param_joiner) 92 end 93 end
An string representing the object’s primary key. For composite primary keys, joins them with to_param_joiner.
Source
# File lib/sequel/plugins/active_model.rb 96 def to_partial_path 97 model._to_partial_path 98 end
Returns a string identifying the path associated with the object.
Private Instance Methods
Source
# File lib/sequel/plugins/active_model.rb 104 def _save(opts) 105 if new? && db.in_transaction?(opts) 106 @rollback_checker = db.rollback_checker(opts) 107 end 108 super 109 end
For new objects, add a rollback checker to check if the transaction in which this instance is created is rolled back.
Source
# File lib/sequel/plugins/active_model.rb 112 def errors_class 113 Errors 114 end
Use ActiveModel compliant errors class.
Source
# File lib/sequel/plugins/active_model.rb 117 def to_param_joiner 118 '-' 119 end
The string to use to join composite primary key param strings.