Module: HalInterpretation::Dsl
- Defined in:
- lib/hal_interpretation/dsl.rb
Instance Method Summary collapse
-
#extract(attr_name, opts = {}) ⇒ Object
Declare that an attribute should be extract from the HAL document.
-
#item_class(klass) ⇒ Object
Declare the class of models this interpreter builds.
Instance Method Details
#extract(attr_name, opts = {}) ⇒ Object
Declare that an attribute should be extract from the HAL document.
attr_name - name of attribute on model to extract
opts - hash of named arguments to method
:from - JSON path from which to get the value for
attribute. Default: "/#{attr_name}".
:with - Callable that can extract the value when
passed a HalClient::Representation of the item.
:coercion - callable with which the raw value should be
transformed before being stored.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hal_interpretation/dsl.rb', line 25 def extract(attr_name, opts={}) extractor_opts = { attr: attr_name, location: opts.fetch(:from) { "/#{attr_name}" } } extractor_opts[:extraction_proc] = opts.fetch(:with) if opts.key? :with extractor_opts[:coercion] = opts[:coercion] if opts.key? :coercion extractors << Extractor.new(extractor_opts) end |
#item_class(klass) ⇒ Object
Declare the class of models this interpreter builds.
4 5 6 7 8 |
# File 'lib/hal_interpretation/dsl.rb', line 4 def item_class(klass) define_method(:item_class) do klass end end |