Class: Chamber::NamespaceSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/chamber/namespace_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_namespaces = {}) ⇒ NamespaceSet

Internal: Creates a new NamespaceSet from arrays, hashes and sets.



36
37
38
# File 'lib/chamber/namespace_set.rb', line 36

def initialize(raw_namespaces = {})
  self.raw_namespaces = raw_namespaces
end

Instance Attribute Details

#raw_namespacesObject

Returns the value of attribute raw_namespaces.



31
32
33
# File 'lib/chamber/namespace_set.rb', line 31

def raw_namespaces
  @raw_namespaces
end

Class Method Details

.[](*namespace_values) ⇒ Object

Internal: Allows for more compact NamespaceSet creation by giving a list of namespace values.

Examples:

NamespaceSet['development', -> { ENV['HOST'] }]

Returns a new NamespaceSet



27
28
29
# File 'lib/chamber/namespace_set.rb', line 27

def self.[](*namespace_values)
  new(namespace_values)
end

Instance Method Details

#+(other) ⇒ Object

Internal: Allows a NamespaceSet to be combined with some other array-like object.

It does not mutate the source NamespaceSet but rather creates a new one and returns it.

Examples:

# Can be an Array
namespace_set = NamespaceSet.new ['value_1', 'value_2']
namespace_set + ['value_3']
# => <NamespaceSet namespaces=['value_1', 'value_2', 'value_3']>

# Can be a Set
namespace_set = NamespaceSet.new ['value_1', 'value_2']
namespace_set + Set['value_3']
# => <NamespaceSet namespaces=['value_1', 'value_2', 'value_3']>

# Can be a object which is convertable to an Array
namespace_set = NamespaceSet.new ['value_1', 'value_2']
namespace_set + (1..3)
# => <NamespaceSet namespaces=['value_1', 'value_2', '1', '2', '3']>

Returns a NamespaceSet



66
67
68
# File 'lib/chamber/namespace_set.rb', line 66

def +(other)
  NamespaceSet.new namespaces + other.to_a
end

#==(other) ⇒ Object

Internal: Determines whether a NamespaceSet is equal to another array-like object.

Returns a Boolean



98
99
100
# File 'lib/chamber/namespace_set.rb', line 98

def ==(other)
  to_a.eql? other.to_a
end

#eachObject

Internal: Iterates over each namespace value and allows it to be used in a block.



74
75
76
77
78
# File 'lib/chamber/namespace_set.rb', line 74

def each
  namespaces.each do |namespace|
    yield namespace
  end
end

#eql?(other) ⇒ Boolean

Internal: Determines whether a NamespaceSet is equal to another NamespaceSet.

Returns a Boolean

Returns:

  • (Boolean)


108
109
110
111
# File 'lib/chamber/namespace_set.rb', line 108

def eql?(other)
  other.is_a?(NamespaceSet) &&
  namespaces == other.namespaces
end

#to_aryObject Also known as: to_a

Internal: Converts a NamespaceSet into an Array consisting of the namespace values stored in the set.

Returns an Array



86
87
88
# File 'lib/chamber/namespace_set.rb', line 86

def to_ary
  namespaces.to_a
end