Method: Sunshine::App#with_server_apps

Defined in:
lib/sunshine/app.rb

#with_server_apps(search_options, options = {}) ⇒ Object

Calls a method for server_apps found with the passed options, and with an optional log message. Supports all App#find options, plus:

:no_threads

bool - disable threaded execution

:msg

“some message” - log message

app.with_server_apps :all, :msg => "doing something" do |server_app|
  # do something here
end

app.with_server_apps :role => :db, :user => "bob" do |server_app|
  # do something here
end


750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/sunshine/app.rb', line 750

def with_server_apps search_options, options={}
  options = search_options.merge options if Hash === search_options

  message = options[:msg]
  method  = options[:no_threads] ? :each : :threaded_each

  block = lambda do
    send(method, search_options) do |server_app|

      if block_given?
        yield(server_app)

      elsif options[:send]
        server_app.send(*options[:send])
      end
    end
  end


  if message
    Sunshine.logger.info(:app, message, &block)

  else
    block.call
  end
end