Class: Chamber::NamespaceSet
- Inherits:
-
Object
- Object
- Chamber::NamespaceSet
- Includes:
- Enumerable
- Defined in:
- lib/chamber/namespace_set.rb
Class Method Summary collapse
-
.[](*namespace_values) ⇒ Object
Internal: Allows for more compact NamespaceSet creation by giving a list of namespace values.
Instance Method Summary collapse
-
#+(other) ⇒ Object
Internal: Allows a NamespaceSet to be combined with some other array-like object.
-
#==(other) ⇒ Object
Internal: Determines whether a NamespaceSet is equal to another array-like object.
-
#each ⇒ Object
Internal: Iterates over each namespace value and allows it to be used in a block.
-
#eql?(other) ⇒ Boolean
Internal: Determines whether a NamespaceSet is equal to another NamespaceSet.
-
#initialize(raw_namespaces = {}) ⇒ NamespaceSet
constructor
Internal: Creates a new NamespaceSet from arrays, hashes and sets.
-
#to_ary ⇒ Object
(also: #to_a)
Internal: Converts a NamespaceSet into an Array consisting of the namespace values stored in the set.
Constructor Details
#initialize(raw_namespaces = {}) ⇒ NamespaceSet
Internal: Creates a new NamespaceSet from arrays, hashes and sets.
18 19 20 |
# File 'lib/chamber/namespace_set.rb', line 18 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
32 33 34 |
# File 'lib/chamber/namespace_set.rb', line 32 def self.[](*namespace_values) self.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
62 63 64 |
# File 'lib/chamber/namespace_set.rb', line 62 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
94 95 96 |
# File 'lib/chamber/namespace_set.rb', line 94 def ==(other) self.to_a.eql? other.to_a end |
#each ⇒ Object
Internal: Iterates over each namespace value and allows it to be used in a block.
70 71 72 73 74 |
# File 'lib/chamber/namespace_set.rb', line 70 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
104 105 106 107 |
# File 'lib/chamber/namespace_set.rb', line 104 def eql?(other) other.is_a?( NamespaceSet) && self.namespaces == other.namespaces end |
#to_ary ⇒ Object Also known as: to_a
Internal: Converts a NamespaceSet into an Array consisting of the namespace values stored in the set.
Returns an Array
82 83 84 |
# File 'lib/chamber/namespace_set.rb', line 82 def to_ary namespaces.to_a end |