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
21 22 23 |
# File 'lib/rtt/storage.rb', line 21 def config(env = :production) @config ||= YAML::load_file(File.join(File.dirname(__FILE__), '..', '..', 'db', 'config.yml'))[env.to_s] end |
#database_file ⇒ Object
9 10 11 |
# File 'lib/rtt/storage.rb', line 9 def database_file File.(File.join(ENV['HOME'], '.rtt', config['database'])) end |
#export(filename) ⇒ Object
13 14 15 |
# File 'lib/rtt/storage.rb', line 13 def export filename FileUtils.cp(database_file, filename) end |
#import(filename) ⇒ Object
17 18 19 |
# File 'lib/rtt/storage.rb', line 17 def import filename FileUtils.cp(filename, database_file) end |
#init(env = :production) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rtt/storage.rb', line 25 def init(env = :production) database_dir = File.dirname(database_file) FileUtils.mkdir_p(database_dir) unless FileTest::directory?(database_dir) ActiveRecord::Base.establish_connection(config(env).merge('database' => database_file)) 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
37 38 39 |
# File 'lib/rtt/storage.rb', line 37 def tables_exists? %w(projects clients tasks users).any? { |t| ActiveRecord::Base.connection.tables.include?(t) } end |