Class: MotherBrain::Gear::Service
- Defined in:
- lib/mb/gears/service.rb,
lib/mb/gears/service/action.rb,
lib/mb/gears/service/action_runner.rb
Defined Under Namespace
Classes: Action, ActionRunner, CleanRoom
Instance Attribute Summary collapse
- #actions ⇒ Set<Action> readonly
- #component ⇒ MB::Component readonly
- #name ⇒ String readonly
-
#service_attribute ⇒ Object
readonly
Returns the value of attribute service_attribute.
-
#service_group ⇒ Object
readonly
Returns the value of attribute service_group.
-
#service_recipe ⇒ Object
readonly
Returns the value of attribute service_recipe.
Class Method Summary collapse
-
.find(gears, name) ⇒ MB::Gear::Service
Finds a gear identified by name in the list of gears supplied.
Instance Method Summary collapse
-
#action(name) ⇒ Gear::Action
Find and return the given action.
-
#action!(name) ⇒ Gear::Action
Find and return the given action.
-
#add_action(new_action) ⇒ Set<Action>
Add a new action to this Service.
-
#dynamic_service? ⇒ Boolean
Indicates whether this service conforms to the dyanamic service pattern.
-
#initialize(component, name, &block) ⇒ Service
constructor
A new instance of Service.
- #set_service_attribute(attribute) ⇒ Object
- #set_service_group(group) ⇒ Object
- #set_service_recipe(recipe) ⇒ Object
-
#stop_action ⇒ Gear::Action
Find and return the stop action.
-
#to_dynamic_service ⇒ MB::Gears::DynamicService
Convert a Service to a DynamicService.
Methods inherited from Base
Constructor Details
#initialize(component, name, &block) ⇒ Service
Returns a new instance of Service.
33 34 35 36 37 38 39 40 41 |
# 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 |
Instance Attribute Details
#actions ⇒ Set<Action> (readonly)
23 24 25 |
# File 'lib/mb/gears/service.rb', line 23 def actions @actions end |
#component ⇒ MB::Component (readonly)
25 26 27 |
# File 'lib/mb/gears/service.rb', line 25 def component @component end |
#name ⇒ String (readonly)
21 22 23 |
# File 'lib/mb/gears/service.rb', line 21 def name @name end |
#service_attribute ⇒ Object (readonly)
Returns the value of attribute service_attribute.
29 30 31 |
# File 'lib/mb/gears/service.rb', line 29 def service_attribute @service_attribute end |
#service_group ⇒ Object (readonly)
Returns the value of attribute service_group.
27 28 29 |
# File 'lib/mb/gears/service.rb', line 27 def service_group @service_group end |
#service_recipe ⇒ Object (readonly)
Returns the value of attribute service_recipe.
28 29 30 |
# File 'lib/mb/gears/service.rb', line 28 def service_recipe @service_recipe end |
Class Method Details
.find(gears, name) ⇒ MB::Gear::Service
Finds a gear identified by name in the list of gears supplied.
15 16 17 |
# File 'lib/mb/gears/service.rb', line 15 def find(gears, name) gears.find { |obj| obj.name == name.to_s } end |
Instance Method Details
#action(name) ⇒ Gear::Action
Find and return the given action
67 68 69 |
# File 'lib/mb/gears/service.rb', line 67 def action(name) actions.find { |action| action.name == name } end |
#action!(name) ⇒ Gear::Action
Find and return the given action
50 51 52 53 54 55 56 57 58 |
# 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) ⇒ Set<Action>
Add a new action to this Service
83 84 85 86 87 88 89 |
# 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? ⇒ Boolean
Indicates whether this service conforms to the dyanamic service pattern
117 118 119 |
# File 'lib/mb/gears/service.rb', line 117 def dynamic_service? missing_fields_for_dynamic_service.empty? end |
#set_service_attribute(attribute) ⇒ Object
99 100 101 |
# File 'lib/mb/gears/service.rb', line 99 def set_service_attribute(attribute) @service_attribute = attribute end |
#set_service_group(group) ⇒ Object
91 92 93 |
# File 'lib/mb/gears/service.rb', line 91 def set_service_group(group) @service_group = group end |
#set_service_recipe(recipe) ⇒ Object
95 96 97 |
# File 'lib/mb/gears/service.rb', line 95 def set_service_recipe(recipe) @service_recipe = recipe end |
#stop_action ⇒ Gear::Action
Find and return the stop action
74 75 76 |
# File 'lib/mb/gears/service.rb', line 74 def stop_action action(:stop) end |
#to_dynamic_service ⇒ MB::Gears::DynamicService
Convert a Service to a DynamicService
106 107 108 109 110 111 112 |
# 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 |