Module: HeartSeed::Helper

Defined in:
lib/heart_seed/helper.rb

Constant Summary collapse

CONFIG_FILE =
"config/heart_seed.yml"

Class Method Summary collapse

Class Method Details

.catalog_tables(catalog_name) ⇒ Array<String>

Returns table names in a specify catalog.

Parameters:

  • catalog_name (String)

Returns:

  • (Array<String>)

    table names in a specify catalog



57
58
59
# File 'lib/heart_seed/helper.rb', line 57

def self.catalog_tables(catalog_name)
  self.catalogs[catalog_name] || []
end

.catalogsHash{String => Array<String>}

Returns key: catalog name, value: table names.

Returns:

  • (Hash{String => Array<String>})

    key: catalog name, value: table names



51
52
53
# File 'lib/heart_seed/helper.rb', line 51

def self.catalogs
  config["catalogs"] || {}
end

.configHash{String => String}

read config/heart_seed.yml

Returns:

  • (Hash{String => String})


7
8
9
10
11
12
13
14
15
16
17
# 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") ⇒ String

Returns Rails.env, PADRINO_ENV, RACK_ENV or default.

Parameters:

  • default (String) (defaults to: "development")

Returns:

  • (String)

    Rails.env, PADRINO_ENV, RACK_ENV or default



63
64
65
66
67
68
69
# 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?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/heart_seed/helper.rb', line 71

def self.production?
  environment == "production"
end

.root_dirPathname

return Rails.root , Padrino.root or current dir

Returns:

  • (Pathname)


33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object

Parameters:

  • dir (String)


46
47
48
# File 'lib/heart_seed/helper.rb', line 46

def self.root_dir=(dir)
  @root_dir = Pathname.new(dir)
end

.seed_dirPathname

Returns:

  • (Pathname)


20
21
22
23
# File 'lib/heart_seed/helper.rb', line 20

def self.seed_dir
  dir = config["seed_dir"] || "db/seeds"
  root_dir.join(dir)
end

.xls_dirPathname

Returns:

  • (Pathname)


26
27
28
29
# File 'lib/heart_seed/helper.rb', line 26

def self.xls_dir
  dir = config["xls_dir"] || "db/xls"
  root_dir.join(dir)
end