Skip to content

Commit 286d218

Browse files
author
Kevin Paulisse
committed
Add documentation and test for #to_h
1 parent 19be23b commit 286d218

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

doc/dev/api/v1/objects/diff.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,12 @@ For example, a diff involving `File['/etc/passwd']` would have:
241241
- `diff.type #=> 'File`
242242

243243
Note that the type will be capitalized because Puppet capitalizes this in catalogs.
244+
245+
## Other methods
246+
247+
These methods are available for debugging or development purposes but are not guaranteed to remain consistent between versions:
248+
249+
- `#inspect` (String): Returns inspection of object
250+
- `#raw` (Array): Returns internal array data structure of the "diff"
251+
- `#to_h` (Hash): Returns object as a hash, where keys are above described methods
252+
- `#[]` (Object): Retrieve indexed array elements from raw internal array object

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def new_line
124124
def to_h
125125
{
126126
change_type: change_type,
127-
change_type_word: change_type_word,
128127
type: type,
129128
title: title,
130129
structure: structure,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,17 @@
272272
expect(testobj.new_line).to be_nil
273273
end
274274
end
275+
276+
describe '#to_h' do
277+
it 'should return a hash with the expected keys and values' do
278+
methods = %w(change_type type title structure old_value new_value old_line new_line old_file new_file)
279+
testobj = described_class.new(chg_2)
280+
result = testobj.to_h
281+
methods.each do |method_name|
282+
method = method_name.to_sym
283+
expect(result.key?(method)).to eq(true)
284+
expect(result[method]).to eq(testobj.send(method))
285+
end
286+
end
287+
end
275288
end

0 commit comments

Comments
 (0)