Skip to content

Commit c39fa48

Browse files
author
Kevin Paulisse
committed
In FactOverride object, key -> fact_name
1 parent 5b876f7 commit c39fa48

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

lib/octocatalog-diff/api/v1/fact_override.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ module V1
88
# Sets up the override of a fact during catalog compilation.
99
class FactOverride
1010
# Accessors
11-
attr_reader :key, :value
11+
attr_reader :fact_name, :value
1212

1313
# Constructor: Accepts a key and value.
14-
# @param input [Hash] Must contain :key and :value
14+
# @param input [Hash] Must contain :fact_name and :value
1515
def initialize(input)
16-
@key = input.fetch(:key)
16+
@fact_name = input.fetch(:fact_name)
1717
@value = input.fetch(:value)
1818
end
19+
20+
# Retrieve the fact_name as #key (essentially an alias)
21+
# @return [String] Value of @fact_name
22+
def key
23+
@fact_name
24+
end
1925
end
2026
end
2127
end

lib/octocatalog-diff/cli/fact_override.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def self.fact_override(input, key = nil)
2727
end
2828
key, raw_value = input.strip.split('=', 2)
2929
value = parsed_value(raw_value)
30-
OctocatalogDiff::API::V1::FactOverride.new(key: key, value: value)
30+
OctocatalogDiff::API::V1::FactOverride.new(fact_name: key, value: value)
3131
elsif key.nil?
3232
message = "Define a key when the input is not a string (#{input.class} => #{input.inspect})"
3333
raise ArgumentError, message
3434
else
35-
OctocatalogDiff::API::V1::FactOverride.new(key: key, value: input)
35+
OctocatalogDiff::API::V1::FactOverride.new(fact_name: key, value: input)
3636
end
3737
end
3838

spec/octocatalog-diff/tests/api/v1/fact_override_spec.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,32 @@
66

77
describe OctocatalogDiff::API::V1::FactOverride do
88
describe '#new' do
9-
it 'should raise error if key is not supplied' do
10-
expect { described_class.new(value: 'bar') }.to raise_error(KeyError, /key/)
9+
it 'should raise error if fact_name is not supplied' do
10+
expect { described_class.new(value: 'bar') }.to raise_error(KeyError, /fact_name/)
1111
end
1212

1313
it 'should raise error if value is not supplied' do
14-
expect { described_class.new(key: 'bar') }.to raise_error(KeyError, /value/)
14+
expect { described_class.new(fact_name: 'bar') }.to raise_error(KeyError, /value/)
15+
end
16+
end
17+
18+
describe '#fact_name' do
19+
it 'should return fact_name' do
20+
testobj = described_class.new(fact_name: 'foo', value: 'bar')
21+
expect(testobj.fact_name).to eq('foo')
1522
end
1623
end
1724

1825
describe '#key' do
19-
it 'should return key' do
20-
testobj = described_class.new(key: 'foo', value: 'bar')
26+
it 'should return fact_name' do
27+
testobj = described_class.new(fact_name: 'foo', value: 'bar')
2128
expect(testobj.key).to eq('foo')
2229
end
2330
end
2431

2532
describe '#value' do
2633
it 'should return value' do
27-
testobj = described_class.new(key: 'foo', value: 'bar')
34+
testobj = described_class.new(fact_name: 'foo', value: 'bar')
2835
expect(testobj.value).to eq('bar')
2936
end
3037
end

0 commit comments

Comments
 (0)