Class: Prick::Build::NodePool

Inherits:
Object
  • Object
show all
Defined in:
lib/builder/node_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNodePool

Returns a new instance of NodePool.



21
22
23
# File 'lib/builder/node_pool.rb', line 21

def initialize() 
  self.clear
end

Instance Attribute Details

#decl_nodesObject (readonly)

Returns the value of attribute decl_nodes.



11
12
13
# File 'lib/builder/node_pool.rb', line 11

def decl_nodes
  @decl_nodes
end

#init_nodesObject (readonly)

Returns the value of attribute init_nodes.



10
11
12
# File 'lib/builder/node_pool.rb', line 10

def init_nodes
  @init_nodes
end

#nodesObject (readonly)

Returns the value of attribute nodes.



8
9
10
# File 'lib/builder/node_pool.rb', line 8

def nodes
  @nodes
end

#seed_nodesObject (readonly)

Returns the value of attribute seed_nodes.



12
13
14
# File 'lib/builder/node_pool.rb', line 12

def seed_nodes
  @seed_nodes
end

#term_nodesObject (readonly)

Returns the value of attribute term_nodes.



13
14
15
# File 'lib/builder/node_pool.rb', line 13

def term_nodes
  @term_nodes
end

Instance Method Details

#add(*nodes) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/builder/node_pool.rb', line 25

def add(*nodes)
  nodes = Array(nodes).flatten
  @nodes.concat(nodes)
  nodes.each { |node| 
    @schemas[node.schema] += 1
    @kind_nodes[node.phase]&.append(node)
  }
  self
end

#after_schema(s) ⇒ Object



6
# File 'lib/builder/node_pool.rb', line 6

def after_schema(s) schemas.reverse.take_while { |schema| schema != s }.reverse end

#before_schema(s) ⇒ Object



5
# File 'lib/builder/node_pool.rb', line 5

def before_schema(s) schemas.take_while { |schema| schema != s } end

#clear(*phases) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/builder/node_pool.rb', line 57

def clear(*phases)
  phases = Array(phases).flatten
  if !phases.empty?
    for phase in phases
      nodes = @kind_nodes[phase]
      nodes.each { |node| delete_node(node) }
      @kind_nodes[phase].clear
    end
  else
    @schemas = Hash.new(0) # map from schema name to number of nodes
    @nodes = []
    @init_nodes = []
    @decl_nodes = []
    @seed_nodes = []
    @term_nodes = []
    @kind_nodes = {
      decl: @decl_nodes,
      init: @init_nodes,
      seed: @seed_nodes,
      term: @term_nodes,
      yml: nil
    }
  end
end

#delete(*nodes) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/builder/node_pool.rb', line 35

def delete(*nodes)
#       puts "#delete(*nodes)"
  nodes = Array(nodes).flatten
  nodes.each { |node|
    delete_node(node)
    kind_nodes = @kind_nodes[node.phase] and kind_nodes.delete_at(kind_nodes.index(node))
  }
  nodes.last
end

#delete_if(phase = nil, &block) ⇒ Object



45
46
47
48
# File 'lib/builder/node_pool.rb', line 45

def delete_if(phase = nil, &block)
  candidates = @kind_nodes[phase] || @nodes
  delete(candidates.select { |node| yield(node) })
end

#delete_schema(*schemas, exclude: []) ⇒ Object



50
51
52
53
54
55
# File 'lib/builder/node_pool.rb', line 50

def delete_schema(*schemas, exclude: [])
  schemas = Array(schemas).flatten
  delete_if { |node| 
    schemas.include?(node.schema) && !exclude.include?(node.phase) && !exclude.include?(node.kind)
  }
end

#dumpObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/builder/node_pool.rb', line 82

def dump
  puts "NodePool, #{nodes.size} nodes"
  indent {
    puts "init_nodes:"
    indent { @init_nodes.each &:dump }
    puts "decl_nodes:"
    indent { @decl_nodes.each &:dump }
    puts "seed_nodes:"
    indent { @seed_nodes.each &:dump }
    puts "term_nodes:"
    indent { @term_nodes.each &:dump }
  }
end

#fox_seed_nodesObject

attr_reader :setup_nodes attr_reader :teardown_nodes



18
# File 'lib/builder/node_pool.rb', line 18

def fox_seed_nodes() seed_nodes.select { |node| node.kind == :fox } end

#schemasObject



4
# File 'lib/builder/node_pool.rb', line 4

def schemas() @schemas.keys end

#sql_seed_nodesObject



19
# File 'lib/builder/node_pool.rb', line 19

def sql_seed_nodes() seed_nodes.select { |node| node.kind == :sql } end