Module: ActiveRestClient::Mapping::ClassMethods

Defined in:
lib/active_rest_client/mapping.rb

Instance Method Summary collapse

Instance Method Details

#_call(name, options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_rest_client/mapping.rb', line 35

def _call(name, options)
  mapped = _calls[name]
  lazy_forced = false
  if mapped.nil? && name.to_s[/^lazy_/]
    mapped = _calls[name.to_s.gsub(/^lazy_/, '').to_sym]
    lazy_forced = true
  end
  request = Request.new(mapped, self, options)
  if lazy_load? || lazy_forced
    ActiveRestClient::LazyLoader.new(request)
  else
    request.call
  end
end

#_callsObject



50
51
52
# File 'lib/active_rest_client/mapping.rb', line 50

def _calls
  @_calls
end

#_map_call(name, details) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/active_rest_client/mapping.rb', line 24

def _map_call(name, details)
  _calls[name] = {name:name}.merge(details)
  _calls["lazy_#{name}".to_sym] = {name:name}.merge(details)
  self.class.send(:define_method, name) do |options={}|
    _call(name, options)
  end
  self.class.send(:define_method, "lazy_#{name}".to_sym) do |options={}|
    _call("lazy_#{name}", options)
  end
end

#_mapped_method(name) ⇒ Object



54
55
56
# File 'lib/active_rest_client/mapping.rb', line 54

def _mapped_method(name)
  _calls[name]
end

#delete(name, url, options = {}) ⇒ Object



16
17
18
# File 'lib/active_rest_client/mapping.rb', line 16

def delete(name, url, options = {})
  _map_call(name, url:url, method: :delete, options:options)
end

#get(name, url, options = {}) ⇒ Object



4
5
6
# File 'lib/active_rest_client/mapping.rb', line 4

def get(name, url, options = {})
  _map_call(name, url:url, method: :get, options:options)
end

#inherited(subclass) ⇒ Object



58
59
60
# File 'lib/active_rest_client/mapping.rb', line 58

def inherited(subclass)
  subclass.instance_variable_set(:@_calls, {})
end

#patch(name, url, options = {}) ⇒ Object



20
21
22
# File 'lib/active_rest_client/mapping.rb', line 20

def patch(name, url, options = {})
  _map_call(name, url:url, method: :patch, options:options)
end

#post(name, url, options = {}) ⇒ Object



12
13
14
# File 'lib/active_rest_client/mapping.rb', line 12

def post(name, url, options = {})
  _map_call(name, url:url, method: :post, options:options)
end

#put(name, url, options = {}) ⇒ Object



8
9
10
# File 'lib/active_rest_client/mapping.rb', line 8

def put(name, url, options = {})
  _map_call(name, url:url, method: :put, options:options)
end