Class: Arrest::HasManySubResourceAttribute

Inherits:
HasManyAttribute show all
Defined in:
lib/arrest/attributes/has_many_sub_resource_attribute.rb

Instance Attribute Summary

Attributes inherited from HasManyAttribute

#clazz_name, #foreign_key, #method_name, #url_part

Attributes inherited from Attribute

#clazz, #json_name, #name, #read_only

Instance Method Summary collapse

Methods inherited from Attribute

#to_hash

Constructor Details

#initialize(ids_field_name, method_name, clazz_name, url_part, foreign_key, read_only) ⇒ HasManySubResourceAttribute

Returns a new instance of HasManySubResourceAttribute.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/arrest/attributes/has_many_sub_resource_attribute.rb', line 5

def initialize(ids_field_name,
               method_name,
               clazz_name,
               url_part,
               foreign_key,
               read_only)
  # the read_only for the super constructor is set to true to avoid sending post request as ids array in JSON
  # directly instead of modifying the ids via the sub_resource
  super(ids_field_name, method_name, clazz_name, url_part, foreign_key, true)
  @sub_resource_read_only = read_only
end

Instance Method Details

#from_hash(parent, value) ⇒ Object



26
27
28
29
# File 'lib/arrest/attributes/has_many_sub_resource_attribute.rb', line 26

def from_hash(parent, value)
  return [] if value == nil
  super_from_hash(parent, value)
end

#sub_resource_field_nameObject



17
18
19
# File 'lib/arrest/attributes/has_many_sub_resource_attribute.rb', line 17

def sub_resource_field_name
  @name
end

#sub_resource_read_only?Boolean

this read only hinders the additional put to the sub resource on saving the encapsulating object

Returns:



22
23
24
# File 'lib/arrest/attributes/has_many_sub_resource_attribute.rb', line 22

def sub_resource_read_only?
  @sub_resource_read_only
end

#super_from_hashObject



3
# File 'lib/arrest/attributes/has_many_sub_resource_attribute.rb', line 3

alias :super_from_hash :from_hash