Class: Migr8::Migration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version = nil, author = nil, desc = nil) ⇒ Migration

Returns a new instance of Migration.



56
57
58
59
60
61
62
63
64
# File 'lib/migr8.rb', line 56

def initialize(version=nil, author=nil, desc=nil)
  #; [!y4dy3] takes version, author, and desc arguments.
  @version = version
  @author  = author
  @desc    = desc
  @vars    = {}
  @up      = ''
  @down    = ''
end

Instance Attribute Details

#applied_atObject

Returns the value of attribute applied_at.



54
55
56
# File 'lib/migr8.rb', line 54

def applied_at
  @applied_at
end

#authorObject

Returns the value of attribute author.



53
54
55
# File 'lib/migr8.rb', line 53

def author
  @author
end

#descObject

Returns the value of attribute desc.



53
54
55
# File 'lib/migr8.rb', line 53

def desc
  @desc
end

#downObject

Returns the value of attribute down.



53
54
55
# File 'lib/migr8.rb', line 53

def down
  @down
end

#down_scriptObject

Returns the value of attribute down_script.



54
55
56
# File 'lib/migr8.rb', line 54

def down_script
  @down_script
end

#idObject

Returns the value of attribute id.



54
55
56
# File 'lib/migr8.rb', line 54

def id
  @id
end

#upObject

Returns the value of attribute up.



53
54
55
# File 'lib/migr8.rb', line 53

def up
  @up
end

#up_scriptObject

Returns the value of attribute up_script.



54
55
56
# File 'lib/migr8.rb', line 54

def up_script
  @up_script
end

#varsObject

Returns the value of attribute vars.



53
54
55
# File 'lib/migr8.rb', line 53

def vars
  @vars
end

#versionObject

Returns the value of attribute version.



53
54
55
# File 'lib/migr8.rb', line 53

def version
  @version
end

Class Method Details

.load_from(filepath) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/migr8.rb', line 113

def self.load_from(filepath)
  #; [!fbea5] loads data from file and returns migration object.
  data = File.open(filepath) {|f| YAML.load(f) }
  mig = self.new(data['version'], data['author'], data['desc'])
  #; [!sv21s] expands values of 'vars'.
  mig.vars = Util::Expander.expand_vars(data['vars'])
  #; [!32ns3] not expand both 'up' and 'down'.
  mig.up   = data['up']
  mig.down = data['down']
  return mig
end

Instance Method Details

#applied?Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/migr8.rb', line 66

def applied?
  #; [!ebzct] returns false when @applied_at is nil, else true.
  return ! @applied_at.nil?
end

#applied_at_or(default) ⇒ Object



99
100
101
102
103
104
# File 'lib/migr8.rb', line 99

def applied_at_or(default)
  #; [!zazux] returns default arugment when not applied.
  return default unless applied?
  #; [!fxb4y] returns @applied_at without msec.
  return @applied_at.split(/\./)[0]   # '12:34:56.789' -> '12:34:56'
end

#filepathObject



106
107
108
109
110
111
# File 'lib/migr8.rb', line 106

def filepath
  #; [!l9t5k] returns nil when version is not set.
  return nil unless @version
  #; [!p0d9q] returns filepath of migration file.
  return Repository.new(nil).migration_filepath(@version)
end