Module: HeartSeed::Helper
- Defined in:
- lib/heart_seed/helper.rb
Constant Summary collapse
- CONFIG_FILE =
"config/heart_seed.yml"
Class Method Summary collapse
-
.catalog_tables(catalog_name) ⇒ Array<String>
Table names in a specify catalog.
-
.catalogs ⇒ Hash{String => Array<String>}
Key: catalog name, value: table names.
-
.config ⇒ Hash{String => String}
read config/heart_seed.yml.
-
.environment(default = "development") ⇒ String
Rails.env, PADRINO_ENV, RACK_ENV or default.
- .production? ⇒ Boolean
-
.root_dir ⇒ Pathname
return Rails.root , Padrino.root or current dir.
- .root_dir=(dir) ⇒ Object
- .seed_dir ⇒ Pathname
- .xls_dir ⇒ Pathname
Class Method Details
.catalog_tables(catalog_name) ⇒ Array<String>
Returns 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 |
.catalogs ⇒ Hash{String => Array<String>}
Returns key: catalog name, value: table names.
51 52 53 |
# File 'lib/heart_seed/helper.rb', line 51 def self.catalogs config["catalogs"] || {} end |
.config ⇒ Hash{String => String}
read config/heart_seed.yml
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.
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
71 72 73 |
# File 'lib/heart_seed/helper.rb', line 71 def self.production? environment == "production" end |
.root_dir ⇒ Pathname
return Rails.root , Padrino.root or current dir
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
46 47 48 |
# File 'lib/heart_seed/helper.rb', line 46 def self.root_dir=(dir) @root_dir = Pathname.new(dir) end |
.seed_dir ⇒ 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_dir ⇒ 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 |