Module: Cuprum::Collections::Scopes::Container
- Included in:
- Conjunction, Disjunction
- Defined in:
- lib/cuprum/collections/scopes/container.rb
Overview
Functionality for implementing a scope container.
Instance Attribute Summary collapse
-
#scopes ⇒ Array<Scope>
readonly
The scopes wrapped by the scope.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if the other object is a scope with matching type and child scopes; otherwise false.
-
#as_json ⇒ Hash{String=>Object}
A JSON-compatible representation of the scope.
- #debug ⇒ Object
-
#empty? ⇒ Boolean
True if the scope has no child scopes; otherwise false.
- #initialize(scopes:, **options) ⇒ Object
-
#with_scopes(scopes) ⇒ Scope
Creates a copy of the scope with the given child scopes.
Instance Attribute Details
#scopes ⇒ Array<Scope>
Returns the scopes wrapped by the scope.
18 19 20 |
# File 'lib/cuprum/collections/scopes/container.rb', line 18 def scopes @scopes end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if the other object is a scope with matching type and child scopes; otherwise false.
24 25 26 27 28 |
# File 'lib/cuprum/collections/scopes/container.rb', line 24 def ==(other) return false unless super other.scopes == scopes end |
#as_json ⇒ Hash{String=>Object}
Returns a JSON-compatible representation of the scope.
31 32 33 |
# File 'lib/cuprum/collections/scopes/container.rb', line 31 def as_json super.merge({ 'scopes' => scopes.map(&:as_json) }) end |
#debug ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cuprum/collections/scopes/container.rb', line 36 def debug # :nocov: = "#{super} (#{scopes.count})" return if empty? scopes.reduce("#{}:") do |str, scope| str + "\n- #{scope.debug.gsub("\n", "\n ")}" end # :nocov: end |
#empty? ⇒ Boolean
Returns true if the scope has no child scopes; otherwise false.
49 50 51 |
# File 'lib/cuprum/collections/scopes/container.rb', line 49 def empty? @scopes.empty? end |
#initialize(scopes:, **options) ⇒ Object
11 12 13 14 15 |
# File 'lib/cuprum/collections/scopes/container.rb', line 11 def initialize(scopes:, **) super(**) @scopes = scopes end |
#with_scopes(scopes) ⇒ Scope
Creates a copy of the scope with the given child scopes.
58 59 60 |
# File 'lib/cuprum/collections/scopes/container.rb', line 58 def with_scopes(scopes) dup.tap { |copy| copy.scopes = scopes } end |