class MonkeyButler::Util

Public Class Methods

camelize(term, uppercase_first_letter = true) click to toggle source
# File lib/monkey_butler/util.rb, line 32
def camelize(term, uppercase_first_letter = true)
  string = term.to_s
  string = string.sub(/^[a-z\d]*/) { $&.capitalize }
  string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
  string.gsub!('/', '::')
  string
end
database_named(name) click to toggle source
# File lib/monkey_butler/util.rb, line 40
def database_named(name)
  raise ArgumentError, "Database name cannot be nil." if name.nil?
  require "monkey_butler/databases/#{name}_database"
  klass_name = "MonkeyButler::Databases::#{Util.camelize(name)}Database"
  Object.const_get(klass_name)
end
migration_named(name, timestamp = migration_timestamp) click to toggle source
# File lib/monkey_butler/util.rb, line 8
def migration_named(name, timestamp = migration_timestamp)
  migration_name = [timestamp, Thor::Util.snake_case(name)].join('_')
end
migration_timestamp() click to toggle source
# File lib/monkey_butler/util.rb, line 4
def migration_timestamp
  Time.now.strftime('%Y%m%d%H%M%S%3N').to_i
end
migration_version_from_path(path) click to toggle source
# File lib/monkey_butler/util.rb, line 16
def migration_version_from_path(path)
  path.match(/(\d{17})_/)[1].to_i
end
migration_versions_from_paths(paths) click to toggle source
# File lib/monkey_butler/util.rb, line 20
def migration_versions_from_paths(paths)
  paths.map { |path| migration_version_from_path(path) }
end
migrations_by_version(paths) click to toggle source
# File lib/monkey_butler/util.rb, line 24
def migrations_by_version(paths)
  paths.inject({}) do |hash, path|
    version = migration_version_from_path(path)
    hash[version] = path
    hash
  end
end
strip_leading_whitespace(string) click to toggle source
# File lib/monkey_butler/util.rb, line 12
def strip_leading_whitespace(string)
  string.gsub(/^\s+/, '')
end
target_classes_named(*names) { |klass| ... } click to toggle source
# File lib/monkey_butler/util.rb, line 47
def target_classes_named(*names)
  raise ArgumentError, "Database name cannot be nil." if names.nil?
  names.flatten.map do |name|
    require "monkey_butler/targets/#{name}/#{name}_target"
    klass_name = "MonkeyButler::Targets::#{Util.camelize(name)}Target"
    Object.const_get(klass_name).tap do |klass|
      yield klass if block_given?
    end
  end
end
unique_tag_for_version(version) click to toggle source
# File lib/monkey_butler/util.rb, line 58
def unique_tag_for_version(version)
  revision = nil
  tag = nil
  begin
    tag = [version, revision].compact.join('.')
    existing_tag = `git tag -l #{tag}`
    break if existing_tag == ""
    revision = revision.to_i + 1
  end while true
  tag
end