Class: Keg::Core
- Inherits:
-
Object
- Object
- Keg::Core
- Defined in:
- lib/keg/core.rb
Instance Method Summary collapse
- #current ⇒ Object
- #current_path ⇒ Object
- #databases_path ⇒ Object
-
#initialize(root) ⇒ Core
constructor
A new instance of Core.
- #select(filename) ⇒ Object
- #select_all ⇒ Object
- #switch(name) ⇒ Object
Constructor Details
Instance Method Details
#current ⇒ Object
29 30 31 32 |
# File 'lib/keg/core.rb', line 29 def current @current = @configuration.load if @current.nil? @current end |
#current_path ⇒ Object
44 45 46 |
# File 'lib/keg/core.rb', line 44 def current_path File.join(databases_path, current) end |
#databases_path ⇒ Object
48 49 50 |
# File 'lib/keg/core.rb', line 48 def databases_path File.join(@root, '.keg', 'databases') end |
#select(filename) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/keg/core.rb', line 20 def select(filename) unless Dir.exists?(current_path) raise "Current database is unknown directory `#{current}`. Please set a exist database." end path = File.join(current_path, filename+'.toml') TOML.load_file(path) end |
#select_all ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/keg/core.rb', line 34 def select_all unless Dir.exists?(current_path) raise "Current database is unknown directory `#{current}`. Please set a exist database." end Dir.glob("#{current_path}/**/*.toml").map do |path| TOML.load_file(path) end end |
#switch(name) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/keg/core.rb', line 11 def switch(name) path = File.join(databases_path, name) if !Dir.exists?(path) || name.empty? raise "Error: No such directory `#{name}`. Please enter a exist database." end @configuration.save name end |