class MigrationSignature::Config

Constants

CONFIG_FILE_PATH
DEFAULTS

Public Class Methods

load() click to toggle source
# File lib/migration_signature/config.rb, line 13
def self.load
  return new(DEFAULTS) unless File.exist?(CONFIG_FILE_PATH)

  require 'yaml'
  hash = YAML.safe_load(File.read(CONFIG_FILE_PATH), [Regexp]) || {}

  new(DEFAULTS.merge(hash))
end
new(opts = DEFAULTS) click to toggle source
# File lib/migration_signature/config.rb, line 22
def initialize(opts = DEFAULTS)
  @opts = opts
end

Public Instance Methods

all_runnable_files() click to toggle source
# File lib/migration_signature/config.rb, line 26
def all_runnable_files
  @all_runnable_files ||= begin
    require 'pathname'

    Dir["#{migration_dir}/*"].sort.reject do |f|
      ignore?(f)
    end
  end
end
ignore?(file) click to toggle source
# File lib/migration_signature/config.rb, line 40
def ignore?(file)
  rails_root_file =
    Pathname.new(file).relative_path_from(@opts['rails_dir']).to_s

  return true if string_ignores.include?(file)
  return true if string_ignores.include?(rails_root_file)
  return true if regexp_ignores.any? { |ignore| ignore =~ file }
  return true if regexp_ignores.any? { |ignore| ignore =~ rails_root_file }

  false
end
migration_dir() click to toggle source
# File lib/migration_signature/config.rb, line 36
def migration_dir
  "#{@opts['rails_dir']}/#{@opts['migration_dir']}"
end

Private Instance Methods

regexp_ignores() click to toggle source
# File lib/migration_signature/config.rb, line 54
def regexp_ignores
  @regexp_ignores ||= @opts['ignore'].find_all { |i| i.is_a?(Regexp) }
end
string_ignores() click to toggle source
# File lib/migration_signature/config.rb, line 58
def string_ignores
  @string_ignores ||= @opts['ignore'].reject { |i| i.is_a?(Regexp) }
end