Class: MyJohnDeereApi::Model::Base
- Inherits:
-
Object
- Object
- MyJohnDeereApi::Model::Base
- Includes:
- Helpers::CaseConversion, Helpers::UriHelpers
- Defined in:
- lib/my_john_deere_api/model/base.rb
Direct Known Subclasses
Asset, AssetLocation, ContributionDefinition, ContributionProduct, Field, Flag, Organization
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#record_type ⇒ Object
readonly
Returns the value of attribute record_type.
Instance Method Summary collapse
-
#accessor ⇒ Object
The client accessor.
-
#initialize(client, record) ⇒ Base
constructor
arguments:.
Constructor Details
#initialize(client, record) ⇒ Base
arguments:
- client
-
the client, because it contains all the config info. The alternative would be a true Config block, but then settings would be app-wide. This allows one app to have multiple clients with different settings.
- record
-
a JSON object of type ‘Field’, returned from the API.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/my_john_deere_api/model/base.rb', line 18 def initialize(client, record) verify_record_type(record['@type']) @id = record['id'] @record_type = record['@type'] @client = client @unsaved = false map_attributes(record) @links = {} record['links'].each do |association| @links[underscore(association['rel'])] = uri_path(association['uri']) end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/my_john_deere_api/model/base.rb', line 6 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/my_john_deere_api/model/base.rb', line 6 def id @id end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
6 7 8 |
# File 'lib/my_john_deere_api/model/base.rb', line 6 def links @links end |
#record_type ⇒ Object (readonly)
Returns the value of attribute record_type.
6 7 8 |
# File 'lib/my_john_deere_api/model/base.rb', line 6 def record_type @record_type end |
Instance Method Details
#accessor ⇒ Object
The client accessor
38 39 40 41 |
# File 'lib/my_john_deere_api/model/base.rb', line 38 def accessor return @accessor if defined?(@accessor) @accessor = client&.accessor end |