Class: Prick::Build::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Node.



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

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

Instance Attribute Details

#argsObject (readonly)

only defined for :exe (String)



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

def args
  @args
end

#kindObject (readonly)

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



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

def kind
  @kind
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#phaseObject (readonly)

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



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

def phase
  @phase
end

Instance Method Details

#dumpObject



48
# File 'lib/prick/builder/node.rb', line 48

def dump() puts "#{inspect} (#{@schema || 'nil'})" end

#inspectObject



47
# File 'lib/prick/builder/node.rb', line 47

def inspect() to_s end

#linesObject



31
# File 'lib/prick/builder/node.rb', line 31

def lines() prefix_lines + source_lines end

#nameObject



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

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

#prefix_linesObject



23
# File 'lib/prick/builder/node.rb', line 23

def prefix_lines() 0 end

#relpathObject



12
# File 'lib/prick/builder/node.rb', line 12

def relpath = path.sub(/^#{Dir.getwd}\//, "")

#schemaObject

Note that schema defaults to ‘public’ which may not be what you want in some cases



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

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

#schema=(s) ⇒ Object



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

def schema=(s) @schema = s end

#sourceObject



19
20
21
# File 'lib/prick/builder/node.rb', line 19

def source
  @source ||= read_source
end

#source_linesObject



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

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

#to_sObject



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

def to_s() @to_s ||= [path, *args].join(" ") end