Module: Seatbelt::Ghost

Defined in:
lib/seatbelt/ghost.rb

Overview

Public: Handles calling and defining of API methods.

Any class that should acts like a API Class have to include this module.

class Flight

include Seatbelt::Ghost

api_method  :estimated_flight_time

api_method  :find_flights,
            :scope => :class

end

flight = Flight.new flight.estimated_flight_time(:to => “London”) Flight.find_flights(:to => “London”, :from => “Frankfurt”)

Defined Under Namespace

Modules: ClassMethods, EigenmethodStore

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Public: Calls a API instance method. If the method isn’t defined or found in the class lookup table a Seatbelt::Errors::NoMethodError is raised.

If method is defined it passes the calling responsibility to the core Callee module.

method_name - the called methods name *args - the methods argument list &block - the methods block (this is optional)

Returns the evaluted method value.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/seatbelt/ghost.rb', line 124

def method_missing(method_name, *args, &block)
  unless self.class.lookup_tbl.has?(method_name)
    unless self.respond_to?(method_name)
      raise Seatbelt::Errors::NoMethodError
    end
  end
  Seatbelt::Callee.handle(self,
                          { :lookup_tbl  => self.class.lookup_tbl,
                            :scope       => :instance,
                            :method_name => method_name
                          },
                          *args,
                          &block)
end

Class Method Details

.included(base) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/seatbelt/ghost.rb', line 21

def self.included(base)
  base.class_eval do
    [Pool::Api, EigenmethodStore, ClassMethods,
      GhostTunnel,Interface].each do |mod|
      self.extend mod
    end
    include EigenmethodStore
    include Seatbelt::Property::InstanceMethods

    class << self

      alias_method :_new, :new
      # Public: Overrides the Class#new method to create the class instance
      # eigenmethods.
      #
      # *args - An argumentlist passed to #initialize
      #
      # Returns the instance.
      def new(*args)
        obj = _new(*args)
        namespace = obj.class.name
        eigenmethods_for_scope = Terminal.
                                 for_scope_and_namespace(:instance,
                                                         namespace)
        unless eigenmethods_for_scope.empty?
          proxy = Seatbelt::Proxy.new
          receiver = eigenmethods_for_scope.first.receiver.new
          eigenmethods_for_scope.each do |eigenmethod|
            options = {:eigenmethod => eigenmethod,
                       :object      => obj,
                       :receiver    => receiver,
                       :return_method => true,
                       :add_to      => false
                      }
            obj.eigenmethods << Seatbelt::EigenmethodProxy.set(proxy, options)
            if obj.class.respond_to?(:synthesizers)
              synthesizers = obj.class.synthesizers.select do |synthesizer|
                synthesizer[:klass].eql?(obj.class.name)
              end
              unless synthesizers.empty?
                synthesizers.each do |synthesizer|
                  synthesizer[:adapter].new(obj.class, receiver).synthesize
                end
              end
            end
          end
        end
        return obj
      end
    end

  end
end