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, line 52
def after_destroy
  super
  @destroyed = true
end
model_name() click to toggle source

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

# File lib/sequel/plugins/active_model.rb, line 58
def model_name
  model.model_name
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, line 63
def persisted?
  return false if new?
  return false if defined?(@destroyed)

  if defined?(@rollback_checker)
    if @rollback_checker.call
      return false
    end
  end
  
  true
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, line 77
def to_key
  if primary_key.is_a?(Symbol)
    [pk] if pk
  else
    pk if pk.all?
  end
end
to_model() click to toggle source

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

# File lib/sequel/plugins/active_model.rb, line 87
def to_model
  self
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, line 93
def to_param
  if persisted? and k = to_key
    k.join(to_param_joiner)
  end
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, line 100
def to_partial_path
  model._to_partial_path
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, line 108
def _save(opts)
  if new? && db.in_transaction?(opts)
    @rollback_checker = db.rollback_checker(opts)
  end
  super
end
errors_class() click to toggle source

Use ActiveModel compliant errors class.

# File lib/sequel/plugins/active_model.rb, line 116
def errors_class
  Errors
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, line 121
def to_param_joiner
  DEFAULT_TO_PARAM_JOINER
end