Class: MC2P::CRUObjectItem

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

Overview

Object item that allows retrieve, create and change an item

Direct Known Subclasses

CRUDObjectItem

Instance Attribute Summary

Attributes inherited from ObjectItemMixin

#_deleted, #json_dict, #resource

Instance Method Summary collapse

Methods inherited from ReadOnlyObjectItem

get, #retrieve

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) ⇒ CRUObjectItem

Initializes an object item Params:

json_dict

Data of the object

resource

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



142
143
144
145
# File 'lib/base.rb', line 142

def initialize(json_dict, resource)
  @save_mixin = SaveObjectItemMixin.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

Instance Method Details

#_changeObject

Creates the object item with the json_dict data



156
157
158
159
160
161
# File 'lib/base.rb', line 156

def _change
  @save_mixin.json_dict = @json_dict
  @save_mixin._deleted = @_deleted
  @save_mixin._change
  @json_dict = @save_mixin.json_dict
end

#_createObject

Creates the object item with the json_dict data



148
149
150
151
152
153
# File 'lib/base.rb', line 148

def _create
  @save_mixin.json_dict = @json_dict
  @save_mixin._deleted = @_deleted
  @save_mixin._create
  @json_dict = @save_mixin.json_dict
end

#saveObject

Executes the internal function _create if the object item don’t have id



164
165
166
167
168
169
# File 'lib/base.rb', line 164

def save
  @save_mixin.json_dict = @json_dict
  @save_mixin._deleted = @_deleted
  @save_mixin.save
  @json_dict = @save_mixin.json_dict
end