class DHS::Collection
A collection is a special type of data that contains multiple items
Constants
- METHOD_NAMES_EXLCUDED_FROM_WRAPPING
Public Instance Methods
_collection()
click to toggle source
# 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
_pagination()
click to toggle source
# File lib/dhs/collection.rb, line 22 def _pagination _record.pagination(_data) end
collection?()
click to toggle source
# File lib/dhs/collection.rb, line 39 def collection? true end
href()
click to toggle source
# File lib/dhs/collection.rb, line 26 def href return _data._raw[:href] if _data._raw.is_a? Hash nil end
item?()
click to toggle source
# File lib/dhs/collection.rb, line 43 def item? false end
raw_items()
click to toggle source
# File lib/dhs/collection.rb, line 47 def raw_items if _raw.is_a?(Array) _raw else access(input: _raw, record: _record) end end
Protected Instance Methods
method_missing(name, *args, **keyword_args, &block)
click to toggle source
# 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
respond_to_missing?(name, _include_all = false)
click to toggle source
# File lib/dhs/collection.rb, line 70 def respond_to_missing?(name, _include_all = false) # We accept every message that does not belong to set of keywords and is not a setter !BLACKLISTED_KEYWORDS.include?(name.to_s) && !name.to_s[/=$/] end
Private Instance Methods
enclose_item_in_data(value)
click to toggle source
Encloses accessed collection item by wrapping it in an DHS::Item
# File lib/dhs/collection.rb, line 79 def enclose_item_in_data(value) data = DHS::Data.new(value, _data, _record) item = DHS::Item.new(data) DHS::Data.new(item, _data) end