Class: Prick::Build::Node

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

Direct Known Subclasses

BuildNode, ExeNode, FoxNode, InlineNode, ModuleNode, SqlNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, phase, kind, path, args = nil) ⇒ Node

Returns a new instance of Node.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/builder/node.rb', line 32

def initialize(parent, phase, kind, path, args = nil) 
  constrain parent, BuildNode, NilClass
  constrain phase, :init, :decl, :seed, :term, nil
  constrain kind, :sql, :exe, :fox, :yml, :inline, :module
  constrain path, String, NilClass
  @parent, @phase, @kind, @path = parent, phase, kind, path
  @args = args&.empty? ? nil : args
  @schema = nil
  @source = nil
  @source_lines = nil
end

Instance Attribute Details

#argsObject (readonly)

only defined for :exe (String)



9
10
11
# File 'lib/builder/node.rb', line 9

def args
  @args
end

#kindObject (readonly)

:sql, :exe, :fox, :yml, :inline, :module



7
8
9
# File 'lib/builder/node.rb', line 7

def kind
  @kind
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/builder/node.rb', line 4

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#phaseObject (readonly)

:init, :decl, :seed, :term or nil (for BuildNode)



6
7
8
# File 'lib/builder/node.rb', line 6

def phase
  @phase
end

#sourceObject (readonly)

Returns the value of attribute source.



16
17
18
# File 'lib/builder/node.rb', line 16

def source
  @source
end

Instance Method Details

#dumpObject



46
# File 'lib/builder/node.rb', line 46

def dump() puts "#{inspect} (#{schema})" end

#inspectObject



45
# File 'lib/builder/node.rb', line 45

def inspect() to_s end

#linesObject



30
# File 'lib/builder/node.rb', line 30

def lines() prefix_lines + source_lines end

#nameObject



11
# File 'lib/builder/node.rb', line 11

def name() @name = File.basename(path) end

#prefix_linesObject



22
# File 'lib/builder/node.rb', line 22

def prefix_lines() 0 end

#schemaObject



13
# File 'lib/builder/node.rb', line 13

def schema() @schema ||= parent&.schema || "public" end

#schema=(s) ⇒ Object



14
# File 'lib/builder/node.rb', line 14

def schema=(s) @schema = s end

#source_linesObject



24
25
26
27
28
# File 'lib/builder/node.rb', line 24

def source_lines()
  return @source_lines if @source_lines
  source
  @source_lines
end

#to_sObject



44
# File 'lib/builder/node.rb', line 44

def to_s() [path, args].compact.join(" ") end