Module: Sequel::Plugins::ActiveModel::InstanceMethods

Defined in:
lib/sequel/plugins/active_model.rb

Constant Summary collapse

DEFAULT_TO_PARAM_JOINER =

The default string to join composite primary keys with in to_param.

'-'.freeze

Instance Method Summary collapse

Instance Method Details

#after_destroyObject

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



27
28
29
30
# File 'lib/sequel/plugins/active_model.rb', line 27

def after_destroy
  super
  @destroyed = true
end

#persisted?Boolean

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

Returns:

  • (Boolean)


33
34
35
# File 'lib/sequel/plugins/active_model.rb', line 33

def persisted?
  !new? && @destroyed != true
end

#to_keyObject

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



38
39
40
41
42
43
44
# File 'lib/sequel/plugins/active_model.rb', line 38

def to_key
  if primary_key.is_a?(Symbol)
    [pk] if pk
  else
    pk if pk.all?
  end
end

#to_modelObject

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



48
49
50
# File 'lib/sequel/plugins/active_model.rb', line 48

def to_model
  self
end

#to_paramObject

An string representing the object’s primary key. For composite primary keys, joins them with to_param_joiner.



54
55
56
57
58
# File 'lib/sequel/plugins/active_model.rb', line 54

def to_param
  if persisted? and k = to_key
    k.join(to_param_joiner)
  end
end