peachy 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ require File.join(File.dirname(__FILE__), 'invalid_proxy_parameters')
5
5
  require File.join(File.dirname(__FILE__), 'method_not_in_ruby_convention')
6
6
  require File.join(File.dirname(__FILE__), 'no_matching_xml_part')
7
7
  require File.join(File.dirname(__FILE__), 'nothing_to_mimic')
8
+ require File.join(File.dirname(__FILE__), 'peachy/compatibility')
8
9
  require File.join(File.dirname(__FILE__), 'peachy/string_styler')
9
10
  require File.join(File.dirname(__FILE__), 'peachy/method_name')
10
11
  require File.join(File.dirname(__FILE__), 'peachy/method_mask')
@@ -0,0 +1,7 @@
1
+ module Peachy
2
+ module Compatibility
3
+ def version_safe_method_id(method)
4
+ RUBY_VERSION < '1.9' ? method.to_s : method.to_sym
5
+ end
6
+ end
7
+ end
@@ -1,14 +1,12 @@
1
1
  module Peachy
2
2
  module MethodMask
3
+ include Compatibility
4
+
3
5
  private
4
6
  def hide_public_methods exceptions
5
- formatted_exception = exceptions.map {|method_name| version_safe_method(method_name)}
7
+ formatted_exception = exceptions.map {|method_name| version_safe_method_id(method_name)}
6
8
  methods_to_hide = public_instance_methods.map {|method| method unless formatted_exception.include? method }.compact
7
9
  private *methods_to_hide
8
10
  end
9
-
10
- def version_safe_method(method_name)
11
- /^1\.8/ === RUBY_VERSION ? method_name.to_s : method_name.to_s.to_sym
12
- end
13
11
  end
14
12
  end
@@ -1,12 +1,16 @@
1
1
  module Peachy
2
2
  module MorphIntoArray
3
+ include Compatibility
4
+
3
5
  private
6
+ MethodsForArraysOnly = Array.instance_methods - Object.instance_methods
7
+
4
8
  def used_as_array method_name, block_given, *args
5
9
  return (block_given or args.size > 0) && array_can?(method_name)
6
10
  end
7
11
 
8
12
  def array_can? method_name
9
- Array.instance_methods.include?(method_name.to_s) && method_name != :type
13
+ MethodsForArraysOnly.include?( version_safe_method_id(method_name))
10
14
  end
11
15
 
12
16
  def morph_into_array to_add_to_array, method_to_invoke, *args, &block
@@ -6,7 +6,7 @@ module Peachy
6
6
  # This hides all public methods on the class except for 'methods', 'nil?'
7
7
  # 'respond_to?', 'inspect' and 'instance_eval', which I've found are too
8
8
  # useful / fundamental / dangerous to hide.
9
- hide_public_methods ['methods', 'nil?', 'respond_to?', 'inspect', 'instance_eval', 'kind_of?', 'send']
9
+ hide_public_methods ['methods', 'nil?', 'respond_to?', 'inspect', 'instance_eval', 'kind_of?', 'send', 'is_a?']
10
10
 
11
11
  # Takes either a string containing XML or a Nokogiri::XML::Element as the
12
12
  # single argument.
@@ -1,3 +1,3 @@
1
1
  module Peachy
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.5'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- shared_examples_for "all parser wrappers" do
3
+ shared_examples_for 'all parser wrappers in Peachy' do
4
4
  it "should be able to find the correct matches in the underlying XML" do
5
5
  matches = @wrapper.find_matches(Peachy::MethodName.new('child'))
6
6
  matches.size.should == 1
@@ -15,10 +15,10 @@ describe "attributes on a parent node" do
15
15
 
16
16
  it "should define the attribute name as a method" do
17
17
  @proxy.root.test_node.name
18
- @proxy.root.test_node.methods.should include('name')
18
+ @proxy.root.test_node.methods.map{|m| m.to_sym}.should include(:name)
19
19
  end
20
20
 
21
21
  it "should raise an error if the attirbute does not exist" do
22
22
  lambda { @proxy.root.test_node.other }.should raise_error(NoMatchingXmlPart)
23
23
  end
24
- end
24
+ end
@@ -16,7 +16,7 @@ XML
16
16
 
17
17
  it "should define a method from a camel cased element name" do
18
18
  @proxy.root.test_node.value.should == 'Check meh.'
19
- @proxy.root.methods.should include('test_node')
19
+ @proxy.root.methods.map{|m| m.to_s}.should include('test_node')
20
20
  end
21
21
 
22
22
  it "should match a method to an attribute by camel case" do
@@ -25,12 +25,12 @@ XML
25
25
 
26
26
  it "should define a method from camel cased attribute name" do
27
27
  @proxy.root.second_node.record_label
28
- @proxy.root.second_node.methods.should include('record_label')
28
+ @proxy.root.second_node.methods.map{|m| m.to_s}.should include('record_label')
29
29
  end
30
30
 
31
31
  it "should match parent attribute names" do
32
32
  @proxy.root.third_node.record_label.should == 'Wall of Sound'
33
- @proxy.root.third_node.methods.should include('record_label')
33
+ @proxy.root.third_node.methods.map{|m| m.to_s}.should include('record_label')
34
34
  end
35
35
  end
36
36
 
@@ -26,7 +26,7 @@ STR
26
26
 
27
27
  it "should define a method for the name of the list items" do
28
28
  @peachy_proxy.xml.list.item
29
- @peachy_proxy.xml.list.methods.should include('item')
29
+ @peachy_proxy.xml.list.methods.map{|m| m.to_s}.should include('item')
30
30
  end
31
31
 
32
32
  it "should create the children as expected" do
@@ -44,21 +44,22 @@ XML
44
44
  @proxy.xml.list.item.size.should == 1
45
45
  end
46
46
 
47
- it "should raise an error if the element has already been accessed as a single child" do
47
+ it "should not consider inherited Object instance methods to be an Array method" do
48
48
  expected_message = <<MSG
49
49
  The 'item' node has already been accessed as a single child, but you are now trying to use it as a collection.
50
50
  Do not try to access Peachy::Proxies in a mixed manner in your implementation.
51
51
  MSG
52
- @proxy.xml.list.item.child
52
+ @proxy.xml.list.item.type
53
53
  lambda { @proxy.xml.list.item[0] }.should raise_error(AlreadyAnOnlyChild, expected_message)
54
54
  end
55
55
 
56
- it "should not treat Array#type as an array reference" do
56
+ it "should raise an error if the element has already been accessed as a single child" do
57
57
  expected_message = <<MSG
58
58
  The 'item' node has already been accessed as a single child, but you are now trying to use it as a collection.
59
59
  Do not try to access Peachy::Proxies in a mixed manner in your implementation.
60
60
  MSG
61
- @proxy.xml.list.item.type
61
+ @proxy.xml.list.item.child
62
62
  lambda { @proxy.xml.list.item[0] }.should raise_error(AlreadyAnOnlyChild, expected_message)
63
63
  end
64
+
64
65
  end
@@ -17,7 +17,7 @@ XML
17
17
 
18
18
  it "should define a method for the element name" do
19
19
  @proxy.test_node
20
- @proxy.methods.should include('test_node')
20
+ @proxy.methods.map{|m| m.to_s}.should include('test_node')
21
21
  end
22
22
 
23
23
  it "should match a method to an attribute by pascal case" do
@@ -26,12 +26,12 @@ XML
26
26
 
27
27
  it "should define a method from pascal cased attribute name" do
28
28
  @proxy.test_node.second_child.record_label
29
- @proxy.test_node.second_child.methods.should include('record_label')
29
+ @proxy.test_node.second_child.methods.map{|m| m.to_s}.should include('record_label')
30
30
  end
31
31
 
32
32
  it "should define a method on a parent with attributes" do
33
33
  @proxy.test_node.third_child.record_label.should == 'Rough Trade'
34
- @proxy.test_node.third_child.methods.should include('record_label')
34
+ @proxy.test_node.third_child.methods.map{|m| m.to_s}.should include('record_label')
35
35
  end
36
36
 
37
37
  it "should allow child nodes to be selected after an attrbiute is selected on a parent node" do
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe "inferring a method from an attribute" do
2
4
  before(:each) do
3
5
  @proxy = Peachy::Proxy.new '<test-node id="1" another="yellow">Check meh.</test-node>'
@@ -13,7 +15,7 @@ describe "inferring a method from an attribute" do
13
15
 
14
16
  it "should define a method for the attribute name" do
15
17
  @proxy.test_node.another
16
- @proxy.test_node.methods.should include('another')
18
+ @proxy.test_node.methods.map{|m| m.to_s}.should include('another')
17
19
  end
18
20
 
19
21
  it "should raise an error if method name doesn't match an attribute name" do
@@ -15,18 +15,18 @@ describe "inferring a method from an element name" do
15
15
  end
16
16
 
17
17
  it "should not expose the original method_missing alias publically" do
18
- @proxy.methods.include?('original_method_missing').should be_false
18
+ @proxy.methods.map{|m| m.to_s}.include?('original_method_missing').should be_false
19
19
  end
20
20
 
21
21
  it 'should add a reader for the method to the underlying class if the method does map to underlying XML node' do
22
22
  @proxy.testnode
23
- @proxy.methods.include?('testnode').should be_true
23
+ @proxy.methods.map{|m| m.to_s}.include?('testnode').should be_true
24
24
  end
25
25
 
26
26
  it 'should define the method on an instance, not on the class' do
27
27
  @proxy.testnode
28
- @proxy.methods.should include('testnode')
29
- @another_proxy.methods.should_not include('testnode')
28
+ @proxy.methods.map{|m| m.to_s}.should include('testnode')
29
+ @another_proxy.methods.map{|m| m.to_s}.should_not include('testnode')
30
30
  end
31
31
 
32
32
  it "should return the node contents when the node isn't defined as a method and the contents of the node is at the lowest point of the tree" do
@@ -41,12 +41,16 @@ describe "inferring a method from an element name" do
41
41
  end
42
42
 
43
43
  it "should only contain the expected public and protected methods" do
44
- @proxy.methods.should include('inspect')
45
- @proxy.methods.should include('methods')
46
- @proxy.methods.should include('nil?')
47
- @proxy.methods.should include('respond_to?')
48
- @proxy.methods.should include('to_s')
49
- @proxy.methods.should include('instance_eval')
50
- @proxy.methods.should_not include('id')
44
+ all_methods = @proxy.methods.map{|m| m.to_s}
45
+ all_methods.should include('inspect')
46
+ all_methods.should include('methods')
47
+ all_methods.should include('nil?')
48
+ all_methods.should include('respond_to?')
49
+ all_methods.should include('to_s')
50
+ all_methods.should include('instance_eval')
51
+ all_methods.should include('kind_of?')
52
+ all_methods.should include('send')
53
+ all_methods.should include('is_a?')
54
+ all_methods.should_not include('id')
51
55
  end
52
56
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'ruby-debug'
3
2
 
4
3
  describe "nested elements should be handled corectly by Peachy" do
5
4
  before(:each) do
@@ -12,8 +11,8 @@ describe "nested elements should be handled corectly by Peachy" do
12
11
 
13
12
  it "should define methods for the ancestors" do
14
13
  @proxy.root.first.second
15
- @proxy.root.methods.should include('first')
16
- @proxy.root.first.methods.should include('second')
14
+ @proxy.root.methods.map{|m| m.to_s}.should include('first')
15
+ @proxy.root.first.methods.map{|m| m.to_s}.should include('second')
17
16
  end
18
17
  end
19
18
 
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe "nodes with multiple children should be handled correctly" do
2
4
  before(:each) do
3
5
  @peachy_proxy = Peachy::Proxy.new '<testnode><child>Check meh.</child><second_child><ancestor>Check meh two times.</ancestor></second_child></testnode>'
@@ -11,8 +13,8 @@ describe "nodes with multiple children should be handled correctly" do
11
13
  it "should define a method with the child name on the proxy" do
12
14
  @node_to_test.child
13
15
  @node_to_test.second_child
14
- @node_to_test.methods.should include('child')
15
- @node_to_test.methods.should include('second_child')
16
+ @node_to_test.methods.map{|m| m.to_s}.should include('child')
17
+ @node_to_test.methods.map{|m| m.to_s}.should include('second_child')
16
18
  end
17
19
 
18
20
  it "should recurse the Proxy to ancestors so that a child will have the correct value" do
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require File.join(File.dirname(__FILE__), 'all_parser_wrappers_spec')
3
2
 
4
3
  # this is to ignore this spec if the nokogiri gem is not available
5
4
  if Gem.available? 'nokogiri'
@@ -12,6 +11,6 @@ if Gem.available? 'nokogiri'
12
11
  @expected_wrapper_class = Peachy::Parsers::NokogiriWrapper
13
12
  end
14
13
 
15
- it_should_behave_like "all parser wrappers"
14
+ it_should_behave_like 'all parser wrappers in Peachy'
16
15
  end
17
16
  end
@@ -35,7 +35,7 @@ if Gem.available? 'nokogiri'
35
35
 
36
36
  it "should enable a way to a new NokogiriWrapper" do
37
37
  @factory.load_parser
38
- @factory.methods.should include('make_from')
38
+ @factory.methods.map{|m| m.to_s}.should include('make_from')
39
39
  end
40
40
 
41
41
  it "should create a NokogiriWrapper from xml" do
@@ -45,4 +45,4 @@ if Gem.available? 'nokogiri'
45
45
  wrapper.content.should == 'Stuff'
46
46
  end
47
47
  end
48
- end
48
+ end
@@ -33,7 +33,7 @@ describe "only REXML is available" do
33
33
 
34
34
  it "should enable a way to a new REXMLWrapper" do
35
35
  @factory.load_parser
36
- @factory.methods.should include('make_from')
36
+ @factory.methods.map{|m| m.to_s}.should include('make_from')
37
37
  end
38
38
 
39
39
  it "should create a REXMLWrapper from xml" do
@@ -17,7 +17,7 @@ XML
17
17
 
18
18
  it "should define a method from a pascal cased element name" do
19
19
  @proxy.root.test_node.value.should == 'Check meh.'
20
- @proxy.root.methods.should include('test_node')
20
+ @proxy.root.methods.map{|m| m.to_s}.should include('test_node')
21
21
  end
22
22
 
23
23
  it "should match a method to an attribute by pascal case" do
@@ -26,12 +26,12 @@ XML
26
26
 
27
27
  it "should define a method from pascal cased attribute name" do
28
28
  @proxy.root.second_node.record_label
29
- @proxy.root.second_node.methods.should include('record_label')
29
+ @proxy.root.second_node.methods.map{|m| m.to_s}.should include('record_label')
30
30
  end
31
31
 
32
32
  it "should define a method on a parent with attributes" do
33
33
  @proxy.root.third_node.record_label.should == 'Wall of Sound'
34
- @proxy.root.third_node.methods.should include('record_label')
34
+ @proxy.root.third_node.methods.map{|m| m.to_s}.should include('record_label')
35
35
  end
36
36
 
37
37
  it "should allow child nodes to be selected after an attrbiute is selected on a parent node" do
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  require 'rexml/document'
3
- require File.join(File.dirname(__FILE__), 'all_parser_wrappers_spec')
4
3
 
5
4
  describe "the REXML parser wrapper class" do
6
5
  before(:each) do
@@ -10,5 +9,5 @@ describe "the REXML parser wrapper class" do
10
9
  @expected_wrapper_class = Peachy::Parsers::REXMLWrapper
11
10
  end
12
11
 
13
- it_should_behave_like "all parser wrappers"
12
+ it_should_behave_like 'all parser wrappers in Peachy'
14
13
  end
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe "a simple element referenced as the first part of a collection" do
2
4
  before(:each) do
3
5
  xml = <<XML
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe "a simple XML collection should be interpretted as an array" do
2
4
  before(:each) do
3
5
  xml = "<xml><stuff><item>first</item><item>second</item><item>third</item></stuff></xml>"
@@ -10,7 +12,7 @@ describe "a simple XML collection should be interpretted as an array" do
10
12
 
11
13
  it "should define a method for the item list name" do
12
14
  @proxy.xml.stuff.item
13
- @proxy.xml.stuff.methods.should include('item')
15
+ @proxy.xml.stuff.methods.map{|m| m.to_s}.should include('item')
14
16
  end
15
17
 
16
18
  it "should set each array item to the content for the list item" do
@@ -1,6 +1,6 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../lib/peachy'))
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'peachy'))
2
2
  require 'mocha'
3
3
 
4
- Spec::Runner.configure do |config|
4
+ RSpec.configure do |config|
5
5
  config.mock_with :mocha
6
6
  end
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe "using Peachy::Proxy incorrectly" do
2
4
  before(:each) do
3
5
  @proxy = Peachy::Proxy.new '<testnode>Check meh.</testnode>'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 4
9
- version: 0.3.4
8
+ - 5
9
+ version: 0.3.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - NJ Pearman
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-08 00:00:00 +01:00
17
+ date: 2010-12-13 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -31,56 +31,57 @@ extensions: []
31
31
  extra_rdoc_files:
32
32
  - README.rdoc
33
33
  files:
34
+ - lib/peachy.rb
35
+ - lib/peachy/proxy.rb
36
+ - lib/peachy/my_meta_class.rb
37
+ - lib/peachy/string_styler.rb
34
38
  - lib/peachy/xml_node.rb
35
- - lib/peachy/childless_proxy_with_attributes.rb
36
- - lib/peachy/method_name.rb
37
- - lib/peachy/mimic.rb
39
+ - lib/peachy/compatibility.rb
38
40
  - lib/peachy/method_mask.rb
39
- - lib/peachy/simple_content.rb
40
- - lib/peachy/current_method_call.rb
41
- - lib/peachy/version.rb
42
- - lib/peachy/proxy.rb
41
+ - lib/peachy/parsers/parser_wrapper.rb
43
42
  - lib/peachy/parsers/rexml_attribute_wrapper.rb
44
43
  - lib/peachy/parsers/nokogiri_wrapper.rb
45
- - lib/peachy/parsers/parser_factory.rb
46
- - lib/peachy/parsers/parser_wrapper.rb
47
44
  - lib/peachy/parsers/rexml_wrapper.rb
45
+ - lib/peachy/parsers/parser_factory.rb
46
+ - lib/peachy/current_method_call.rb
48
47
  - lib/peachy/morph_into_array.rb
49
- - lib/peachy/my_meta_class.rb
50
- - lib/peachy/string_styler.rb
48
+ - lib/peachy/simple_content.rb
49
+ - lib/peachy/version.rb
50
+ - lib/peachy/method_name.rb
51
+ - lib/peachy/childless_proxy_with_attributes.rb
52
+ - lib/peachy/mimic.rb
53
+ - lib/method_not_in_ruby_convention.rb
54
+ - lib/invalid_proxy_parameters.rb
51
55
  - lib/nothing_to_mimic.rb
52
56
  - lib/no_matching_xml_part.rb
53
- - lib/invalid_proxy_parameters.rb
54
- - lib/method_not_in_ruby_convention.rb
55
57
  - lib/already_an_only_child.rb
56
- - lib/peachy.rb
57
- - spec/nokogiri_is_the_available_xml_parser_spec.rb
58
- - spec/hyphen_separated_names_spec.rb
59
- - spec/proxy_spec.rb
60
- - spec/elements_referenced_as_collections_spec.rb
61
- - spec/simple_content_wrapper_for_Peachy_spec.rb
62
- - spec/collections_with_children_as_arrays_spec.rb
58
+ - spec/nodes_with_children_spec.rb
59
+ - spec/nokigiri_wrapper_spec.rb
63
60
  - spec/method_name_spec.rb
64
- - spec/childless_elements_referenced_as_collections_spec.rb
65
- - spec/make_peachy_quiet_spec.rb
66
- - spec/simple_xml_collections_as_arrays_spec.rb
67
- - spec/simple_element_referenced_as_collections_spec.rb
68
- - spec/using_peachy_proxy_incorrectly_spec.rb
69
61
  - spec/mimc_spec.rb
62
+ - spec/pascal_case_names_spec.rb
63
+ - spec/rexml_wrapper_spec.rb
64
+ - spec/simple_element_referenced_as_collections_spec.rb
65
+ - spec/make_peachy_quiet_spec.rb
70
66
  - spec/inferring_a_method_from_an_attribute_spec.rb
71
67
  - spec/camel_case_names_spec.rb
72
- - spec/attributes_on_a_parent_node_spec.rb
73
- - spec/pascal_case_names_spec.rb
74
- - spec/peachy_spec.rb
75
- - spec/only_rexml_is_available_spec.rb
76
- - spec/parsers/rexml_attribute_wrapper_spec.rb
77
- - spec/parsers/all_parser_wrappers_spec.rb
78
- - spec/parsers/nokigiri_wrapper_spec.rb
79
- - spec/parsers/rexml_wrapper_spec.rb
68
+ - spec/collections_with_children_as_arrays_spec.rb
69
+ - spec/nokogiri_is_the_available_xml_parser_spec.rb
70
+ - spec/simple_content_wrapper_for_Peachy_spec.rb
71
+ - spec/simple_xml_collections_as_arrays_spec.rb
72
+ - spec/all_parser_wrappers_spec.rb
73
+ - spec/nested_elements_spec.rb
80
74
  - spec/inferring_a_method_from_element_name_spec.rb
75
+ - spec/rexml_attribute_wrapper_spec.rb
76
+ - spec/elements_referenced_as_collections_spec.rb
77
+ - spec/only_rexml_is_available_spec.rb
78
+ - spec/proxy_spec.rb
79
+ - spec/peachy_spec.rb
80
+ - spec/attributes_on_a_parent_node_spec.rb
81
+ - spec/using_peachy_proxy_incorrectly_spec.rb
81
82
  - spec/spec_helper.rb
82
- - spec/nested_elements_spec.rb
83
- - spec/nodes_with_children_spec.rb
83
+ - spec/childless_elements_referenced_as_collections_spec.rb
84
+ - spec/hyphen_separated_names_spec.rb
84
85
  - README.rdoc
85
86
  - History.txt
86
87
  has_rdoc: true
@@ -94,6 +95,7 @@ rdoc_options:
94
95
  require_paths:
95
96
  - lib
96
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
97
99
  requirements:
98
100
  - - ">="
99
101
  - !ruby/object:Gem::Version
@@ -101,6 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
103
  - 0
102
104
  version: "0"
103
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
104
107
  requirements:
105
108
  - - ">="
106
109
  - !ruby/object:Gem::Version
@@ -110,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
113
  requirements: []
111
114
 
112
115
  rubyforge_project:
113
- rubygems_version: 1.3.6
116
+ rubygems_version: 1.3.7
114
117
  signing_key:
115
118
  specification_version: 3
116
119
  summary: Peachy gives a very simple object-style interface on top of an XML DOM.