Class: Dao::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/dao/api/context.rb

Constant Summary collapse

Attrs =
%w( api interface params result method args )

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Context

Returns a new instance of Context.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dao/api/context.rb', line 6

def initialize(*args, &block)
  options = Dao.options_for!(args)

  api = options[:api]
  interface = options[:interface]
  params = options[:params]

  params = Params.for(:api => api, :interface => interface, :params => params)
  result = Result.new(:api => api, :interface => interface, :params => params)
  params.result = result

  method = interface.method.bind(api)
  args = [params, result].slice(0, method.arity)

  self.api = api
  self.interface = interface
  self.params = params
  self.result = result
  self.method = method
  self.args = args
end

Instance Method Details

#callObject



28
29
30
# File 'lib/dao/api/context.rb', line 28

def call()
  method.call(*args)
end

#update(options = {}) ⇒ Object



32
33
34
35
36
# File 'lib/dao/api/context.rb', line 32

def update(options = {})
  options.each do |key, val|
    send("#{ key }=", val)
  end
end