Class: LHS::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!
Constructor Details
This class inherits a constructor from LHS::Proxy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/lhs/collection.rb', line 55
def method_missing(name, *args, &block)
if _collection.respond_to?(name)
value = _collection.send(name, *args, &block)
record = LHS::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)
end
end
|
Instance Method Details
#_collection ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/lhs/collection.rb', line 29
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
|
20
21
22
|
# File 'lib/lhs/collection.rb', line 20
def
_record.(_data)
end
|
#collection? ⇒ Boolean
37
38
39
|
# File 'lib/lhs/collection.rb', line 37
def collection?
true
end
|
#href ⇒ Object
24
25
26
27
|
# File 'lib/lhs/collection.rb', line 24
def href
return _data._raw[:href] if _data._raw.is_a? Hash
nil
end
|
#item? ⇒ Boolean
41
42
43
|
# File 'lib/lhs/collection.rb', line 41
def item?
false
end
|
#raw_items ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/lhs/collection.rb', line 45
def raw_items
if _raw.is_a?(Array)
_raw
else
access(input: _raw, record: _record)
end
end
|