Skip to content

Commit

Permalink
Allow configuration values with no default (=nil)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Ignjatovic committed Jun 23, 2016
1 parent 5e94265 commit fe0902b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/tepee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class << self

protected

def add(name, default, env_var: "#{env_var_prefix}#{name}")
def add(name, default = nil, env_var: "#{env_var_prefix}#{name}")
value = ENV[String(env_var).upcase] || default
const_set(String(name).upcase, value)
define_singleton_method(name) { value }
Expand Down
2 changes: 1 addition & 1 deletion lib/tepee/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Tepee
# This module holds the Tepee version information.
module Version
STRING = '0.0.1'.freeze
STRING = '0.0.2'.freeze

module_function

Expand Down
2 changes: 2 additions & 0 deletions spec/lib/tepee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
S2_VALUE2_VALUE = 's2value2:' + SecureRandom.uuid

class DummyConf < Tepee
add :no_default_value
add :value123456789, 'value should be overriden, you should not see this'
add :value987654321, VALUE2_VALUE
section(:section1) do
Expand All @@ -35,6 +36,7 @@ class DummyConf < Tepee
end
end

it { expect(DummyConf.no_default_value).to be_nil }
# At root
it { expect(DummyConf.value123456789).to eq VALUE1_VALUE }
it { expect(DummyConf::VALUE123456789).to eq VALUE1_VALUE }
Expand Down

0 comments on commit fe0902b

Please sign in to comment.