Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ruby/lib/centroid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def [](key)

if value.is_a?(Hash)
Config.new(value)
elsif value.is_a?(Array)
value.map { |e| e.is_a?(Hash) ? Config.new(e) : e }
else
value
end
Expand Down
20 changes: 20 additions & 0 deletions ruby/test/centroid_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def json_config
'{"theEnvironment":{"theKey":"TheValue"}}'
end

def json_config_with_array
'{"theArray":[{"theKey": "Value1"},{"theKey": "Value2"}]}'
end

def shared_file_path
'config.json'
end
Expand Down Expand Up @@ -114,6 +118,22 @@ def test_respond_to
assert(!config.respond_to?(:does_not_exist))
end

def test_indexing_json_array
config = Centroid::Config.new(json_config_with_array)
assert_equal(config.the_array[0].the_key, "Value1")
assert_equal(config.the_array[1].the_key, "Value2")
end

def test_enumerating_json_array
config = Centroid::Config.new(json_config_with_array)
itemCount = 0
config.the_array.each do |item|
assert_equal(item.the_key, config.the_array[itemCount].the_key)
itemCount += 1
end
assert_equal(itemCount, 2)
end

def test_enumerating_json_object
config = Centroid::Config.new(json_config)
itemCount = 0
Expand Down