Module: FmRest::Spyke::Model::RecordID

Extended by:
ActiveSupport::Concern
Included in:
FmRest::Spyke::Model
Defined in:
lib/fmrest/spyke/model/record_id.rb

Overview

Modifies Spyke models to use __record_id instead of id as the "primary key" method, so that we can map a model class to a FM layout with a field named id without clobbering it.

The id reader method still maps to the record ID for backwards compatibility and because Spyke hardcodes its use at various points through its codebase, but it can be safely overwritten (e.g. to map to a FM field).

The recommended way to deal with a layout that maps an id attribute is to remap it in the model to something else, e.g. unique_id.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__mod_idInteger Also known as: mod_id

Returns the record's modId.

Returns:

  • (Integer)

    the record's modId



28
29
30
# File 'lib/fmrest/spyke/model/record_id.rb', line 28

def __mod_id
  @__mod_id
end

#__record_idInteger Also known as: record_id, id

Returns the record's recordId.

Returns:

  • (Integer)

    the record's recordId



23
24
25
# File 'lib/fmrest/spyke/model/record_id.rb', line 23

def __record_id
  @__record_id
end

Instance Method Details

#__record_id?Boolean Also known as: record_id?, persisted?

Returns:

  • (Boolean)


57
58
59
# File 'lib/fmrest/spyke/model/record_id.rb', line 57

def __record_id?
  __record_id.present?
end

#destroy(id = nil) ⇒ Object

Spyke override -- Use __record_id instead of id

Parameters:

  • id (Integer) (defaults to: nil)

    The id of the record to destroy



82
83
84
# File 'lib/fmrest/spyke/model/record_id.rb', line 82

def destroy(id = nil)
  new(__record_id: id).destroy
end

#hashObject

Spyke override -- Use __record_id instead of id



65
66
67
# File 'lib/fmrest/spyke/model/record_id.rb', line 65

def hash
  __record_id.hash
end

#inspectString

Spyke override -- Renders class string with layout name and record_id.

Returns:

  • (String)

    A string representation of the class



74
75
76
# File 'lib/fmrest/spyke/model/record_id.rb', line 74

def inspect
  "#<#{self.class}(layout: #{self.class.layout}) record_id: #{__record_id.inspect} #{inspect_attributes}>"
end