Class: Flok::ServicesCompilerContext

Inherits:
Object
  • Object
show all
Defined in:
lib/flok/services_compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_context) ⇒ ServicesCompilerContext

Returns a new instance of ServicesCompilerContext.



53
54
55
56
57
58
59
60
# File 'lib/flok/services_compiler.rb', line 53

def initialize config_context
  @config = config_context

  #A hash containing the 'class' name of the service to a block that can be used with Service.new
  @_services = {}

  @services = []
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



51
52
53
# File 'lib/flok/services_compiler.rb', line 51

def config
  @config
end

#servicesObject

Returns the value of attribute services.



51
52
53
# File 'lib/flok/services_compiler.rb', line 51

def services
  @services
end

Instance Method Details

#get_bindingObject



78
79
80
# File 'lib/flok/services_compiler.rb', line 78

def get_binding
  return binding
end

#readyObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/flok/services_compiler.rb', line 62

def ready
  #Create an array from the service_instances where each element in the array is the full code of the service
  @config.service_instances.each do |i|
    #Get the instance name and class name of the service, normally defined in a ./config/services.rb file
    sname = i[:instance_name]
    sclass = i[:class]
    soptions = i[:options]

    sblock = @_services[sclass]
    raise "No service found for service_name: #{sclass.inspect} when trying to create service with instance name #{sname.inspect}. @_services contained: #{@_services.inspect} \[email protected]_instances contained: #{@config.service_instances.inspect}" unless sblock
    service = Service.new(sname, soptions)
    service.instance_eval(&sblock)
    @services << service
  end
end

#service(name, &block) ⇒ Object



82
83
84
# File 'lib/flok/services_compiler.rb', line 82

def service name, &block
  @_services[name] = block
end