Class: Hoth::Service
- Inherits:
-
Object
- Object
- Hoth::Service
- Defined in:
- lib/hoth/service.rb
Instance Attribute Summary collapse
-
#module ⇒ Object
Returns the value of attribute module.
-
#name ⇒ Object
Returns the value of attribute name.
-
#params_arity ⇒ Object
Returns the value of attribute params_arity.
Instance Method Summary collapse
- #endpoint ⇒ Object
- #execute(*args) ⇒ Object
- #impl_class ⇒ Object
-
#initialize(name, &block) ⇒ Service
constructor
A new instance of Service.
- #is_local? ⇒ Boolean
- #return_nothing? ⇒ Boolean
- #returns(return_value) ⇒ Object
- #transport ⇒ Object
- #via_endpoint(via = nil) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Service
Returns a new instance of Service.
5 6 7 8 9 |
# File 'lib/hoth/service.rb', line 5 def initialize(name, &block) @name = name @params_arity = block.arity instance_eval(&block) end |
Instance Attribute Details
#module ⇒ Object
Returns the value of attribute module.
3 4 5 |
# File 'lib/hoth/service.rb', line 3 def module @module end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/hoth/service.rb', line 3 def name @name end |
#params_arity ⇒ Object
Returns the value of attribute params_arity.
3 4 5 |
# File 'lib/hoth/service.rb', line 3 def params_arity @params_arity end |
Instance Method Details
#endpoint ⇒ Object
46 47 48 |
# File 'lib/hoth/service.rb', line 46 def endpoint @endpoint ||= self.module[Hoth.env][@via_endpoint] end |
#execute(*args) ⇒ Object
33 34 35 36 |
# File 'lib/hoth/service.rb', line 33 def execute(*args) result = self.is_local? ? impl_class.send(:execute, *args) : transport.call_remote_with(*args) return return_nothing? ? nil : result end |
#impl_class ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/hoth/service.rb', line 19 def impl_class @impl_class_name ||= "#{self.name.to_s.camelize}Impl" begin @impl_class_name.constantize rescue NameError => e # no local implementation false end end |
#is_local? ⇒ Boolean
29 30 31 |
# File 'lib/hoth/service.rb', line 29 def is_local? !!impl_class end |
#return_nothing? ⇒ Boolean
38 39 40 |
# File 'lib/hoth/service.rb', line 38 def return_nothing? [:nothing, :nil, nil].include? @return_value end |
#returns(return_value) ⇒ Object
11 12 13 |
# File 'lib/hoth/service.rb', line 11 def returns(return_value) @return_value = return_value end |
#transport ⇒ Object
15 16 17 |
# File 'lib/hoth/service.rb', line 15 def transport @transport ||= Transport.create(endpoint.transport, self) end |
#via_endpoint(via = nil) ⇒ Object
42 43 44 |
# File 'lib/hoth/service.rb', line 42 def via_endpoint(via = nil) @via_endpoint = via || :default end |