Skip to content

Commit

Permalink
fix reserved name error
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Sep 18, 2023
1 parent c98ac2e commit a9a9cce
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
dachsfisch (0.1.0)
dachsfisch (0.1.1)
nokogiri (>= 1.14.1, < 2.0.0)

GEM
Expand Down
3 changes: 2 additions & 1 deletion lib/dachsfisch/json2_xml_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def add_element(xml, element)
def add_node(xml, key, element)
case element
when Hash
node = xml.send(key) { add_element(xml, element) }
# underscore is used to disambiguate tag names from ruby methods
node = xml.send("#{key}_") { add_element(xml, element) }
handle_attribute_and_namespaces(node, element)
when Array
element.each do |sub_element|
Expand Down
2 changes: 1 addition & 1 deletion lib/dachsfisch/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Dachsfisch
VERSION = '0.1.0'
VERSION = '0.1.1'
end
18 changes: 18 additions & 0 deletions spec/support/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ def self.xml
end
end

class CustomExampleWithReservedWord < ExampleBase
def self.json
<<~JSON
{
"test": {
"$1": "test"
}
}
JSON
end

def self.xml
<<-XML
<test>test</test>
XML
end
end

class Example3 < ExampleBase
def self.json
<<~JSON
Expand Down

0 comments on commit a9a9cce

Please sign in to comment.