Class: Pluckr::Schema::Scope
- Inherits:
-
Object
- Object
- Pluckr::Schema::Scope
- Defined in:
- lib/pluckr/schema/scope.rb
Overview
A level of the AST: the nodes selected for one model (the root source, or one nested singular association).
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize(model, nodes) ⇒ Scope
constructor
A new instance of Scope.
- #ones ⇒ Object
- #outputs ⇒ Object
-
#rooted? ⇒ Boolean
True when anything here needs a root record to hang off.
Constructor Details
#initialize(model, nodes) ⇒ Scope
Returns a new instance of Scope.
10 11 12 13 14 |
# File 'lib/pluckr/schema/scope.rb', line 10 def initialize(model, nodes) @model = model @nodes = nodes.freeze freeze end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/pluckr/schema/scope.rb', line 8 def model @model end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
8 9 10 |
# File 'lib/pluckr/schema/scope.rb', line 8 def nodes @nodes end |
Instance Method Details
#fields ⇒ Object
16 17 18 |
# File 'lib/pluckr/schema/scope.rb', line 16 def fields nodes.grep(Field) end |
#ones ⇒ Object
20 21 22 |
# File 'lib/pluckr/schema/scope.rb', line 20 def ones nodes.grep(One) end |
#outputs ⇒ Object
24 25 26 |
# File 'lib/pluckr/schema/scope.rb', line 24 def outputs nodes.map(&:output) end |
#rooted? ⇒ Boolean
True when anything here needs a root record to hang off.
29 30 31 |
# File 'lib/pluckr/schema/scope.rb', line 29 def rooted? nodes.any? { |node| !(node.is_a?(Aggregate) && node.independent?) } end |