Class: MC2P::ReadOnlyObjectItem

Inherits:
ObjectItem show all
Defined in:
lib/base.rb

Overview

Object item that allows retrieve an item

Direct Known Subclasses

CRObjectItem, CRUObjectItem, Currency, Gateway, PayData, Sale

Instance Attribute Summary

Attributes inherited from ObjectItemMixin

#_deleted, #json_dict, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ObjectItem

#method_missing, #respond_to?, #respond_to_missing?, #set

Methods inherited from ObjectItemMixin

#id_required_and_not_deleted, #to_s

Constructor Details

#initialize(json_dict, resource) ⇒ ReadOnlyObjectItem

Initializes an object item Params:

json_dict

Data of the object

resource

Resource used to delete, save, create or retrieve the object



82
83
84
85
# File 'lib/base.rb', line 82

def initialize(json_dict, resource)
  @retrieve_mixin = RetrieveObjectItemMixin.new(json_dict, resource)
  super(json_dict, resource)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MC2P::ObjectItem

Class Method Details

.get(object_id) ⇒ Object

Retrieve object with object_id and return Params:

object_id

Id to retrieve

Returns: Object after retrieve



91
92
93
94
95
96
97
# File 'lib/base.rb', line 91

def self.get(object_id)
  obj = new({
              @id_property => object_id
            }, resource)
  obj.retrieve
  obj
end

Instance Method Details

#retrieveObject

Retrieves the data of the object item



100
101
102
103
104
105
# File 'lib/base.rb', line 100

def retrieve
  @retrieve_mixin.json_dict = @json_dict
  @retrieve_mixin._deleted = @_deleted
  @retrieve_mixin.retrieve
  @json_dict = @retrieve_mixin.json_dict
end