class MC2P::ObjectItem

Object item - class used to wrap the data from API that represent an item

Public Class Methods

new(json_dict, resource) click to toggle source

Initializes an object item Params:

json_dict

Data of the object

resource

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

# File lib/base.rb, line 42
def initialize(json_dict, resource)
  @json_dict = json_dict.nil? ? {} : json_dict
  @resource = resource
  @_deleted = false
  @id_property = 'id'
end

Public Instance Methods

method_missing(key, *args) click to toggle source

Allows use the following syntax to get a field of the object:

obj.name

Params:

key

Field to return

Returns: Value of the field from json_dict

Calls superclass method
# File lib/base.rb, line 54
def method_missing(key, *args)
  @json_dict.include?(key.to_s) ? @json_dict[key.to_s] : super
end
respond_to?(key, include_private = false) click to toggle source
Calls superclass method
# File lib/base.rb, line 62
def respond_to?(key, include_private = false)
  @json_dict.include?(key.to_s) || super
end
respond_to_missing?(key, include_private = false) click to toggle source
Calls superclass method
# File lib/base.rb, line 58
def respond_to_missing?(key, include_private = false)
  @json_dict.include?(key.to_s) || super
end
set(key, value) click to toggle source

Allows use the following syntax to set a field of the object:

obj.name = 'example'

Params:

key

Field to change

value

Content to replace the current value

# File lib/base.rb, line 71
def set(key, value)
  @json_dict[key] = value
end