Skip to content

Commit

Permalink
Merge pull request #29 from stitchfix/reduce-hashie-scope
Browse files Browse the repository at this point in the history
Return a hash with indifferent access rather than a Mash
  • Loading branch information
mboeh committed Jul 5, 2022
2 parents 7f640c2 + fb75af3 commit 822d391
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class NotFound < RuntimeError; end
class FileError < RuntimeError; end
class AlreadyLoaded < RuntimeError; end

class SettingHash < Hash
include Hashie::Extensions::IndifferentAccess
include Hashie::Extensions::KeyConversion
include Hashie::Extensions::DeepMerge
end

include Singleton
NUM_KLASS = if RUBY_VERSION.split(/\./)[0].to_i == 2 && RUBY_VERSION.split(/\./)[1].to_i >= 4
Integer
Expand Down Expand Up @@ -87,7 +93,7 @@ def self.available_settings
#=================================================================

def initialize
@available_settings ||= Hashie::Mash.new
@available_settings ||= SettingHash.new
end

def has_key?(key)
Expand All @@ -105,6 +111,9 @@ def value_for(key, args = [])
end

v = @available_settings[name]
if v.is_a?(Hash)
v = SettingHash[v]
end
if block_given?
v = yield(v, args)
end
Expand Down Expand Up @@ -151,7 +160,7 @@ def loaded?

def load(params)
# reset settings hash
@available_settings = Hashie::Mash.new
@available_settings = SettingHash.new
@loaded = false

files = []
Expand Down
1 change: 1 addition & 0 deletions spec/mc_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
expect(subject[:two][:three]).to eq(5)
expect(subject['two'][:three]).to eq(5)
expect(subject[:two]['three']).to eq(5)
expect(subject[:two].symbolize_keys[:three]).to eq(5)
end

context "working with arrays" do
Expand Down

0 comments on commit 822d391

Please sign in to comment.