Sha256: 1c7d695a306f915fcd36d1b8445cd046969e784cbee672d933b1532ec4c2072d

Contents?: true

Size: 879 Bytes

Versions: 13

Compression:

Stored size: 879 Bytes

Contents

require 'rubygems'
require 'simple_service'

class ConcatAnotherName < SimpleService::Command
  expects :first_name, :last_name
  returns :name

  def call
    self.name = "#{first_name} #{last_name}"
  end
end

class CreateAnotherHelloString < SimpleService::Command
  expects :name
  returns :hello

  def call
    self.hello ||= ''
    self.hello += "#{name}, say hello world!"
  end
end

class SayHelloMultipleTimes < SimpleService::Organizer
  expects :first_name, :last_name, :num_times
  returns :hello
  commands ConcatAnotherName, CreateAnotherHelloString

  # overriding the #call method on the organizer allows
  # you to do things like loop and call the service commands
  # multiple times
  def call
    num_times.times do
      super
    end
  end
end

result = SayHelloMultipleTimes.new(first_name: 'Ruby', last_name: 'Gem', num_times: 3).call
puts result[:hello]

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
simple_service-1.4.1 example/override_organizer_call_method.rb
simple_service-1.4.0 example/override_organizer_call_method.rb
simple_service-1.3.91 example/override_organizer_call_method.rb
simple_service-1.3.9 example/override_organizer_call_method.rb
simple_service-1.3.8 example/override_organizer_call_method.rb
simple_service-1.3.5 example/override_organizer_call_method.rb
simple_service-1.3.4 example/override_organizer_call_method.rb
simple_service-1.3.3 example/override_organizer_call_method.rb
simple_service-1.3.2 example/override_organizer_call_method.rb
simple_service-1.3.1 example/override_organizer_call_method.rb
simple_service-1.3.0 example/override_organizer_call_method.rb
simple_service-1.2.6 example/override_organizer_call_method.rb
simple_service-1.2.5 example/override_organizer_call_method.rb