Class: Chamber::NamespaceSet
- Inherits:
-
Object
- Object
- Chamber::NamespaceSet
- Includes:
- Enumerable
- Defined in:
- lib/chamber/namespace_set.rb
Instance Attribute Summary collapse
-
#raw_namespaces ⇒ Object
readonly
Returns the value of attribute raw_namespaces.
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(&block) ⇒ 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.
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_namespaces ⇒ Object
Returns the value of attribute raw_namespaces.
17 18 19 |
# File 'lib/chamber/namespace_set.rb', line 17 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
29 30 31 |
# File 'lib/chamber/namespace_set.rb', line 29 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
96 97 98 |
# File 'lib/chamber/namespace_set.rb', line 96 def ==(other) to_a.eql? other.to_a end |
#each(&block) ⇒ Object
Internal: Iterates over each namespace value and allows it to be used in a block.
74 75 76 |
# File 'lib/chamber/namespace_set.rb', line 74 def each(&block) namespaces.each(&block) end |
#eql?(other) ⇒ Boolean
Internal: Determines whether a NamespaceSet is equal to another NamespaceSet.
Returns a Boolean
106 107 108 109 |
# File 'lib/chamber/namespace_set.rb', line 106 def eql?(other) other.is_a?(NamespaceSet) && 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
84 85 86 |
# File 'lib/chamber/namespace_set.rb', line 84 def to_ary namespaces.to_a end |