Class: EnvironmentRequirement

Inherits:
HasAttributes show all
Defined in:
lib/hosties/Definitions.rb

Overview

Used to describe an environment.

Instance Attribute Summary collapse

Attributes inherited from HasAttributes

#attributes, #constraints

Instance Method Summary collapse

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

#groupingObject (readonly)

Returns the value of attribute grouping.



96
97
98
# File 'lib/hosties/Definitions.rb', line 96

def grouping
  @grouping
end

#hostsObject (readonly)

Returns the value of attribute hosts.



96
97
98
# File 'lib/hosties/Definitions.rb', line 96

def hosts
  @hosts
end

#typeObject (readonly)

Returns the value of attribute type.



96
97
98
# File 'lib/hosties/Definitions.rb', line 96

def type
  @type
end

Instance Method Details

#finishedObject



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.

Raises:

  • (ArgumentError)


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