Giter VIP home page Giter VIP logo

gyoku's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gyoku's Issues

Rexml is required but is not in the Gemfile

Since this gem hasn't been released in a while the only possible way to use the pretty printing is to do this:

Gemfile:

source 'https://rubygems.org'

gem 'gyoku', git: 'https://github.com/savonrb/gyoku'

script.rb:

require 'bundler/setup'
require 'gyoku'

xml = Gyoku.xml({ document: "xy" }, { pretty_print: true })

This fails however since rexml is used for pretty printing, so the Gemfile must look like this to make the pretty printing work:

source 'https://rubygems.org'

gem 'gyoku', git: 'https://github.com/savonrb/gyoku'
gem 'rexml'

rexml should be included in the Gemfile of gyoku. It should not be necessary for the user of the library to include it in his/her Gemfile.

Gyoku.xml with unwrap: true doesn't set attributes

For example:

Gyoku.xml({items: {:content! => [item: "abc"], :@amount => "1"}}, unwrap: true)
# => "<items><item>abc</item></items>"

But I'm expecting:

Gyoku.xml({items: {:content! => [item: "abc"], :@amount => "1"}}, unwrap: true)
# => "<items amount=\"1\"><item>abc</item></items>"

Circular Require detected by JRuby-9+

Line /lib/gyoku/array.rb:3 require "gyoku/hash"

establishes a circular require pattern. Commenting that line out seems to resolve the issue. The following is the full exception listing from JRuby-9.1.14.0

/Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247: warning: loading in progress, circular require considered harmful - /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku/hash.rb require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku/array.rb:3 require at org/jruby/RubyKernel.java:955 block in (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 require at org/jruby/RubyKernel.java:955 block in (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku/hash.rb:3 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku.rb:2 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 require at org/jruby/RubyKernel.java:955 block in load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/akami-1.3.1/lib/akami/wsse.rb:7 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/akami-1.3.1/lib/akami.rb:2 require at org/jruby/RubyKernel.java:955 block in (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 require at org/jruby/RubyKernel.java:955 block in (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon/header.rb:1 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon/builder.rb:1 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 require at org/jruby/RubyKernel.java:955 block in load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon/operation.rb:4 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 each at org/jruby/RubyArray.java:1734 block in load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 each at org/jruby/RubyArray.java:1734 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 (root) at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon/client.rb:1 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:1 require at org/jruby/RubyKernel.java:955 block in require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 tap at org/jruby/RubyKernel.java:1741 load_dependency at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:232 require at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:247 <main> at /Users/jscott/rDeveloper/BMIService/vendor/bundle/jruby/2.3.0/gems/savon-2.11.1/lib/savon.rb:27 require at org/jruby/RubyKernel.java:955 <main> at /Users/jscott/.rvm/gems/jruby-9.1.14.0@bmiservice/gems/bundler-1.16.0/lib/bundler/runtime.rb:1

Stop camelcase

Hi, congrats for the nice gem.
I need instead it do
How can I do this? thanks

 @teste = Gyoku.xml(
          :enviar_instrucao => {
            :instrucao_unica =>{
              :razao => 'Upgrade de Conta',
              :valores => {:valor => '100', :attributes! => { :valor => { :moeda => 'BRL' }}},
              :id_propio => 'TesteRails',
              :pagador => {
                :nome => 'Igor Cesar',
                :email => '[email protected]',
                :id_pagador =>'01',
                :endereco_cobranca => {
                  :logradouro => 'Rua do Teste',
                  :numero => '45',
                  :complemento => 'em frente ao PC',
                  :bairro => 'Palhaco Ze',
                  :cidade => 'Rio de Janeiro',
                  :estado => 'RJ',
                  :pais => 'Brasil',
                  :CEP => '20765171',
                  :telefone_fixo => '(21) 99527-2766'
                }
              }
            }
            }, :key_converter => :none)

Gyoku.xml() method is not idempotent

The xml method does not behave as I would expect as it modifies the hash that is passed into it. Moreover, it modifies elements within the hash as it proceeds. Consider the following code:

nil_content = { :content! => nil, :'@xs1:nil' => 1 }
bar = { request: { "attributes" => { "text" => nil_content, "date" => nil_content } }}
bar_xml = Gyoku.xml(bar)
puts bar_xml

This produces:

Note that the xs1:nil attribute is not set in the XML when it should be. This is because somehow Gyoku is modifying the content of the nil_content variable.

By changing the bar_xml assignment to use the Rails deep_dup() Hash method to:

bar_xml = Gyoku.xml(bar.deep_dup)
puts bar_xml

This produces:

I note that in the implementation it performs a dup on the hash that is called, but that is insufficient. It should perform (the equivalent) a deep_dup instead.

:order! keys are not converted

Unfortunately am stuck using 1.8.7

Savon settings:

convert_request_keys_to :camelelcase
element_form_default :qualified

but this is not applying to the :order! array, so I am getting an argument error:
Missing elements in :order! [:user_name, :email_count]

Upon further exploration the error is coming from

gyoku-1.0.0/lib/gyoku/hash.rb:76:in `order'
hashable = [:email_count, :user_name]
orderable = ['userName', 'emailCount']

Thanks

Gyoku generates blank attribute values if there are fewer attribute values than elements

If attributes! are not given for all elements, Gyoku generates the attribute with blank values.
This breaks web services which require that attribute to be unspecified or non-blank

For example:

hash = { :find_user => { :person => ["Lucy", "Anna", "Beth"], :attributes! => { :person => { :id => [1, 2] } } } }
Gyoku.xml(hash)

generates

<findUser><person id=\"1\">Lucy</person><person id=\"2\">Anna</person><person id=\"\">Beth</person></findUser>

The blank id for the last element is incorrect if web service does not require you to specify ids for new elements.
The generated xml should have been:

<findUser><person id=\"1\">Lucy</person><person id=\"2\">Anna</person><person>Beth</person></findUser>

without the id attribute.

CI: Repair code coverage tool

In GitHub Actions output, examples:

Coveralls encountered an exception:
NoMethodError
undefined method `coverage' for #<SimpleCov::SourceFile:0x00007f3142fd0cd0 @filename="/home/runner/work/gyoku/gyoku/lib/gyoku.rb", @coverage_data={"lines"=>[1, 1, nil, 1, nil, nil, 1, 4, nil, nil, nil, 1, 6, nil, nil, nil]}>

          properties[:coverage] = file.coverage
                                      ^^^^^^^^^
Did you mean?  coverage_data
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/coveralls-0.7.2/lib/coveralls/simplecov.rb:50:in `block in format'
/opt/hostedtoolcache/Ruby/3.1.1/x64/lib/ruby/3.1.0/forwardable.rb:238:in `each'
/opt/hostedtoolcache/Ruby/3.1.1/x64/lib/ruby/3.1.0/forwardable.rb:238:in `each'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/coveralls-0.7.2/lib/coveralls/simplecov.rb:40:in `format'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/result.rb:51:in `format!'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/configuration.rb:197:in `block in at_exit'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov.rb:189:in `run_exit_tasks!'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov.rb:179:in `at_exit_behavior'
/home/runner/work/gyoku/gyoku/vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/defaults.rb:30:in `block in <top (required)>'

v1.1.0

List of changes for the upcoming v1.1.0 release.

Custom :key_converter?

Any reason not to accept something callable or allow one to add a converter?

The problem I've found is that some schemas upcase certain words. For example:

Ruby:camelcaseWanted
:product_id ProductIdProductID
:iso_codeIsoCodeISOCode

Gyoku is not threadsafe

Sometimes when using gyoku through Savon we get an exception like so:

NoMethodError: undefined method `upcase' for nil:NilClass

vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:5:in `__singleton__' org/jruby/RubyString.java:3037:in `gsub' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:5:in `__singleton__' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:11:in `__singleton__' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:24:in `create'
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku.rb:8:in `xml_tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/message.rb:22:in `to_s'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:146:in `tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:146:in `tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:33:in `to_s'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/operation.rb:72:in `build_request'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/operation.rb:48:in `call'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/client.rb:38:in `call'

I'm not exactly sure why this happen, probably the result is not as gyoku expect it but a proper error would be nicer than a NoMethodError.

'DateTime' resolution in /lib/gyoku/xml_value.rb fails on Windows

I'm not sure why exactly this is happening, but Gyoku seems to be running fine out of the box on the [Ruby 1.8] Linux machine I was running on, but when I tried it on a [Ruby 1.9] Windows machine with a similar Gem setup, I'm getting an error with it resolving DateTime in /lib/gyoku/xml_value.rb:

https://gist.github.com/7b2c1ecb970019f66b9b

Which obviously is fixable just adding require 'Date'. I'm not much of a Rubyist, so I'm not sure that's the right solution (well, manually hacking a gem isn't, regardless). Any thoughts? Versions below:

c:\Test>ruby --version
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
c:\Test>gem list
...
gyoku (0.4.2)

attributes not preserved for arrays

This code:

xml = Gyoku.xml({
  'foo' => { '@foo' => 'foo' },
  'bar' => [ { '@bar' => 'bar', 'baz' => { } } ],
})

produces this xml:

<foo foo="foo">
</foo>
<bar>
    <baz>
    </baz>
</bar>

but should produce:

<foo foo="foo">
</foo>
<bar bar="bar">
    <baz>
    </baz>
</bar>

(the attributes are missing when the hash value is an array of hashes).

I looked at array.rb for how to fix this, but it's not obvious to me.

Strathmeyer mentioned this in #18 (comment), but I thought it was better to enter a separate issue for this rather than hijack an existing one.

Using @-nodes without the attributes-magic

It just so happens to be the case that I need to use XML-nodes starting with an @.

>> client.call(:get_member_detail, message: { "relationid" => 3_055_232})
=> Savon::SOAPFault: (s:Client) .Net SqlClient Data Provider : Procedure or Function 'GetMemberDetail' expects parameter '@relationid', which was not supplied.

Is there some sort of workaround for this? I now get an empty string after adding the @ to relationid.

>> Gyoku.xml(:@responseid => 1234)
=> ""

Maybe we can only add the attributes via :@attr when there's a valid node present?

encoding of special characters is not consistent across ruby versions

Consider the following ruby script:

require 'gyoku'
puts "Ruby Version: #{RUBY_VERSION}"
puts Gyoku.xml(:special_chars => %q{&"<>'})

When executed on Ruby 1.9.3, it produces this output:

Ruby Version: 1.9.3
<specialChars>&amp;&quot;&lt;&gt;'</specialChars>

When executed on Ruby 2.0.0, it produces this output:

Ruby Version: 2.0.0
<specialChars>&amp;&quot;&lt;&gt;&#39;</specialChars>

The apostrophe character is not encoded at all on Ruby 1.9.3, but on ruby 2.0 it is converted to &#39;. The reason appears to be because of this line. The behavior of the CGI.escapeHTML function seems to have changed from Ruby 1.9.3 to Ruby 2.0. Here is an example.

This script:

require 'cgi'
string = %q{<>&"'}
puts "Ruby Version: #{RUBY_VERSION}"
puts "Original: #{string}"
puts "Encoded: #{CGI.escapeHTML(string)}"

produces this output on Ruby 1.9.3:

Ruby Version: 1.9.3
Original: <>&"'
Encoded: &lt;&gt;&amp;&quot;'

but this output on Ruby 2.0:

Ruby Version: 2.1.1
Original: <>&"'
Encoded: &lt;&gt;&amp;&quot;&#39;

It seems like the output should not change depending on the ruby version. In addition, if an apostrophe is going to be encoded, it seems like it would be more correct to encode it as &apos; instead of &#39;. In fact, encoding it as &#39; is directly causing me a problem here. :)

rubinius-coverage needed as a development_dependency

Hi,
Without this gem in the gemspec

 /usr/share/gems/gems/bundler-1.3.5/lib/bundler/resolver.rb:296:in `resolve': Could not find gem 'rubinius-coverage (>= 0) ruby' in the gems available on this machine. (Bundler::GemNotFound)

@keys not working as documented

Doc says this:

Using "@" keys and ":content!"

Gyoku.xml(
"foo/" => {
:@bar => "1",
:@biz => "2",
:@baz => "3",
:content! => ""
})

=> "<foo baz="3" bar="1" biz="2"/>"

Actual output:

1.9.2-p318 :021 > Gyoku.xml(
1.9.2-p318 :022 > "foo/" => {
1.9.2-p318 :023 > :@bar => "1",
1.9.2-p318 :024 > :@biz => "2",
1.9.2-p318 :025 > :@baz => "3",
1.9.2-p318 :026 > :content! => ""
1.9.2-p318 :027?> })
=> "@BAR1/@bar@biz2/@biz@BAZ3/@baz" โ€จ

(gyoku (1.0.0, 0.4.6, 0.4.4))

This is rather frustrating as I am generating very large XML documents with a large attributes hash that need self closing tags for blank values. That is very inefficient with the attributes hash and the :content! syntax would be far superior if it worked as expected...

Circular Require Errors

I'm getting the following error whenever I try to run an application I'm building:

/Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36: warning: loading in progress, circular require considered harmful - /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/gyoku-0.4.4/lib/gyoku/hash.rb
    from add_card_tests.rb:2:in `<main>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/git/i2c_web_service/i2c_tests/test_helper.rb:4:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/git/i2c_web_service/lib/i2c/web_services/client.rb:1:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
    from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/savon-0.9.9/lib/savon.rb:3:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
    from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/savon-0.9.9/lib/savon/client.rb:2:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/akami-1.0.0/lib/akami.rb:2:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/akami-1.0.0/lib/akami/wsse.rb:4:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/gyoku-0.4.4/lib/gyoku.rb:2:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/gyoku-0.4.4/lib/gyoku/hash.rb:3:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/gems/ruby-1.9.3-p0@i2c_web_service/gems/gyoku-0.4.4/lib/gyoku/array.rb:3:in `<top (required)>'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mkoby/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

Just to be thorough here are my requires as they appear in the stacktrace:

add_card_tests.rb:
require 'test_helper.rb'

test_helper.rb:
require 'i2c/web_services/client'

i2c/web_services/client.rb:
require 'savon'

I have my own Client class but it's namespaced under I2C::WebServices::Client, so this shouldn't interfere with savon's own class client, and the errors would indicate that the circular dependency is deeper than savon and well into the gyoku gem.

Any help is greatly appreciated.

Surprising Array to XML conversion

I got an Hash with a nested Array of hashes:

>> Gyoku.xml(attributes: [ {key: 'foo', value: 'bar' } ])
=> "<attributes><key>foo</key><value>bar</value></attributes>"

The XML contains no indication that this was an array?

Accidently i tried:

>> Gyoku.xml(attributes: [ {key: 'foo', value: 'bar'}, {key: 'more', value: 'foo' } ] )
=> "<attributes><key>foo</key><value>bar</value></attributes><attributes><key>more</key><value>foo</value></attributes>"

I found that even more surprising... but it gave me a hint how to achieve the expected output:

>> Gyoku.xml(attributes: { item: [ {key: 'foo', value: 'bar'}, {key: 'more', value: 'foo' } ] })
=> "<attributes><item><key>foo</key><value>bar</value></item><item><key>more</key><value>foo</value></item></attributes>"

I can work with that but i do wonder - is this the intended behaviour when converting an array of hashes to XML?

Conflict between camelcase methods in Rails

The camelcase method defined in Rails allow to create camelcase and lower camelcase and is your definition of the method is conflicting with it when using like this camelcase(:lower) to have a lower camelcase.

to_xml of a Hash containing an Array of Hashes

Hi there,

When converting a hash containing an array of hashes, like this:

:some => [{ :new => "user" }, { :old => "gorilla" }]

I expected the following output:

<some>
    <new>user</new>
    <old>gorilla</old>
</some>

But, instead it produces this:

<some>
    <new>user</new>
</some>
<some>
    <old>gorilla</old>
</some>

It seems like the parent hash should be the root element and should not repeat since there is only one key (:some)

Thoughts?

Thanks,
Matt

Gyoku.xml produces wrong results with arrays of hashes

It produces:

h = {attrs: [{attr: 1}, {attr: 2}, {attr: 3}]}
=> {:attrs=>[{:attr=>1}, {:attr=>2}, {:attr=>3}]}
Gyoku.xml(h)
=> "<foo><bar>1</bar></foo><foo><bar>2</bar></foo><foo><bar>3</bar></foo>"

I think this behaviour is completely incorrect. I believe it should return: <foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>.
I haven't got time to look it yet, but It may be related to #40

Attribute parsing (XML -> Hash)

Hi,

In parsing XML to hash, Gyoku seems to ignore attributes when there's a content inside the tag :

<myTag myAttribute="attributeContent" />
<myTag myAttribute="otherAttributeContent">tagContent</myTag>

is parsed (by 0.4.4) as

{ :my_tag => [ { :@my_attribute=>"attributeContent" }, "tagContent" ] }

Is this really the correct behavior? Is there a way to force attribute parsing?

Thanks,
Gilles

Custom attributes for self-closing tags and nil values

Gyoku seems to swallow custom attributes provided via :attributes! Hashes for self-closing tags and nil values.

Gyoku.xml(
  :root => {
    "category/" => "",
    :attributes! => { :category  => { :id => 1 }  }
  }
)

# => "<root><category/></root>"

Generating array of self closing tags difficult (impossible?)

One of our partner interfaces loves to use a list of self closing elements with attributes in the requests. In savon 0.7 I was able to generate these using by setting the values to an array of nils with the appropriate attributes hash with array of attribute values. In Gyoku, I can use the / suffix notation to generate a single element, but when I try to generate an array (using empty hashes instead of nils to avoid the xsi nil), the generated elements are not self closing.

I am working around this by generating the XML fragments by hand and using the ! Suffix to avoid escaping the output.

Support for arrays nested in other array.

When I have need to use nested arrays in savon SOAP client, but this is case caused bug in my opinion.

irb(main):001:0> Gyoku::Array.to_xml([[{ value: "1" }]], "Map")
=> "<Map>[{:value=>\"1\"}]</Map>"

Nested array is treated with to_s method. IMO it could be treated as normal Array. I done some workaround in https://github.com/seban/gyoku/commit/e7706cfaea69bba655d30c49c1eabe6893bddc3d. After my fix it looks like:

2.0.0p247 :001 > Gyoku::Array.to_xml([[{ value: "1" }]], "Map")
 => "<Map><element><value>1</value></element></Map>"

If it is ok for you I can submit pull request.

pretty_print doesn't work as expected

Hi there.

I wanted to generate some XML, and I wanted it to look nice. Having to concatenate some identical tags I set unwrap: true (which works fine), but the result wasn't prettified.

pry(main)> Gyoku.xml({ a: :b, c: [{ d: :e }, { f: :g }] }, { unwrap: true })
=> "<a>b</a><c><d>e</d><f>g</f></c>"

pry(main)> Gyoku.xml({ a: :b, c: [{ d: :e }, { f: :g }] }, { unwrap: true, pretty_print: true  })
=> "<a>b</a><c><d>e</d><f>g</f></c>"

pry(main)> Gyoku.xml({ a: :b, c: [{ d: :e }, { f: :g }] }, { unwrap: true, pretty_print: true, compact: false })
=> "<a>b</a><c><d>e</d><f>g</f></c>"

I would have expected both of the last results to be something like this:

<a>b</a>
<c>
  <d>e</d>
  <f>g</f>
</c>

I'm currently running Gyoku v. 1.3.1

Thanks in advance

Distinct attributes for Array elements

How do i get ditinct attributes for Array elements

Gyoku.xml(:person => "Eve", :attributes! => { :person => { :id => 1 } })

results in:

<person id="1">Eve</person>

If i make person an Array, it gives the same attribute for each element

Gyoku.xml(:person => ["Adam","Eve"], :attributes! => { :person => { :id => 1 } })

results in:

<person id="1">Adam</person><person id="1">Eve</person>

How do i get distinct attrbiutes for Array elements like this:

<person id="1">Adam</person><person id="2">Eve</person>

Declaring attributes! as Array doesn't help either:

Gyoku.xml(:person => ["Adam","Eve"], :attributes! => { :person => [{ :id => 1 }, {:id => 2}] })

results in invalid xml like this:

<person {:id=>1}=\"\" {:id=>2}=\"\">Adam</person><person {:id=>1}=\"\" {:id=>2}=\"\">Eve</person>

strange behavior of unescape xml

When I try to generate custom XML which should be used like this:

resp = client.request 'save_waybill', :body => { :waybill! => '<a>Some XML</a>' }

it results in the following request:

<ins0:save_waybill><ins0:waybill>&lt;a&gt;Some tag&lt;/a&gt;</ins0:waybill></ins0:save_waybill>

when i use something different from waybill everything seems to work fine:

resp = client.request 'save_waybill', :body => { :waybil! => '<a>Some XML</a>' }
<ins0:save_waybill><wsdl:waybil><a>Some XML</a></wsdl:waybil></ins0:save_waybill>

The same applies, when i change the name of the method save_waybill to something not ending with waybill.

Unintended attribute behaviour with unescaped tags ?

If I write the following code:

Gyoku.xml(tag!: '<p>text<p>', attributes!: {tag: { prop: 1}})

the output is "<tag><p>text<p></tag>", note the property may be missing in the tag

But it works with:

Gyoku.xml(tag!: '<p>text<p>', attributes!: {tag!: { prop: 1}})

output: '<tag prop="1"><p>text<p></tag>'

I would like to ask if this is the intended behaviour before submitting a PR

Mapping of Date objects

Date objects are mapped like DateTime, e.g. results in strings like 2009-08-17T00:00:00+00:00

Shouldn't they be mapped to something like 2009-08-17 (without the time)? This breaks my app and ist not valid xsd:date as well.

This is in the context of Savon, of course.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.