Class: Hoth::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/hoth/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#moduleObject

Returns the value of attribute module.



3
4
5
# File 'lib/hoth/service.rb', line 3

def module
  @module
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/hoth/service.rb', line 3

def name
  @name
end

#params_arityObject

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

#endpointObject



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_classObject



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/hoth/service.rb', line 29

def is_local?
  !!impl_class
end

#return_nothing?Boolean

Returns:

  • (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

#transportObject



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