Class: Tama::Controllers::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/controllers/controller.rb

Overview

A Controller just passes any method calls it gets to its api The api can be whatever class you want it to be.

A Controller can contain one api or an array of apis. In case of an array TamaController checks each of its apis in turn and executes the method on the first API that supports it

Direct Known Subclasses

TamaController

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Controller

Returns a new instance of Controller.



19
20
21
# File 'lib/controllers/controller.rb', line 19

def initialize(api)
  self.api = api
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/controllers/controller.rb', line 23

def method_missing(method_name,*args)
  if self.api.is_a? Array
    index = 0
    begin
      self.api[index].send(method_name,*args)
    rescue NoMethodError => e
      index += 1
      raise if index == self.api.length || (not method_name == e.name)
      retry
    end
  else
    api.send(method_name)
  end
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



17
18
19
# File 'lib/controllers/controller.rb', line 17

def api
  @api
end