Module: Powcloud::Insurance::HttpService

Included in:
AgentContainer
Defined in:
lib/powcloud/insurance/http_service.rb

Defined Under Namespace

Modules: ClassMethods Classes: HttpServiceBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



18
19
20
# File 'lib/powcloud/insurance/http_service.rb', line 18

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#create_http_serviceObject

Instance method! Creates unique HttpService class per agent instance.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/powcloud/insurance/http_service.rb', line 31

def create_http_service
  agent_instance = self

  block = self.class.send(:class_variable_get, :@@http_service_block)
  http_service_class = Class.new(HttpServiceBase) do |clazz|
    # NOTE: @@agent will create Class::@@agent variable, instad of http_service_class1::@@agent 
    class_variable_set(:@@agent, agent_instance)
  end

  # NOTE: Sinatra::Base.inherited callback is not called yet during do |clazz| block above.
  # This is why the following is going here, not in that block.
  http_service_class.register Sinatra::Async

  http_service_class.class_eval(&block)
  http_service_class
end