Skip to content

Commit

Permalink
chore: backward compatibility and hash hash attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalahutdinov committed Dec 19, 2017
1 parent edabf10 commit 0ac51ab
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/anyway/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def config_name(val = nil)
# my_config = Anyway::Config.for(:my_app)
# # will load data from config/my_app.yml, secrets.my_app, ENV["MY_APP_*"]
def for(name)
new(name, false).load_from_sources
new(name: name, load: false).load_from_sources
end
end

Expand All @@ -56,11 +56,19 @@ def for(name)
#
# my_config = Anyway::Config.new(:my_app, true, {overrides: {some: :value}})
#
def initialize(config_name = nil, do_load = true, overrides: {})
@config_name = config_name || self.class.config_name
# rubocop:disable Metrics/LineLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
def initialize(config_name = nil, do_load = true, name: nil, load: true, overrides: {})
unless config_name.nil? && do_load.nil?
warn "[Deprecated] Positional arguments for Anyway::Config#initialize will be removed in 1.2.0. Use keyword arguments instead: initialize(name:, load:, overrides:)"
end
name = config_name unless config_name.nil?
load = do_load unless do_load.nil?

@config_name = name || self.class.config_name
raise ArgumentError, "Config name is missing" unless @config_name
load(overrides) if do_load
self.load(overrides) if load
end
# rubocop:enable Metrics/LineLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity

def reload(overrides = {})
clear
Expand Down

0 comments on commit 0ac51ab

Please sign in to comment.