Class: OpalORM::Util
- Inherits:
-
Object
- Object
- OpalORM::Util
- Defined in:
- lib/opal_orm/util.rb
Class Method Summary collapse
- .config_path ⇒ Object
- .current_path ⇒ Object
- .db_path ⇒ Object
- .ensure_db_dir ⇒ Object
- .get_config ⇒ Object
- .get_database_path ⇒ Object
- .make_config ⇒ Object
- .save_config(new_config) ⇒ Object
Class Method Details
.config_path ⇒ Object
17 18 19 |
# File 'lib/opal_orm/util.rb', line 17 def self.config_path File.join(self.db_path, 'opal_config.json') end |
.current_path ⇒ Object
9 10 11 |
# File 'lib/opal_orm/util.rb', line 9 def self.current_path Dir.pwd end |
.db_path ⇒ Object
13 14 15 |
# File 'lib/opal_orm/util.rb', line 13 def self.db_path File.join(self.current_path, 'db') end |
.ensure_db_dir ⇒ Object
3 4 5 6 7 |
# File 'lib/opal_orm/util.rb', line 3 def self.ensure_db_dir unless Dir.exist?(self.db_path) Dir.mkdir('db') end end |
.get_config ⇒ Object
21 22 23 24 25 |
# File 'lib/opal_orm/util.rb', line 21 def self.get_config if File.exists?(Util.config_path) JSON.parse(File.read(Util.config_path))|| {} end end |
.get_database_path ⇒ Object
27 28 29 30 31 32 |
# File 'lib/opal_orm/util.rb', line 27 def self.get_database_path db_name = get_config["db_name"] if db_name File.join(db_path, db_name) end end |
.make_config ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/opal_orm/util.rb', line 34 def self.make_config Util.ensure_db_dir unless File.exists?(Util.config_path) File.new(Util.config_path, 'w') end end |
.save_config(new_config) ⇒ Object
42 43 44 45 46 |
# File 'lib/opal_orm/util.rb', line 42 def self.save_config(new_config) File.open(Util.config_path, "w+") do |f| f.write(new_config.to_json) end end |