Class: RMonitor::Commands::Invoke

Inherits:
Object
  • Object
show all
Defined in:
lib/rmonitor/commands/invoke.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Invoke

Returns a new instance of Invoke.



4
5
6
7
8
9
# File 'lib/rmonitor/commands/invoke.rb', line 4

def initialize(options = {})
  @profiles = options[:profiles] || Config.new.profiles
  @matcher = options[:matcher] || Matcher.new(options)
  @strategy = options[:strategy] || Strategies::Pessimistic.new(options)
  @factory = options[:factory] || Actions.new(options)
end

Instance Method Details

#execute(name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/rmonitor/commands/invoke.rb', line 11

def execute(name)
  profile = @profiles.find { |p| p[:name] == name }

  raise UnknownProfileError unless profile
  raise UninvokableProfileError unless @matcher.invokable?(profile)

  actions = @factory.create(profile)

  @strategy.execute(actions)
end