Module: Rtt::Storage
- Included in:
- Rtt
- Defined in:
- lib/rtt/storage.rb
Instance Method Summary collapse
- #config(env = :production) ⇒ Object
- #database_file ⇒ Object
- #export(filename) ⇒ Object
- #import(filename) ⇒ Object
- #init(env = :production) ⇒ Object
- #tables_exists? ⇒ Boolean
Instance Method Details
#config(env = :production) ⇒ Object
22 23 24 |
# File 'lib/rtt/storage.rb', line 22 def config(env = :production) @config ||= YAML::load_file(File.join(File.dirname(__FILE__), '..', '..', 'db', 'config.yml'))[env.to_s] end |
#database_file ⇒ Object
8 9 10 |
# File 'lib/rtt/storage.rb', line 8 def database_file File.(File.join(File.dirname(__FILE__), '..', '..', config['database'])) end |
#export(filename) ⇒ Object
12 13 14 15 |
# File 'lib/rtt/storage.rb', line 12 def export filename require 'fileutils' FileUtils.cp(database_file, filename) end |
#import(filename) ⇒ Object
17 18 19 20 |
# File 'lib/rtt/storage.rb', line 17 def import filename require 'fileutils' FileUtils.cp(filename, database_file) end |
#init(env = :production) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/rtt/storage.rb', line 26 def init(env = :production) ActiveRecord::Base.establish_connection(config(env)) log_dir = File.(File.join(File.dirname(__FILE__), '..', '..', 'log')) Dir::mkdir(log_dir) unless FileTest::directory?(log_dir) ActiveRecord::Base.logger = Logger.new(File.open(File.(File.join(File.dirname(__FILE__), '..', '..', 'log', 'database.log')), 'a')) silence_stream(STDOUT) do require File.(File.join(File.dirname(__FILE__), '..', '..', 'db', 'schema.rb')) unless tables_exists? end end |
#tables_exists? ⇒ Boolean
36 37 38 |
# File 'lib/rtt/storage.rb', line 36 def tables_exists? %w(projects clients tasks users).any? { |t| ActiveRecord::Base.connection.tables.include?(t) } end |