module Sequel::Plugins::ActiveModel::InstanceMethods

Public Instance Methods

after_destroy() click to toggle source

Record that an object was destroyed, for later use by destroyed?

Calls superclass method
   # File lib/sequel/plugins/active_model.rb
49 def after_destroy
50   super
51   @destroyed = true
52 end
model_name() click to toggle source

Return ::ActiveModel::Name instance for the class.

   # File lib/sequel/plugins/active_model.rb
55 def model_name
56   model.model_name
57 end
persisted?() click to toggle source

False if the object is new? or has been destroyed, true otherwise.

   # File lib/sequel/plugins/active_model.rb
60 def persisted?
61   return false if new?
62   return false if defined?(@destroyed)
63 
64   if defined?(@rollback_checker)
65     if @rollback_checker.call
66       return false
67     end
68   end
69   
70   true
71 end
to_key() click to toggle source

An array of primary key values, or nil if the object is not persisted.

   # File lib/sequel/plugins/active_model.rb
74 def to_key
75   if primary_key.is_a?(Symbol)
76     [pk] if pk
77   else
78     pk if pk.all?
79   end
80 end
to_model() click to toggle source

With the active_model plugin, Sequel model objects are already compliant, so this returns self.

   # File lib/sequel/plugins/active_model.rb
84 def to_model
85   self
86 end
to_param() click to toggle source

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
90 def to_param
91   if persisted? and k = to_key
92     k.join(to_param_joiner)
93   end
94 end
to_partial_path() click to toggle source

Returns a string identifying the path associated with the object.

   # File lib/sequel/plugins/active_model.rb
97 def to_partial_path
98   model._to_partial_path
99 end

Private Instance Methods

_save(opts) click to toggle source

For new objects, add a rollback checker to check if the transaction in which this instance is created is rolled back.

Calls superclass method
    # File lib/sequel/plugins/active_model.rb
105 def _save(opts)
106   if new? && db.in_transaction?(opts)
107     @rollback_checker = db.rollback_checker(opts)
108   end
109   super
110 end
errors_class() click to toggle source

Use ActiveModel compliant errors class.

    # File lib/sequel/plugins/active_model.rb
113 def errors_class
114   Errors
115 end
to_param_joiner() click to toggle source

The string to use to join composite primary key param strings.

    # File lib/sequel/plugins/active_model.rb
118 def to_param_joiner
119   '-'
120 end