Class: MC2P::ObjectItemMixin

Inherits:
Object
  • Object
show all
Defined in:
lib/mixins.rb

Overview

Basic info of the object item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_dict, resource, id_property = 'id') ⇒ ObjectItemMixin

Returns a new instance of ObjectItemMixin.



9
10
11
12
13
14
# File 'lib/mixins.rb', line 9

def initialize(json_dict, resource, id_property = 'id')
  @json_dict = json_dict
  @resource = resource
  @_deleted = nil
  @id_property = id_property
end

Instance Attribute Details

#_deletedObject

Returns the value of attribute _deleted.



7
8
9
# File 'lib/mixins.rb', line 7

def _deleted
  @_deleted
end

#json_dictObject

Returns the value of attribute json_dict.



5
6
7
# File 'lib/mixins.rb', line 5

def json_dict
  @json_dict
end

#resourceObject

Returns the value of attribute resource.



6
7
8
# File 'lib/mixins.rb', line 6

def resource
  @resource
end

Instance Method Details

#id_required_and_not_deletedObject



16
17
18
19
20
# File 'lib/mixins.rb', line 16

def id_required_and_not_deleted
  raise BadUseError('Object don\'t have ID') unless
      @json_dict.fetch(@id_property, false)
  raise BadUseError('Object deleted') if @_deleted
end

#to_sObject

Returns: Name of the object and content



23
24
25
# File 'lib/mixins.rb', line 23

def to_s
  "#{self.class.name} #{@json_dict}"
end