module HeartSeed::Helper

Constants

CONFIG_FILE

Public Class Methods

catalog_tables(catalog_name) click to toggle source

@param catalog_name [String] @return [Array<String>] table names in a specify catalog

# File lib/heart_seed/helper.rb, line 57
def self.catalog_tables(catalog_name)
  self.catalogs[catalog_name] || []
end
catalogs() click to toggle source

@return [Hash{String => Array<String>}] key: catalog name, value: table names

# File lib/heart_seed/helper.rb, line 51
def self.catalogs
  config["catalogs"] || {}
end
config() click to toggle source

read config/heart_seed.yml @return [Hash{String => String}]

# File lib/heart_seed/helper.rb, line 7
def self.config
  if File.exist?(CONFIG_FILE)
    YAML.load_file(CONFIG_FILE)
  else
    {
        "seed_dir" => "db/seeds",
        "xls_dir"  => "db/xls",
        "catalogs" => {},
    }
  end
end
environment(default = "development") click to toggle source

@param default [String] @return [String] {Rails.env}, PADRINO_ENV, RACK_ENV or default

# File lib/heart_seed/helper.rb, line 63
def self.environment(default = "development")
  env ||= Rails.env          if defined? Rails
  env ||= ENV["PADRINO_ENV"] if ENV["PADRINO_ENV"]
  env ||= ENV["RACK_ENV"]    if ENV["RACK_ENV"]
  env ||= default
  env
end
production?() click to toggle source
# File lib/heart_seed/helper.rb, line 71
def self.production?
  environment == "production"
end
root_dir() click to toggle source

return {Rails.root} , {Padrino.root} or current dir @return [Pathname]

# File lib/heart_seed/helper.rb, line 33
def self.root_dir
  return @root_dir if @root_dir

  if defined? Rails
    Rails.root
  elsif defined? Padrino
    Pathname.new(Padrino.root)
  else
    Pathname.pwd
  end
end
root_dir=(dir) click to toggle source

@param dir [String]

# File lib/heart_seed/helper.rb, line 46
def self.root_dir=(dir)
  @root_dir = Pathname.new(dir)
end
seed_dir() click to toggle source

@return [Pathname]

# File lib/heart_seed/helper.rb, line 20
def self.seed_dir
  dir = config["seed_dir"] || "db/seeds"
  root_dir.join(dir)
end
xls_dir() click to toggle source

@return [Pathname]

# File lib/heart_seed/helper.rb, line 26
def self.xls_dir
  dir = config["xls_dir"] || "db/xls"
  root_dir.join(dir)
end