Module: Dawn::BaseApi::ClassExtension

Includes:
RequestExtension
Defined in:
lib/dawn/api/base_api.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from RequestExtension

#request

Methods included from SafeExtension

#safe

Instance Method Details

#data_key(key_name, options = {}) ⇒ Object

Defines accessor for an internal @data Hash. Methods defined are (key_name) and (key_name)=

Parameters:

  • key_name (Symbol)
  • options (Hash) (defaults to: {})


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, options={})
  options = { write: true, read: true, path: key_name }.merge(options)
  key_path = options.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 options.fetch(:read)
  define_method(key_name.to_s+"=") do |v|
    route_dp.inject(@data) { |d, key| d[key] }[last_key] = v
  end if options.fetch(:write)

  data_keys.push(key_name)

  return key_name
end

#data_keysArray

Returns:

  • (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.

Parameters:

  • options (Hash)

Returns:

  • (String)


35
36
37
# File 'lib/dawn/api/base_api.rb', line 35

def id_param(options)
  options.delete(:id)
end