Skip to content

Commit

Permalink
Address edge case with table config param (rubyconfig#339) by @krasno…
Browse files Browse the repository at this point in the history
  • Loading branch information
danilogco committed Oct 13, 2023
1 parent 2e0f2a0 commit 7087b7d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/confset/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def merge!(hash)
end

# Some keywords that don't play nicely with OpenStruct
SETTINGS_RESERVED_NAMES = %w[select collect test count zip min max exit!].freeze
SETTINGS_RESERVED_NAMES = %w[select collect test count zip min max exit! table].freeze

# An alternative mechanism for property access.
# This let's you do foo['bar'] along with foo.bar.
Expand All @@ -134,11 +134,11 @@ def []=(param, value)
end

def key?(key)
table.key?(key)
@table.key?(key)
end

def has_key?(key)
table.has_key?(key)
@table.has_key?(key)
end

def method_missing(method_name, *args)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/reserved_keywords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ zip: cherry
max: kumquat
min: fig
exit!: taro
table: strawberry
22 changes: 22 additions & 0 deletions spec/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
expect(config.max).to eq("kumquat")
expect(config.min).to eq("fig")
expect(config.exit!).to eq("taro")
expect(config.table).to eq("strawberry")
end

it "should allow to access them using [] operator" do
Expand All @@ -30,6 +31,7 @@
expect(config["max"]).to eq("kumquat")
expect(config["min"]).to eq("fig")
expect(config["exit!"]).to eq("taro")
expect(config["table"]).to eq("strawberry")

expect(config[:select]).to eq("apple")
expect(config[:collect]).to eq("banana")
Expand All @@ -38,6 +40,26 @@
expect(config[:max]).to eq("kumquat")
expect(config[:min]).to eq("fig")
expect(config[:exit!]).to eq("taro")
expect(config[:table]).to eq("strawberry")
end
end

context "when empty" do
let(:config) do
Confset.load_files("#{fixture_path}/empty1.yml")
end

it "should allow to access them via object member notation" do
expect(config.select).to be_nil
expect(config.table).to be_nil
end

it "should allow to access them using [] operator" do
expect(config["select"]).to be_nil
expect(config["table"]).to be_nil

expect(config[:select]).to be_nil
expect(config[:table]).to be_nil
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
RSpec.configure do |config|
# Turn the deprecation warnings into errors, giving you the full backtrace
config.raise_errors_for_deprecations!
config.include FixtureHelper

config.before(:suite) do
Confset.module_eval do
Expand Down

0 comments on commit 7087b7d

Please sign in to comment.