Class: Hoth::Services

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

Class Method Summary collapse

Class Method Details

.define(&block) ⇒ Object

With Hoth::Services.define followed by a block you define all your available services.

Example:

Hoth::Services.define do

  service :increment_counter do |counter|
    returns :nothing
  end

  service :value_of_counter do |counter|
    returns :fixnum
  end

  service :create_account do ||
    returns :account_id
  end

end

after defining your services you can call each of them with Hoth::Services.service_name(params)

Hoth::Services.increment_counter(counter)
current_number = Hoth::Services.value_of_counter(counter)
 = Hoth::Services.()

see Hoth::ServiceDefinition for further informations of the block content.



35
36
37
# File 'lib/hoth/services.rb', line 35

def self.define(&block)
  ServiceDefinition.new.instance_eval(&block)
end

.method_missing(meth, *args, &blk) ⇒ Object

this is where the services get called



42
43
44
45
46
47
48
# File 'lib/hoth/services.rb', line 42

def method_missing(meth, *args, &blk) # :nodoc:
  if _service = ServiceRegistry.locate_service(meth)
    _service.execute(*args)
  else
    super
  end
end