Skip to content

Commit

Permalink
Replace all characters that cannot be used as method or class name
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed May 30, 2018
1 parent 6e8eef4 commit 6993b25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/ansible_tower_client/hash_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def modelized_list
end

def convert_value(key, value, parent)
method = key_to_attribute(key)
method = key_to_attribute(key).gsub(/\W/, '_') # replace all unqualified characters for method and class names

new_val =
if attr_excluded?(method)
value
Expand Down
4 changes: 3 additions & 1 deletion spec/base_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"name" => "jeff",
"address" => { "street" => "22 charlotte rd"},
"serialized_json" => { "key" => "value"}.to_json,
"serialized_yaml" => { "key" => "value"}.to_yaml
"serialized_yaml" => { "key" => "value"}.to_yaml,
":Special$ Key3" => { "key" => "value"}
}
end

Expand All @@ -17,6 +18,7 @@
expect(instance.name).to eq("jeff")
expect(instance.address).to be_kind_of(described_class)
expect(instance.address.street).to eq("22 charlotte rd")
expect(instance._special__key3).to be_kind_of(AnsibleTowerClient::BaseModel::SpecialKey3)
end
end

Expand Down

0 comments on commit 6993b25

Please sign in to comment.