Module: Dawn::BaseApi::ClassExtension
- Includes:
- RequestExtension
- Defined in:
- lib/dawn/api/base_api.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#data_key(key_name, options = {}) ⇒ Object
Defines accessor for an internal @data Hash.
- #data_keys ⇒ Array
-
#id_param(options) ⇒ String
Strips a valid id parameter from the given options.
Methods included from RequestExtension
Methods included from SafeExtension
Instance Method Details
#data_key(key_name, options = {}) ⇒ Object
Defines accessor for an internal @data Hash. Methods defined are (key_name) and (key_name)=
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dawn/api/base_api.rb', line 52 def data_key(key_name, ={}) = { write: true, read: true, path: key_name }.merge() key_path = .fetch(:path) route = key_path.to_s.split("/") route_dp = route.dup last_key = route_dp.pop define_method(key_name) do route.inject(@data) { |d, key| d[key] } end if .fetch(:read) define_method(key_name.to_s+"=") do |v| route_dp.inject(@data) { |d, key| d[key] }[last_key] = v end if .fetch(:write) data_keys.push(key_name) return key_name end |
#data_keys ⇒ Array
42 43 44 |
# File 'lib/dawn/api/base_api.rb', line 42 def data_keys @data_keys ||= [] end |
#id_param(options) ⇒ String
Strips a valid id parameter from the given options. This method is normally overwritten in each subclass to suite their id needs.
35 36 37 |
# File 'lib/dawn/api/base_api.rb', line 35 def id_param() .delete(:id) end |