Class: Pluckr::Schema::Scope

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/pluckr/schema/scope.rb', line 8

def model
  @model
end

#nodesObject (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

#fieldsObject



16
17
18
# File 'lib/pluckr/schema/scope.rb', line 16

def fields
  nodes.grep(Field)
end

#onesObject



20
21
22
# File 'lib/pluckr/schema/scope.rb', line 20

def ones
  nodes.grep(One)
end

#outputsObject



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.

Returns:

  • (Boolean)


29
30
31
# File 'lib/pluckr/schema/scope.rb', line 29

def rooted?
  nodes.any? { |node| !(node.is_a?(Aggregate) && node.independent?) }
end