Module: Postmen::CollectionProxy::ClassMethods

Defined in:
lib/postmen/collection_proxy.rb

Overview

This module holds all class-level methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#settingsObject (readonly)

Settings hash. Used in model/key methods.



12
13
14
# File 'lib/postmen/collection_proxy.rb', line 12

def settings
  @settings
end

Instance Method Details

#get(response) ⇒ Object

Wraps raw JSON response into an model

Parameters:

  • response (Hash)

    parsed JSON response

Returns:

  • model an instance of



36
37
38
# File 'lib/postmen/collection_proxy.rb', line 36

def get(response)
  model.new(response[:data])
end

#key(key = nil) ⇒ Symbol

Sets (if argument is provides) or gets the key where the data is being searched in the API response.

Returns:

  • (Symbol)

    key name

See Also:



27
28
29
30
# File 'lib/postmen/collection_proxy.rb', line 27

def key(key = nil)
  return settings[:key] unless key
  settings[:key] = key
end

#model(model = nil) ⇒ Class

Sets (if argument is provided) or gets the model class name

Returns:

  • (Class)

    Model name, eg. ‘Label`



17
18
19
20
# File 'lib/postmen/collection_proxy.rb', line 17

def model(model = nil)
  return settings[:model] unless model
  settings[:model] = model
end