Class: OpalORM::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/opal_orm/util.rb

Class Method Summary collapse

Class Method Details

.config_pathObject



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_pathObject



9
10
11
# File 'lib/opal_orm/util.rb', line 9

def self.current_path
  Dir.pwd
end

.db_pathObject



13
14
15
# File 'lib/opal_orm/util.rb', line 13

def self.db_path
  File.join(self.current_path, 'db')
end

.ensure_db_dirObject



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_configObject



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_pathObject



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_configObject



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