Class: DdrAux::Client::Model Abstract
- Inherits:
-
Hashie::Hash
- Object
- Hashie::Hash
- DdrAux::Client::Model
- Includes:
- Hashie::Extensions::Coercion, Hashie::Extensions::IndifferentAccess, Hashie::Extensions::MergeInitializer, Hashie::Extensions::MethodReader
- Defined in:
- lib/ddr_aux/client/model.rb
Overview
This class is abstract.
Constant Summary collapse
- DEFAULT_TIMESTAMPS =
[:created_at, :updated_at].freeze
Class Attribute Summary collapse
-
.path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
- .coerce_timestamps!(*keys) ⇒ Object
- .find(**args) ⇒ Object (also: where)
- .get(id) ⇒ Object
- .inherited(subclass) ⇒ Object
- .list ⇒ Object (also: all)
Class Attribute Details
.path ⇒ Object
Returns the value of attribute path.
17 18 19 |
# File 'lib/ddr_aux/client/model.rb', line 17 def path @path end |
Class Method Details
.coerce_timestamps!(*keys) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/ddr_aux/client/model.rb', line 23 def (*keys) if keys.empty? keys = DEFAULT_TIMESTAMPS end coerce_keys *keys, ->(v) { ::Time.parse(v) } end |
.find(**args) ⇒ Object Also known as: where
42 43 44 45 46 |
# File 'lib/ddr_aux/client/model.rb', line 42 def find(**args) request_path = "#{path}/find?%s" % URI.encode_www_form(args) response = Request.get_response(request_path) new response.to_h end |
.get(id) ⇒ Object
30 31 32 33 34 |
# File 'lib/ddr_aux/client/model.rb', line 30 def get(id) request_path = [path, id].join("/") response = Request.get_response(request_path) new response.to_h end |
.inherited(subclass) ⇒ Object
19 20 21 |
# File 'lib/ddr_aux/client/model.rb', line 19 def inherited(subclass) subclass.path = path end |
.list ⇒ Object Also known as: all
36 37 38 39 |
# File 'lib/ddr_aux/client/model.rb', line 36 def list response = Request.get_response(path) response.map { |record| new(record) } end |