Class: TaskSupport
Class Method Summary collapse
- .config_export(path = "#{Rails.root}/config/radiant_config.yml") ⇒ Object
- .config_import(path = "#{Rails.root}/config/radiant_config.yml", clear = nil) ⇒ Object
- .establish_connection ⇒ Object
Class Method Details
.config_export(path = "#{Rails.root}/config/radiant_config.yml") ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/task_support.rb', line 10 def config_export(path = "#{Rails.root}/config/radiant_config.yml") self.establish_connection FileUtils.mkdir_p(File.dirname(path)) if File.open(File.(path), 'w') { |f| YAML.dump(Radiant::Config.to_hash.to_yaml,f) } puts "Radiant::Config saved to #{path}" end end |
.config_import(path = "#{Rails.root}/config/radiant_config.yml", clear = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/task_support.rb', line 17 def config_import(path = "#{Rails.root}/config/radiant_config.yml", clear = nil) self.establish_connection Radiant::Config.delete_all if clear if File.exist?(path) configs = YAML.load(YAML.load_file(path)) configs.each do |key, value| c = Radiant::Config.find_or_initialize_by_key(key) c.value = value c.save end puts "Radiant::Config updated from #{path}" else puts "No file exists at #{path}" end end |
.establish_connection ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/task_support.rb', line 3 def establish_connection unless ActiveRecord::Base.connected? connection_hash = YAML.load_file("#{Rails.root}/config/database.yml").to_hash env_connection = connection_hash[RAILS_ENV] ActiveRecord::Base.establish_connection(env_connection) end end |