Class: LHS::Collection

Inherits:
Proxy
  • Object
show all
Includes:
Create, InternalCollection
Defined in:
lib/lhs/collection.rb,
lib/lhs/concerns/collection/internal_collection.rb

Overview

A collection is a special type of data that contains multiple items

Defined Under Namespace

Modules: InternalCollection

Instance Attribute Summary

Attributes inherited from Proxy

#_data, #_loaded

Instance Method Summary collapse

Methods inherited from Proxy

#initialize, #load!, #reload!

Methods included from Proxy::Create

#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 (protected)



38
39
40
41
42
# File 'lib/lhs/collection.rb', line 38

def method_missing(name, *args, &block)
  value = _collection.send(name, *args, &block)
  return enclose_in_data(value) if value.is_a? Hash
  value
end

Instance Method Details

#_collectionObject



22
23
24
25
26
# File 'lib/lhs/collection.rb', line 22

def _collection
  raw = _data._raw if _data._raw.is_a?(Array)
  raw ||= _data._raw[items_key]
  Collection.new(raw, _data, _record)
end

#_paginationObject



14
15
16
# File 'lib/lhs/collection.rb', line 14

def _pagination
  _record.pagination(_data)
end

#collection?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/lhs/collection.rb', line 28

def collection?
  true
end

#hrefObject



18
19
20
# File 'lib/lhs/collection.rb', line 18

def href
  _data._raw[:href]
end

#item?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/lhs/collection.rb', line 32

def item?
  false
end