Module: Apimaster::Mapper::ClassMethods

Defined in:
lib/apimaster/mapper.rb

Constant Summary collapse

OPTION_TYPES =
[:accessor, :required, :optional]

Instance Method Summary collapse

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 attr_options name, options = {}
  @attr_options ||= {}
  @attr_options[name] = options
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 find_attrs_in_options type, option = :all
  raise "Unknown attribute options type: #{type}" unless OPTION_TYPES.include? type
  @attr_options ||= {}
  @attr_options.select do |name, options|
    type_options = (options.is_a?(Hash) and options.key?(type)) ? options[type] : nil
    type_options.is_a?(Array) and (type_options.include?(option) or type_options.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