Top Level Namespace

Defined Under Namespace

Modules: ServiceProvider

Instance Method Summary collapse

Instance Method Details

#require_service(service_name) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/service_provider.rb', line 60

def require_service(service_name)
  self.send(:define_method, "#{service_name}=") do |value|
    instance_variable_set("@#{service_name}", value)
  end
  self.send(:define_method, "#{service_name.to_s}") do 
    service = instance_variable_get("@#{service_name.to_sym}")
    unless service
      service = ServiceProvider.provider.get_service(service_name.to_sym)
      instance_variable_set("@#{service_name.to_sym}", service)
    end  
    service
  end
  
end