Class: Chamber::NamespaceSet

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_namespaces = {}) ⇒ NamespaceSet

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



19
20
21
# File 'lib/chamber/namespace_set.rb', line 19

def initialize(raw_namespaces = {})
  self.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



33
34
35
# File 'lib/chamber/namespace_set.rb', line 33

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



63
64
65
# File 'lib/chamber/namespace_set.rb', line 63

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



95
96
97
# File 'lib/chamber/namespace_set.rb', line 95

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.



71
72
73
74
75
# File 'lib/chamber/namespace_set.rb', line 71

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)


105
106
107
108
# File 'lib/chamber/namespace_set.rb', line 105

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



83
84
85
# File 'lib/chamber/namespace_set.rb', line 83

def to_ary
  namespaces.to_a
end