Class: Skiima::Dependency::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/skiima/dependency/script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, adapter, version, scriptname) ⇒ Script

Returns a new instance of Script.



9
10
11
12
# File 'lib/skiima/dependency/script.rb', line 9

def initialize(group, adapter, version, scriptname)
  @group, @adapter, @version = group.to_s, adapter.to_s, version.to_s
  set_attr(scriptname)
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



5
6
7
# File 'lib/skiima/dependency/script.rb', line 5

def adapter
  @adapter
end

#attrObject

Returns the value of attribute attr.



6
7
8
# File 'lib/skiima/dependency/script.rb', line 6

def attr
  @attr
end

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/skiima/dependency/script.rb', line 7

def content
  @content
end

#filenameObject

Returns the value of attribute filename.



7
8
9
# File 'lib/skiima/dependency/script.rb', line 7

def filename
  @filename
end

#groupObject

Returns the value of attribute group.



5
6
7
# File 'lib/skiima/dependency/script.rb', line 5

def group
  @group
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/skiima/dependency/script.rb', line 6

def name
  @name
end

#sqlObject

Returns the value of attribute sql.



7
8
9
# File 'lib/skiima/dependency/script.rb', line 7

def sql
  @sql
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/skiima/dependency/script.rb', line 6

def type
  @type
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/skiima/dependency/script.rb', line 5

def version
  @version
end

Instance Method Details

#down_filenameObject



29
30
31
# File 'lib/skiima/dependency/script.rb', line 29

def down_filename
  filename.sub('.sql', '.drop.sql')
end

#full_down_filename(root) ⇒ Object



45
46
47
# File 'lib/skiima/dependency/script.rb', line 45

def full_down_filename(root)
  File.join(root, group, down_filename)
end

#full_filename(root) ⇒ Object



41
42
43
# File 'lib/skiima/dependency/script.rb', line 41

def full_filename(root)
  File.join(root, group, filename)
end

#interpolate_sql(char, vars = {}) ⇒ Object



25
26
27
# File 'lib/skiima/dependency/script.rb', line 25

def interpolate_sql(char, vars = {})
  @sql = Skiima.interpolate_sql(char, @content, vars)
end

#read_content(direction, root) ⇒ Object



18
19
20
21
22
23
# File 'lib/skiima/dependency/script.rb', line 18

def read_content(direction, root)
  @content = case
    when (direction == :up) then read_upfile(root)
    when (direction == :down && down_script?(root)) then read_downfile(root)
  end
end

#read_downfile(root) ⇒ Object



37
38
39
# File 'lib/skiima/dependency/script.rb', line 37

def read_downfile(root)
  File.open(full_down_filename(root)).read
end

#read_upfile(root) ⇒ Object



33
34
35
# File 'lib/skiima/dependency/script.rb', line 33

def read_upfile(root)
  File.open(full_filename(root)).read
end