class MotherBrain::Gear::Service

Attributes

actions[R]

@return [Set<Action>]

component[R]

@return [MB::Component]

name[R]

@return [String]

service_attribute[R]
service_group[R]
service_recipe[R]

Public Class Methods

find(gears, name) click to toggle source

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
new(component, name, &block) click to toggle source

@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

action(name) click to toggle source

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
action!(name) click to toggle source

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_action(new_action) click to toggle source

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
dynamic_service?() click to toggle source

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
set_service_attribute(attribute) click to toggle source
# File lib/mb/gears/service.rb, line 99
def set_service_attribute(attribute)
  @service_attribute = attribute
end
set_service_group(group) click to toggle source
# File lib/mb/gears/service.rb, line 91
def set_service_group(group)
  @service_group = group
end
set_service_recipe(recipe) click to toggle source
# File lib/mb/gears/service.rb, line 95
def set_service_recipe(recipe)
  @service_recipe = recipe
end
stop_action() click to toggle source

Find and return the stop action

@return [Gear::Action]

# File lib/mb/gears/service.rb, line 74
def stop_action
  action(:stop)
end
to_dynamic_service() click to toggle source

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

dsl_eval(&block) click to toggle source
# File lib/mb/gears/service.rb, line 123
def dsl_eval(&block)
  CleanRoom.new(self).instance_eval do
    instance_eval(&block)
  end
end
missing_fields_for_dynamic_service() click to toggle source
# 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