Module: Apimaster::Mapper::ClassMethods
- Defined in:
- lib/apimaster/mapper.rb
Constant Summary collapse
- OPTION_TYPES =
[:accessor, :required, :optional]
Instance Method Summary collapse
-
#attr_options(name, options = {}) ⇒ Object
attr_options :url, accessor: [:get, :list].
-
#find_attrs_in_options(type, option = :all) ⇒ Object
[:url, :name].
- #post(hash) ⇒ Object
- #to_api_hashes(accessor = :all) ⇒ Object
- #to_hashes(accessor = :all) ⇒ Object
Instance Method Details
#attr_options(name, options = {}) ⇒ Object
attr_options :url, accessor: [:get, :list]
100 101 102 103 |
# File 'lib/apimaster/mapper.rb', line 100 def name, = {} @attr_options ||= {} @attr_options[name] = end |
#find_attrs_in_options(type, option = :all) ⇒ Object
- :url, :name
106 107 108 109 110 111 112 113 |
# File 'lib/apimaster/mapper.rb', line 106 def type, option = :all raise "Unknown attribute options type: #{type}" unless OPTION_TYPES.include? type @attr_options ||= {} @attr_options.select do |name, | = (.is_a?(Hash) and .key?(type)) ? [type] : nil .is_a?(Array) and (.include?(option) or .include?(:all)) end.keys end |
#post(hash) ⇒ Object
115 116 117 |
# File 'lib/apimaster/mapper.rb', line 115 def post hash self.new.post hash end |
#to_api_hashes(accessor = :all) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/apimaster/mapper.rb', line 127 def to_api_hashes accessor = :all result = [] self.each do |val| result << val.to_api_hash(accessor) end result end |
#to_hashes(accessor = :all) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/apimaster/mapper.rb', line 119 def to_hashes accessor = :all result = [] self.each do |val| result << val.to_hash(accessor) end result end |