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.



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

def initialize(parent, phase, kind, path, args = nil)
  constrain parent, BuildNode, NilClass
  constrain phase, :init, :decl, :seed, :auth, :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

#dirObject



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

def dir() @dir ||= path && File.dirname(path) end

#dumpObject



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

def dump()
  if path =~ /(?:^|\/)schema\/#{@schema}\//
    puts inspect
  else
    puts "#{inspect} (#{@schema || 'nil'})"
  end
end

#inspectObject



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

def inspect() to_s end

#linesObject



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

def lines() prefix_lines + source_lines end

#nameObject



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

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

#prefix_linesObject



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

def prefix_lines() 0 end

#relpathObject



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

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

#schemaObject

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



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

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

#schema=(s) ⇒ Object



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

def schema=(s) @schema = s end

#sourceObject



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

def source
  @source ||= read_source
end

#source_linesObject



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

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

#to_sObject



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

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