Module: Riagent::Conversion

Defined in:
lib/riagent/conversion.rb

Instance Method Summary collapse

Instance Method Details

#destroyed?Boolean Also known as: deleted?

Has this document been deleted? Required by ActiveModel::Conversion API

Returns:

  • (Boolean)


29
30
31
# File 'lib/riagent/conversion.rb', line 29

def destroyed?
  @destroyed ||= false
end

#new_record?Boolean

Is this a new, unsaved document? Required by ActiveModel::Conversion API

Returns:

  • (Boolean)


37
38
39
# File 'lib/riagent/conversion.rb', line 37

def new_record?
  !persisted?
end

#persist!Object

Marks the document as saved/persisted Called by save, and when instantiating query results (see ::Persistence)



43
44
45
# File 'lib/riagent/conversion.rb', line 43

def persist!
  @persisted = true
end

#persisted?Boolean

Has this document been saved to Riak? Required by ActiveModel::Conversion API

Returns:

  • (Boolean)


50
51
52
# File 'lib/riagent/conversion.rb', line 50

def persisted?
  @persisted ||= false
end

#to_keyObject

Returns an Enumerable of all key attributes if any is set, or nil if the document is not persisted Required by ActiveModel::Conversion API



57
58
59
# File 'lib/riagent/conversion.rb', line 57

def to_key
  self.new_record? ? nil : [self.key]
end

#to_modelObject

Returns an instance of an ActiveModel object (ie, itself) Required by ActiveModel::Conversion API



63
64
65
# File 'lib/riagent/conversion.rb', line 63

def to_model
  self
end

#to_paramString|nil

Returns a string representing the object’s key suitable for use in URLs, or nil if persisted? is false. Required by ActiveModel::Conversion API

Returns:

  • (String|nil)


71
72
73
# File 'lib/riagent/conversion.rb', line 71

def to_param
  self.key
end

#to_partial_pathString

Returns a string identifying the path associated with the object. ActionPack uses this to find a suitable partial to represent the object. Used in Rails helper methods such as link_to Required by ActiveModel::Conversion API

Returns:

  • (String)


80
81
82
# File 'lib/riagent/conversion.rb', line 80

def to_partial_path
  "#{self.class.collection_name}/#{self.key}"
end