Skip to content

Commit

Permalink
use RACK_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
hahmed committed May 31, 2019
1 parent 91b9142 commit 6edbbe0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
14 changes: 3 additions & 11 deletions lib/gel/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Gel::Config
def initialize
@root = File.expand_path("~/.config/gel")
@root = ENV.fetch('GEL_CONFIG') { File.expand_path("~/.config/gel") }
@path = File.join(@root, "config")
@config = nil
end
Expand All @@ -15,14 +15,6 @@ def all
config
end

def config_exists?
File.exist?(@path)
end

def config_file
File.read(@path)
end

def [](group = nil, key)
if group.nil?
group, key = key.split(".", 2)
Expand All @@ -45,9 +37,9 @@ def []=(group = nil, key, value)

def read
result = {}
if config_exists?
if File.exist?(@path)
context = nil
config_file.each_line do |line|
File.read(@path).each_line do |line|
line.chomp!
if line =~ /\A(\S[^:]*):\z/
context = result[$1] = {}
Expand Down
30 changes: 8 additions & 22 deletions test/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,20 @@

class ConfigTest < Minitest::Test
def test_reading_single_item_from_config_successully
config = Class.new(Gel::Config) do
define_method(:config_file) do
File.open(fixture_file("config")).read
end

define_method(:config_exists?) do
true
end
end

klass = config.new
prev_gel_config = ENV['GEL_CONFIG']
ENV['GEL_CONFIG'] = fixture_file('')
klass = Gel::Config.new
assert_equal '1', klass['jobs']
assert_equal 'true', klass['gem.mit']
ENV['GEL_CONFIG'] = prev_gel_config
end

def test_reading_all_from_config_successully
config = Class.new(Gel::Config) do
define_method(:config_file) do
File.open(fixture_file("config")).read
end

define_method(:config_exists?) do
true
end
end

output = config.new.all
prev_gel_config = ENV['GEL_CONFIG']
ENV['GEL_CONFIG'] = fixture_file('')
output = Gel::Config.new.all
assert output['jobs'] == { '' => '1' }
assert output['gem'] == { 'mit' => 'true' }
ENV['GEL_CONFIG'] = prev_gel_config
end
end

0 comments on commit 6edbbe0

Please sign in to comment.