Misc features #729

Merged
merged 2 commits into from Oct 5, 2012

Conversation

Projects
None yet
3 participants
Contributor

benlangfeld commented Jul 13, 2012

No description provided.

Owner

flavorjones commented Jul 13, 2012

Thanks, I'll take a look today.

lib/nokogiri/xml/node.rb
@@ -258,7 +259,12 @@ def [] name
###
# Set the attribute value for the attribute +name+ to +value+
def []= name, value
- set name.to_s, value
+ if value.nil?
+ remove_attribute name.to_s
@tenderlove

tenderlove Jul 13, 2012

Owner

If we wan't this to quack like a hash, shouldn't we implement delete rather than having a magic value mean delete? I'm not really excited about the idea of calling a setter that could possibly have the side effect of deleting something.

@benlangfeld

benlangfeld Jul 13, 2012

Contributor

The question is why you would ever want to render an XML node with an
attribute present but empty.

Regards,
Ben Langfeld

Em 13 Jul 2012, às 19:05, Aaron Patterson
reply@reply.github.com
escreveu:

@@ -258,7 +259,12 @@ def [] name
###
# Set the attribute value for the attribute +name+ to +value+
def []= name, value

  •    set name.to_s, value
    
  •    if value.nil?
    
  •      remove_attribute name.to_s
    

If we wan't this to quack like a hash, shouldn't we implement delete rather than having a magic value mean delete? I'm not really excited about the idea of calling a setter that could possibly have the side effect of deleting something.


Reply to this email directly or view it on GitHub:
https://github.com/sparklemotion/nokogiri/pull/729/files#r1160798

@tenderlove

tenderlove Jul 13, 2012

Owner

Your scheme definition could demand the presence of the attribute but not define a value. Sorry, I won't accept this feature without a stronger argument.

@benlangfeld

benlangfeld Jul 13, 2012

Contributor

Ok, I'll move this up into a decorator.

lib/nokogiri/xml/node.rb
+ if value.nil?
+ remove_attribute name.to_s
+ else
+ value = value.join if value.is_a?(Array)
@tenderlove

tenderlove Jul 13, 2012

Owner

Why? The developer using nokogiri should probably figure out why they're passing arrays and format them the way they want. I really don't like the idea of supporting "laissez-faire" API like this.

@benlangfeld

benlangfeld Jul 13, 2012

Contributor

Good question. This one snuck in from monkey-patches. Will rebase it out.

@flavorjones

flavorjones Jul 16, 2012

Owner

Worth nothing that "quack like a hash" is on the roadmap for 2.0 (see #666)

test/xml/test_node.rb
+ </root>
+ eoxml
+
+ tires = xml.xpath(:'//bike:tire', {'bike' => 'http://schwinn.com/'})
@tenderlove

tenderlove Jul 13, 2012

Owner

Do people actually write code like this? Since XPath isn't valid for a symbol literal in Ruby, people would actually have to do extra work for this to happen. Supporting "what if" use-cases like this makes me sad.

Contributor

benlangfeld commented Jul 17, 2012

Objectionable content removed. Any thoughts on the remainder?

Contributor

benlangfeld commented Sep 16, 2012

Can someone review this please?

Contributor

benlangfeld commented Oct 2, 2012

I'd really love to get some of this in.

Contributor

benlangfeld commented Oct 4, 2012

No breaking changes here. @flavorjones @jvshahid merge?

Owner

flavorjones commented Oct 5, 2012

I don't think the symbol-to-string conversion is useful. There's also a test around non-string attribute values, which doesn't have any corresponding code changes. Can you tell me a little more about that?

In the future, pull requests should not contain reversions, and should not contain multiple features. Following this convention will make it easier to communicate about the pull request and will speed up merging if the PR is accepted.

Contributor

benlangfeld commented Oct 5, 2012

Option 1:

foo.xpath 'ns:bar', 'ns' => 'baz'

Option 2:

foo.xpath 'ns:bar', ns: 'baz'

The latter is better in my view and is what I want my code to look like. You might not like it, but it doesn't do you any harm. Therefore, there is no logical reason not to merge it.

As for the non-string attribute values, there is a change: https://github.com/sparklemotion/nokogiri/pull/729/files#L0R261. Without that change, the test fails.

Owner

flavorjones commented Oct 5, 2012

Fine. Please rebase so whitespace changes and revert commits aren't present.

Contributor

benlangfeld commented Oct 5, 2012

Rebased on master.

flavorjones added a commit that referenced this pull request Oct 5, 2012

Merge pull request #729 from adhearsion/feature/misc
XPath lookup with namespaces with hash keys and XML::Node#[]= should stringify values

@flavorjones flavorjones merged commit dae5dcb into sparklemotion:master Oct 5, 2012

1 check failed

default The Travis build failed
Details
Owner

flavorjones commented Oct 5, 2012

Merged, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment