Class: DHS::Collection
Overview
A collection is a special type of data that contains multiple items
Defined Under Namespace
Modules: HandleNested, InternalCollection
Constant Summary
collapse
- METHOD_NAMES_EXLCUDED_FROM_WRAPPING =
%w(to_a to_ary map).freeze
Proxy::Accessors::BLACKLISTED_KEYWORDS
Instance Attribute Summary
Attributes inherited from Proxy
#_data, #_loaded
Instance Method Summary
collapse
Methods inherited from Proxy
#initialize, #load!, #record, #reload!
#create, #create!
#clear_cache!
Constructor Details
This class inherits a constructor from DHS::Proxy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **keyword_args, &block) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/dhs/collection.rb', line 57
def method_missing(name, *args, **keyword_args, &block)
if _collection.respond_to?(name)
value = _collection.send(name, *args, **keyword_args, &block)
record = DHS::Record.for_url(value[:href]) if value.is_a?(Hash) && value[:href]
record ||= _record
value = enclose_item_in_data(value) if value.is_a?(Hash)
return value if METHOD_NAMES_EXLCUDED_FROM_WRAPPING.include?(name.to_s)
wrap_return(value, record, name, args)
elsif _data._raw.is_a?(Hash)
get(name, *args, **keyword_args)
end
end
|
Instance Method Details
#_collection ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/dhs/collection.rb', line 31
def _collection
@_collection ||= begin
raw = _data._raw if _data._raw.is_a?(Array)
raw ||= _data.access(input: _data._raw, record: _record)
Collection.new(raw, _data, _record)
end
end
|
22
23
24
|
# File 'lib/dhs/collection.rb', line 22
def
_record.(_data)
end
|
#collection? ⇒ Boolean
39
40
41
|
# File 'lib/dhs/collection.rb', line 39
def collection?
true
end
|
#href ⇒ Object
26
27
28
29
|
# File 'lib/dhs/collection.rb', line 26
def href
return _data._raw[:href] if _data._raw.is_a? Hash
nil
end
|
#item? ⇒ Boolean
43
44
45
|
# File 'lib/dhs/collection.rb', line 43
def item?
false
end
|
#raw_items ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/dhs/collection.rb', line 47
def raw_items
if _raw.is_a?(Array)
_raw
else
access(input: _raw, record: _record)
end
end
|