Class: Prick::Build::NodePool
- Inherits:
-
Object
- Object
- Prick::Build::NodePool
- Defined in:
- lib/prick/builder/node_pool.rb
Instance Attribute Summary collapse
-
#all_nodes ⇒ Object
readonly
All nodes including nodes deleted later on.
-
#decl_nodes ⇒ Object
readonly
Returns the value of attribute decl_nodes.
-
#init_nodes ⇒ Object
readonly
Returns the value of attribute init_nodes.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#seed_nodes ⇒ Object
readonly
Returns the value of attribute seed_nodes.
-
#term_nodes ⇒ Object
readonly
Returns the value of attribute term_nodes.
Instance Method Summary collapse
- #add(*nodes) ⇒ Object
- #after_schema(s) ⇒ Object
- #before_schema(s) ⇒ Object
-
#build_nodes ⇒ Object
List of BuildNode nodes.
- #clear(*phases) ⇒ Object
- #delete(*nodes) ⇒ Object
- #delete_if(phase = nil, &block) ⇒ Object
- #delete_schema(*schemas, exclude: []) ⇒ Object
- #dump ⇒ Object
-
#fox_seed_nodes ⇒ Object
attr_reader :setup_nodes attr_reader :teardown_nodes.
-
#initialize ⇒ NodePool
constructor
A new instance of NodePool.
- #keep_schemas ⇒ Object
-
#pg_graph_ignore_schemas ⇒ Object
List of schemas to ignore when building PgGraph objects.
-
#refresh_schemas ⇒ Object
List of schemas that should be rebuilt.
- #schemas ⇒ Object
- #sql_seed_nodes ⇒ Object
Constructor Details
#initialize ⇒ NodePool
Returns a new instance of NodePool.
46 47 48 |
# File 'lib/prick/builder/node_pool.rb', line 46 def initialize() self.clear end |
Instance Attribute Details
#all_nodes ⇒ Object (readonly)
All nodes including nodes deleted later on
11 12 13 |
# File 'lib/prick/builder/node_pool.rb', line 11 def all_nodes @all_nodes end |
#decl_nodes ⇒ Object (readonly)
Returns the value of attribute decl_nodes.
14 15 16 |
# File 'lib/prick/builder/node_pool.rb', line 14 def decl_nodes @decl_nodes end |
#init_nodes ⇒ Object (readonly)
Returns the value of attribute init_nodes.
13 14 15 |
# File 'lib/prick/builder/node_pool.rb', line 13 def init_nodes @init_nodes end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
8 9 10 |
# File 'lib/prick/builder/node_pool.rb', line 8 def nodes @nodes end |
#seed_nodes ⇒ Object (readonly)
Returns the value of attribute seed_nodes.
15 16 17 |
# File 'lib/prick/builder/node_pool.rb', line 15 def seed_nodes @seed_nodes end |
#term_nodes ⇒ Object (readonly)
Returns the value of attribute term_nodes.
16 17 18 |
# File 'lib/prick/builder/node_pool.rb', line 16 def term_nodes @term_nodes end |
Instance Method Details
#add(*nodes) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/prick/builder/node_pool.rb', line 50 def add(*nodes) nodes = Array(nodes).flatten term_nodes = [] # Ugly hack to do recursive init/term but preserve order within a term block @nodes.concat(nodes) @all_nodes.concat(nodes) nodes.each { |node| @schemas[node.schema] += 1 if node.phase == :term term_nodes << node else @kind_nodes[node.phase]&.append(node) end } term_nodes.reverse.each { |node| @kind_nodes[:term]&.append node } self end |
#after_schema(s) ⇒ Object
6 |
# File 'lib/prick/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/prick/builder/node_pool.rb', line 5 def before_schema(s) schemas.take_while { |schema| schema != s } end |
#build_nodes ⇒ Object
List of BuildNode nodes
25 |
# File 'lib/prick/builder/node_pool.rb', line 25 def build_nodes() nodes.select { |node| node.is_a?(BuildNode) } end |
#clear(*phases) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/prick/builder/node_pool.rb', line 89 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 = [] @all_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
67 68 69 70 71 72 73 74 75 |
# File 'lib/prick/builder/node_pool.rb', line 67 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
77 78 79 80 |
# File 'lib/prick/builder/node_pool.rb', line 77 def delete_if(phase = nil, &block) candidates = @kind_nodes[phase] || @nodes delete(candidates.select { |node| yield(node) }) end |
#delete_schema(*schemas, exclude: []) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/prick/builder/node_pool.rb', line 82 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 |
#dump ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/prick/builder/node_pool.rb', line 115 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_nodes ⇒ Object
attr_reader :setup_nodes attr_reader :teardown_nodes
21 |
# File 'lib/prick/builder/node_pool.rb', line 21 def fox_seed_nodes() seed_nodes.select { |node| node.kind == :fox } end |
#keep_schemas ⇒ Object
42 43 44 |
# File 'lib/prick/builder/node_pool.rb', line 42 def keep_schemas() build_nodes.reject(&:refresh_schema).map(&:schema).uniq end |
#pg_graph_ignore_schemas ⇒ Object
List of schemas to ignore when building PgGraph objects. This is used to exclude foreign schemas that doesn’t follow the PgGraph naming conventions
30 31 32 33 34 |
# File 'lib/prick/builder/node_pool.rb', line 30 def pg_graph_ignore_schemas() all_nodes.select { |node| node.is_a?(BuildNode) && node.pg_graph_ignore_schema }.map(&:schema).uniq end |
#refresh_schemas ⇒ Object
List of schemas that should be rebuilt. #refresh_schemas is not cached and can be manipulated by removing build nodes from the pool
38 39 40 |
# File 'lib/prick/builder/node_pool.rb', line 38 def refresh_schemas() build_nodes.select(&:refresh_schema).map(&:schema).uniq end |
#schemas ⇒ Object
4 |
# File 'lib/prick/builder/node_pool.rb', line 4 def schemas() @schemas.keys end |
#sql_seed_nodes ⇒ Object
22 |
# File 'lib/prick/builder/node_pool.rb', line 22 def sql_seed_nodes() seed_nodes.select { |node| node.kind == :sql } end |