class SqlMigrations::File
Class that represents script file
Attributes
database[R]
date[R]
datetime[R]
name[R]
path[R]
time[R]
type[R]
Public Class Methods
new(path, database, type)
click to toggle source
# File lib/sql_migrations/file.rb, line 7 def initialize(path, database, type) @path = path @database = database @type = type.to_s @file, @base, @parent = elements(path) @date, @time, @name = match(@file) if @file @datetime = (@date.to_s + @time.to_s).to_i end
Public Instance Methods
==(other)
click to toggle source
# File lib/sql_migrations/file.rb, line 25 def ==(other) datetime == other.datetime end
content()
click to toggle source
# File lib/sql_migrations/file.rb, line 21 def content ::File.read(@path) end
to_s()
click to toggle source
# File lib/sql_migrations/file.rb, line 29 def to_s @file.to_s end
valid?()
click to toggle source
# File lib/sql_migrations/file.rb, line 17 def valid? [@name, @time, @date, @database, directories?].all? end
Private Instance Methods
directories?()
click to toggle source
# File lib/sql_migrations/file.rb, line 48 def directories? if @database == :default file_in_type_base_directory? || file_in_database_directory? else file_in_database_directory? end end
elements(path)
click to toggle source
# File lib/sql_migrations/file.rb, line 35 def elements(path) _filename, _base_directory, _parent_directory = path.split(::File::SEPARATOR).last(3).reverse rescue ArgumentError => e puts "Invalid path: #{path}" end
file_in_database_directory?()
click to toggle source
# File lib/sql_migrations/file.rb, line 64 def file_in_database_directory? file_in_type_parent_directory? && (@base == @database.to_s) end
file_in_type_base_directory?()
click to toggle source
# File lib/sql_migrations/file.rb, line 56 def file_in_type_base_directory? @base == "#{@type}s" end
file_in_type_parent_directory?()
click to toggle source
# File lib/sql_migrations/file.rb, line 60 def file_in_type_parent_directory? @parent == "#{@type}s" end
match(filename)
click to toggle source
# File lib/sql_migrations/file.rb, line 42 def match(filename) _, date, time, name = filename.match(/^(\d{8})_(\d{6})_(.*)?\.sql$/).to_a [date, time, name] end