class MotherBrain::Gear::Service
Attributes
@return [Set<Action>]
@return [MB::Component]
@return [String]
Public Class Methods
Finds a gear identified by name in the list of gears supplied.
@param [Array<MB::Gear::Service>] gears
the list of gears to search in
@param [#to_s] name
the name of the gear to search for
@return [MB::Gear::Service]
# File lib/mb/gears/service.rb, line 15 def find(gears, name) gears.find { |obj| obj.name == name.to_s } end
@param [MB::Component] component @param [#to_s] name
# File lib/mb/gears/service.rb, line 33 def initialize(component, name, &block) @name = name.to_s @component = component @actions = Set.new if block_given? dsl_eval(&block) end end
Public Instance Methods
Find and return the given action
@param [String] name
@raise [ActionNotFound] if there is no action of the given name defined
@return [Gear::Action]
# File lib/mb/gears/service.rb, line 67 def action(name) actions.find { |action| action.name == name } end
Find and return the given action
@param [String] name
@raise [ActionNotFound] if there is no action of the given name defined
@return [Gear::Action]
# File lib/mb/gears/service.rb, line 50 def action!(name) action = action(name) unless action raise ActionNotFound, "#{self.class.keyword} '#{_attributes_[:name]}' does not have the action '#{name}'" end action end
Add a new action to this Service
@param [Service::Action] new_action
@return [Set<Action>]
# File lib/mb/gears/service.rb, line 83 def add_action(new_action) if action(new_action.name) raise DuplicateAction, "Action '#{new_action.name}' already defined on service '#{_attributes_[:name]}'" end actions << new_action end
Indicates whether this service conforms to the dyanamic service pattern
@return TrueClass, FalseClass
# File lib/mb/gears/service.rb, line 117 def dynamic_service? missing_fields_for_dynamic_service.empty? end
# File lib/mb/gears/service.rb, line 99 def set_service_attribute(attribute) @service_attribute = attribute end
# File lib/mb/gears/service.rb, line 91 def set_service_group(group) @service_group = group end
# File lib/mb/gears/service.rb, line 95 def set_service_recipe(recipe) @service_recipe = recipe end
Find and return the stop action
@return [Gear::Action]
# File lib/mb/gears/service.rb, line 74 def stop_action action(:stop) end
Convert a Service
to a DynamicService
@return [MB::Gears::DynamicService]
# File lib/mb/gears/service.rb, line 106 def to_dynamic_service log { "Service '#{self.name}' does not appear to by a dynamic service. It does not define the following fields which are required for dynamic services: #{self.missing_fields_for_dynamic_service.join(",")}" } unless dynamic_service? MotherBrain::Gear::DynamicService.new(component.name, name) end
Private Instance Methods
# File lib/mb/gears/service.rb, line 123 def dsl_eval(&block) CleanRoom.new(self).instance_eval do instance_eval(&block) end end
# File lib/mb/gears/service.rb, line 129 def missing_fields_for_dynamic_service %w[service_group service_recipe service_attribute].collect do |field| field if self.instance_variable_get("@#{field}").nil? end.compact end