Class: EnvironmentRequirement
- Inherits:
-
HasAttributes
- Object
- HasAttributes
- EnvironmentRequirement
- Defined in:
- lib/hosties/Definitions.rb
Overview
Used to describe an environment.
Instance Attribute Summary collapse
-
#grouping ⇒ Object
readonly
Returns the value of attribute grouping.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from HasAttributes
Instance Method Summary collapse
- #finished ⇒ Object
-
#grouped_by(attr) ⇒ Object
Optionally specify an attribute to group by when registering environments of this type.
-
#initialize(type) ⇒ EnvironmentRequirement
constructor
A new instance of EnvironmentRequirement.
-
#need(host1, *more) ⇒ Object
Define the hosts that an environment needs to be valid, for instance, maybe you need a :logger host and a :service host at a minimum.
Methods inherited from HasAttributes
#have_attributes, #valid?, #where
Constructor Details
#initialize(type) ⇒ EnvironmentRequirement
Returns a new instance of EnvironmentRequirement.
97 98 99 100 101 |
# File 'lib/hosties/Definitions.rb', line 97 def initialize(type) super() @type = type @hosts = [] end |
Instance Attribute Details
#grouping ⇒ Object (readonly)
Returns the value of attribute grouping.
96 97 98 |
# File 'lib/hosties/Definitions.rb', line 96 def grouping @grouping end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
96 97 98 |
# File 'lib/hosties/Definitions.rb', line 96 def hosts @hosts end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
96 97 98 |
# File 'lib/hosties/Definitions.rb', line 96 def type @type end |
Instance Method Details
#finished ⇒ Object
122 123 124 |
# File 'lib/hosties/Definitions.rb', line 122 def finished Hosties::EnvironmentDefinitions[@type] = self end |
#grouped_by(attr) ⇒ Object
Optionally specify an attribute to group by when registering environments of this type.
117 118 119 120 |
# File 'lib/hosties/Definitions.rb', line 117 def grouped_by(attr) raise ArgumentError, "Unknown attribute #{attr}" unless @attributes.include?(attr) @grouping = attr end |
#need(host1, *more) ⇒ Object
Define the hosts that an environment needs to be valid, for instance, maybe you need a :logger host and a :service host at a minimum.
106 107 108 109 110 111 112 113 |
# File 'lib/hosties/Definitions.rb', line 106 def need(host1, *more) sum = more << host1 # Array doesn't have an 'exists' method, so behold - map reduce wankery! unless sum.map { |x| Hosties::HostDefinitions.include? x }.reduce(true) { |xs, x| x & xs } raise ArgumentError, "Unrecognized host type" end @hosts += sum end |