class MinceMigrator::Migrations::File

Attributes

name[R]

Public Class Methods

convert_path_to_name(path) click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 63
def self.convert_path_to_name(path)
  path.split("/")[-1].gsub('.rb', '')
end
find(name) click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 58
def self.find(name)
  file = new(name)
  file.tap(&:load) if file.persisted?
end
load_from_file(path_to_file) click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 53
def self.load_from_file(path_to_file)
  name = convert_path_to_name(path_to_file)
  find(name)
end
new(name) click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 11
def initialize(name)
  @original_name = name
  @version = 1
  self.name = name
end

Public Instance Methods

body() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 41
def body
  @body ||= Template.new(klass_name).render
end
filename() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 25
def filename
  "#{name}.rb"
end
full_path() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 29
def full_path
  ::File.join Config.migration_dir, filename
end
full_relative_path() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 17
def full_relative_path
  ::File.join(Config.migration_relative_dir, filename)
end
klass() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 37
def klass
  loader.klass
end
klass_name() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 33
def klass_name
  name.split("_").map(&:capitalize).join
end
load() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 49
def load
  loader.call
end
name=(val) click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 21
def name=(val)
  @name = val.gsub(" ", "_").downcase
end
persisted?() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 45
def persisted?
  ::File.exists?(full_path)
end

Private Instance Methods

loader() click to toggle source
# File lib/mince_migrator/migrations/file.rb, line 69
def loader
  @loader ||= Loader.new(full_path: full_path, klass_name: klass_name)
end