peachy 0.2.1 → 0.3.0

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.
data/History.txt CHANGED
@@ -1,3 +1,22 @@
1
+ == 0.3.0
2
+
3
+ * Major improvements
4
+ * No longer hard-wired to Nokogiri, determining which XML parser is available
5
+ at first usage, defaulting to REXML if Nokogiri is not found.
6
+
7
+ * Minor improvements
8
+ * Improved implementation of NokogiriWrapper.
9
+
10
+
11
+ == 0.2.1
12
+
13
+ * Major improvements
14
+ * Actually a breaking change from previous version, introducing NokogiriWrapper.
15
+ It's no longer possible to pass a Nokogiri node directly into Peachy.
16
+ * Only children can now be treated as if they are arrays in any way, morphing into
17
+ an array if treated as an array.
18
+
19
+
1
20
  == 0.2.0
2
21
 
3
22
  * Major improvements
data/README.rdoc CHANGED
@@ -14,18 +14,14 @@ then
14
14
 
15
15
  require 'peachy'
16
16
 
17
- in irb/your codebase to get going.
17
+ in irb / your codebase to get going.
18
18
 
19
19
  == Usage
20
20
  The Peachy::Proxy is the key class in Peachy. Create a new instance of a
21
- Peachy::Proxy passing in either a raw XML string, or a Nokogiri::XML instance
21
+ Peachy::Proxy by passing in a raw XML string
22
22
 
23
23
  proxy = Peachy::Proxy.new('<xml><node>Peachy</node></xml>')
24
24
 
25
- or
26
-
27
- proxy = Peachy::Proxy.new(Nokogiri::XML('<xml><node>Peachy</node></xml>'))
28
-
29
25
  Once you have a Proxy, it's straightforward to drill down through the XML by
30
26
  node name:
31
27
 
@@ -43,8 +39,10 @@ More detailed usage examples can be found in the .rb files in the /test director
43
39
 
44
40
  === XML parsing
45
41
 
46
- Currently, Peachy is hard wired to use Nokogiri for XML parsing, but this will
47
- be abstracted out at some point.
42
+ Peachy tries to determine which XML parser to load when it is first used. Nokogiri
43
+ is currently the first choice, defaulting to REXML if Nokogiri is not available.
44
+ It's possible to extend this out so let me know if there are any other XML parsers
45
+ that you'd like Peachy to support.
48
46
 
49
47
  === Elements and Attributes
50
48
 
data/lib/peachy.rb CHANGED
@@ -4,7 +4,6 @@ require File.join(File.dirname(__FILE__), 'already_an_only_child')
4
4
  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
- require File.join(File.dirname(__FILE__), 'no_xml_parser_available')
8
7
  require File.join(File.dirname(__FILE__), 'peachy/convention_checks')
9
8
  require File.join(File.dirname(__FILE__), 'peachy/string_styler')
10
9
  require File.join(File.dirname(__FILE__), 'peachy/method_name')
@@ -13,14 +12,17 @@ require File.join(File.dirname(__FILE__), 'peachy/morph_into_array')
13
12
  require File.join(File.dirname(__FILE__), 'peachy/my_meta_class')
14
13
  require File.join(File.dirname(__FILE__), 'peachy/xml_node')
15
14
  require File.join(File.dirname(__FILE__), 'peachy/simple_content')
16
- require File.join(File.dirname(__FILE__), 'peachy/xml_parser_factory')
15
+ require File.join(File.dirname(__FILE__), 'peachy/parsers/parser_factory')
16
+ require File.join(File.dirname(__FILE__), 'peachy/parsers/with_xpath')
17
+ require File.join(File.dirname(__FILE__), 'peachy/parsers/parser_wrapper')
17
18
  require File.join(File.dirname(__FILE__), 'peachy/parsers/nokogiri_wrapper')
19
+ require File.join(File.dirname(__FILE__), 'peachy/parsers/rexml_wrapper')
20
+ require File.join(File.dirname(__FILE__), 'peachy/parsers/rexml_attribute_wrapper')
18
21
  require File.join(File.dirname(__FILE__), 'peachy/proxy')
19
22
  require File.join(File.dirname(__FILE__), 'peachy/proxy_factory')
20
23
  require File.join(File.dirname(__FILE__), 'peachy/childless_proxy_with_attributes')
21
24
 
22
25
  # first up, load the underlying XML parser that Peachy will use
23
- Peachy::XmlParserFactory.new.load_parser
24
26
 
25
27
  module Peachy
26
28
  def self.whine
@@ -30,4 +32,16 @@ module Peachy
30
32
  def self.whiny?
31
33
  return @whine
32
34
  end
35
+
36
+ def self.proxy xml
37
+ create_factory unless defined? @factory
38
+ return Proxy.new(@factory.make_from(xml))
39
+ end
40
+
41
+ private
42
+ def self.create_factory
43
+ @factory ||= Peachy::Parsers::ParserFactory.new
44
+ @factory.load_parser
45
+ return @factory
46
+ end
33
47
  end
@@ -1,6 +1,8 @@
1
1
  module Peachy
2
2
  module Parsers
3
- class NokogiriWrapper
3
+ class NokogiriWrapper < ParserWrapper
4
+ include WithXPath
5
+
4
6
  def initialize nokogiri
5
7
  @nokogiri = nokogiri
6
8
  end
@@ -10,32 +12,29 @@ module Peachy
10
12
  # in the children of the current location in the DOM.
11
13
  def find_matches method_name
12
14
  matches = xpath(xpath_for(method_name))
13
- return nil if matches.length < 1
14
- return matches
15
+ matches.any? ? matches : nil
15
16
  end
16
17
 
17
18
  def find_match_by_attributes method_name
18
- mapped = method_name.variations.map {|variation| attribute(variation) }
19
- mapped.find {|match| match != nil }
20
- end
21
-
22
- def find_attribute method_name
23
- attribute(method_name.to_s)
19
+ match = @nokogiri.attribute_nodes.find do |attribute|
20
+ attribute if method_name.variations.include? attribute.name
21
+ end
22
+ match.nil? ? nil : make_from(match)
24
23
  end
25
24
 
26
25
  def has_children_and_attributes?
27
- there_are_child_nodes? and node_has_attributes?
26
+ has_children? and has_attributes?
28
27
  end
29
28
 
30
29
  # Determines whether the given element contains any child elements or not.
31
30
  # The choice of implementation is based on performance tests between using
32
31
  # XPath and a Ruby iterator.
33
- def there_are_child_nodes?
34
- children.any? {|child| child.kind_of? Peachy::Parsers::NokogiriWrapper }
32
+ def has_children?
33
+ @nokogiri.children.any? {|child| child.kind_of? Nokogiri::XML::Element }
35
34
  end
36
35
 
37
- def node_has_attributes?
38
- attribute_nodes.size > 0
36
+ def has_attributes?
37
+ @nokogiri.attribute_nodes.size > 0
39
38
  end
40
39
 
41
40
  def content
@@ -47,26 +46,12 @@ module Peachy
47
46
  end
48
47
 
49
48
  private
50
- def attribute_nodes
51
- @nokogiri.attribute_nodes.map {|attribute| attribute.content }
52
- end
53
-
54
- def children
55
- @nokogiri.children.map {|child| NokogiriWrapper.new(child) if child.kind_of? Nokogiri::XML::Element }
56
- end
57
-
58
- # Gets the XPath for all variations of the MethodName instance
59
- def xpath_for method_name
60
- method_name.variations.map {|variation| "./#{variation}" } * '|'
61
- end
62
-
63
49
  def xpath xpath
64
- @nokogiri.xpath(xpath).map{|noko_node| NokogiriWrapper.new(noko_node) }
50
+ @nokogiri.xpath(xpath).map{|noko_node| make_from(noko_node) }
65
51
  end
66
52
 
67
- def attribute attribute_name
68
- noko = @nokogiri.attribute(attribute_name)
69
- noko.nil?? nil : NokogiriWrapper.new(noko)
53
+ def make_from child
54
+ NokogiriWrapper.new(child)
70
55
  end
71
56
  end
72
57
  end
@@ -0,0 +1,22 @@
1
+ module Peachy
2
+ module Parsers
3
+ class ParserFactory
4
+ def load_parser
5
+ return load_up(:nokogiri) if Gem.available? /nokogiri/
6
+ require('rexml/document')
7
+ @parser = :rexml
8
+ end
9
+
10
+ def make_from raw_xml
11
+ return NokogiriWrapper.new(Nokogiri::XML(raw_xml)) if @parser == :nokogiri
12
+ return REXMLWrapper.new(REXML::Document.new(raw_xml)) if @parser == :rexml
13
+ end
14
+
15
+ private
16
+ def load_up xml_parser
17
+ require(xml_parser.to_s)
18
+ @parser = xml_parser
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ module Peachy
2
+ module Parsers
3
+ class ParserWrapper
4
+ def initialize
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module Peachy
2
+ module Parsers
3
+ class REXMLAttributeWrapper < ParserWrapper
4
+ def initialize array
5
+ @attribute = array
6
+ end
7
+
8
+ def content
9
+ @attribute.last
10
+ end
11
+
12
+ def name
13
+ @attribute.first
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ module Peachy
2
+ module Parsers
3
+ class REXMLWrapper < ParserWrapper
4
+ include WithXPath
5
+
6
+ def initialize rexml_element
7
+ @rexml = rexml_element
8
+ end
9
+
10
+ def find_matches method_name
11
+ matches = REXML::XPath.match(@rexml, xpath_for(method_name))
12
+ return nil if matches.size < 1
13
+ matches.map {|node| REXMLWrapper.new(node)}
14
+ end
15
+
16
+ def find_match_by_attributes method_name
17
+ match = @rexml.attributes.find {|attribute| method_name.variations.include? attribute.first }
18
+ match.nil? ? nil : REXMLAttributeWrapper.new(match)
19
+ end
20
+
21
+ def has_children?
22
+ @rexml.elements.size > 0
23
+ end
24
+
25
+ def has_attributes?
26
+ @rexml.attributes.size > 0
27
+ end
28
+
29
+ def has_children_and_attributes?
30
+ has_children? and has_attributes?
31
+ end
32
+
33
+ def content
34
+ @rexml.text
35
+ end
36
+
37
+ def name
38
+ @rexml.name
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ module Peachy
2
+ module Parsers
3
+ module WithXPath
4
+ # Gets the XPath for all variations of the MethodName instance
5
+ def xpath_for method_name
6
+ method_name.variations.map {|variation| "./#{variation}" } * '|'
7
+ end
8
+ end
9
+ end
10
+ end
data/lib/peachy/proxy.rb CHANGED
@@ -13,7 +13,7 @@ module Peachy
13
13
  # single argument.
14
14
  def initialize xml_node
15
15
  @xml = xml_node if xml_node.kind_of? String
16
- @nokogiri_node = xml_node if xml_node.kind_of? Peachy::Parsers::NokogiriWrapper #Nokogiri::XML::Element
16
+ @node = xml_node if xml_node.kind_of? Peachy::Parsers::ParserWrapper
17
17
  end
18
18
 
19
19
  # Overloaded so that calls to methods representative of an XML element or
@@ -113,7 +113,7 @@ module Peachy
113
113
  end
114
114
 
115
115
  def create_from_element_list method_name, matches
116
- define_method(method_name) { return matches_to_array(matches) }
116
+ define_method(method_name) { return matches_to_array(matches) }
117
117
  end
118
118
 
119
119
  def matches_to_array matches
@@ -130,7 +130,7 @@ module Peachy
130
130
  end
131
131
 
132
132
  def variables_are_nil?
133
- @xml.nil? and @nokogiri_node.nil?
133
+ @xml.nil? and @node.nil?
134
134
  end
135
135
 
136
136
  def no_matching_xml method_name
@@ -2,22 +2,11 @@ module Peachy
2
2
  class ProxyFactory
3
3
  class << self
4
4
  def create_from_element match
5
- return create_proxy(match) if there_are_child_nodes?(match)
6
- return create_proxy_with_attributes(match) if node_has_attributes?(match)
5
+ return create_proxy(match) if match.has_children?
6
+ return create_proxy_with_attributes(match) if match.has_attributes?
7
7
  return create_content_child(match)
8
8
  end
9
9
 
10
- def node_has_attributes? match
11
- match.node_has_attributes?
12
- end
13
-
14
- # Determines whether the given element contains any child elements or not.
15
- # The choice of implementation is based on performance tests between using
16
- # XPath and a Ruby iterator.
17
- def there_are_child_nodes? match
18
- match.there_are_child_nodes?
19
- end
20
-
21
10
  def create_content_child match
22
11
  SimpleContent.new(match.content, match.name)
23
12
  end
@@ -1,3 +1,3 @@
1
1
  module Peachy
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -14,7 +14,18 @@ module Peachy
14
14
  # variable.
15
15
  def node
16
16
  raise InvalidProxyParameters.new(:xml => nil, :nokogiri => nil) if variables_are_nil?
17
- @nokogiri_node ||= Peachy::Parsers::NokogiriWrapper.new(Nokogiri::XML(@xml))
17
+ @node ||= create
18
+ end
19
+
20
+ def create
21
+ load_factory unless defined? @factory
22
+ @factory.make_from @xml
23
+ end
24
+
25
+ private
26
+ def load_factory
27
+ @factory = Peachy::Parsers::ParserFactory.new
28
+ @factory.load_parser
18
29
  end
19
30
  end
20
31
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "attributes on a parent node" do
4
4
  before(:each) do
5
- @proxy = Peachy::Proxy.new '<root><test_node name="Test"><child>Check meh.</child><test_node></root>'
5
+ @proxy = Peachy::Proxy.new '<root><test_node name="Test"><child>Check meh.</child></test_node></root>'
6
6
  end
7
7
 
8
8
  it "should return the child when accessing it by name" do
@@ -5,7 +5,7 @@ describe "interpreting element and attribute names that are defined in camelCase
5
5
  <root>
6
6
  <testNode>Check meh.</testNode>
7
7
  <secondNode id="2" recordLabel="Wall of Sound">Check meh, too.</secondNode>
8
- <thirdNode id="2" recordLabel="Wall of Sound"><child>Nested</child></secondNode>
8
+ <thirdNode id="2" recordLabel="Wall of Sound"><child>Nested</child></thirdNode>
9
9
  </root>
10
10
  XML
11
11
  end
@@ -1,8 +1,10 @@
1
1
  require 'spec_helper'
2
+ require 'nokogiri'
2
3
 
3
4
  describe "nokogiri is the available XML parser" do
4
5
  before(:each) do
5
- @factory = Peachy::XmlParserFactory.new
6
+ @factory = Peachy::Parsers::ParserFactory.new
7
+ expectation = @factory.stubs(:require).with('nokogiri').returns(true)
6
8
  end
7
9
 
8
10
  it "should check whether Nokogiri is available" do
@@ -11,15 +13,28 @@ describe "nokogiri is the available XML parser" do
11
13
  expectation.satisfied?.should be_true
12
14
  end
13
15
 
14
- it "should return Nokogiri if Nokogiri is an available gem" do
16
+ it "should return Nokogiri" do
15
17
  parser_type = @factory.load_parser
16
18
  parser_type.should == :nokogiri
17
19
  end
18
20
 
19
- it "should load Nokogiri if Nokogiri is an available gem" do
21
+ it "should load Nokogiri" do
20
22
  expectation = @factory.expects(:require).with('nokogiri').returns(true)
21
23
  parser_type = @factory.load_parser
22
24
  expectation.satisfied?.should be_true
23
25
  end
26
+
27
+ it "should not load REXML" do
28
+ expectation = @factory.expects(:require).with('rexml/document').never.returns(true)
29
+ parser_type = @factory.load_parser
30
+ expectation.satisfied?.should be_true
31
+ end
32
+
33
+ it "should create a NokogiriWrapper from xml" do
34
+ @factory.load_parser
35
+ wrapper = @factory.make_from '<thing>Stuff</thing>'
36
+ wrapper.should be_a Peachy::Parsers::NokogiriWrapper
37
+ wrapper.content.should == 'Stuff'
38
+ end
24
39
  end
25
40
 
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'rexml/document'
3
+
4
+ describe "only REXML is available" do
5
+ before(:each) do
6
+ @factory = Peachy::Parsers::ParserFactory.new
7
+ @factory.stubs(:require).with('rexml/document').returns(true)
8
+ Gem.stubs(:available?).with(/nokogiri/).returns(false)
9
+ end
10
+
11
+ it "should return REXML if no other XML parser is available" do
12
+ parser = @factory.load_parser
13
+ parser.should == :rexml
14
+ end
15
+
16
+ it "should load REXML" do
17
+ expectation = @factory.expects(:require).with('rexml/document').returns(true)
18
+ @factory.load_parser
19
+ expectation.satisfied?.should be_true
20
+ end
21
+
22
+ it "should check whether other XML parsers are available" do
23
+ expectation = Gem.expects(:available?).with(/nokogiri/).returns(false)
24
+ @factory.load_parser
25
+ expectation.satisfied?.should be_true
26
+ end
27
+
28
+ it "should not load any other XML parsers" do
29
+ expectation = @factory.expects(:require).with('nokogiri').never.returns(false)
30
+ @factory.load_parser
31
+ expectation.satisfied?.should be_true
32
+ end
33
+
34
+ it "should create a REXMLWrapper from xml" do
35
+ @factory.load_parser
36
+ wrapper = @factory.make_from '<thing>Stuff</thing>'
37
+ wrapper.should be_a Peachy::Parsers::REXMLWrapper
38
+ wrapper.has_children?.should be_true
39
+ end
40
+ end
41
+
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for "all parser wrappers" do
4
+ it "should be able to find the correct matches in the underlying XML" do
5
+ matches = @wrapper.find_matches(Peachy::MethodName.new('child'))
6
+ matches.size.should == 1
7
+ matches[0].name.should == 'child'
8
+ matches[0].content.should == 'Name'
9
+ matches[0].should be_a @expected_wrapper_class
10
+ end
11
+
12
+ it "should return no matches for a child name that doesn't exist" do
13
+ matches = @wrapper.find_matches(Peachy::MethodName.new('not_a_child'))
14
+ matches.should be_nil
15
+ end
16
+
17
+ it "should be able to find the correct attribute matches in the underlying XML" do
18
+ match = @wrapper.find_match_by_attributes(Peachy::MethodName.new('type'))
19
+ match.name.should == 'type'
20
+ match.content.should == 'test'
21
+ end
22
+
23
+ it "should return no matches for an attribute name that doesn't exist" do
24
+ matches = @wrapper.find_match_by_attributes(Peachy::MethodName.new('attrbiute'))
25
+ matches.should be_nil
26
+ end
27
+
28
+ it "should indicate that an element has children" do
29
+ @wrapper.has_children?.should be_true
30
+ end
31
+
32
+ it "should indicate that an element has an attributes" do
33
+ @wrapper.has_attributes?.should be_true
34
+ end
35
+
36
+ it "should indicate that an element has both children and an attribute" do
37
+ @wrapper.has_children_and_attributes?.should be_true
38
+ end
39
+ end
40
+
41
+ describe "the Nokogiri parser wrapper class" do
42
+ before(:each) do
43
+ noko = Nokogiri::XML('<root type="test"><child>Name</child></root>')
44
+ @wrapper = Peachy::Parsers::NokogiriWrapper.new((noko/'root')[0])
45
+ @expected_wrapper_class = Peachy::Parsers::NokogiriWrapper
46
+ end
47
+
48
+ it_should_behave_like "all parser wrappers"
49
+ end
50
+
51
+ require 'rexml/document'
52
+
53
+ describe "the REXML parser wrapper class" do
54
+ before(:each) do
55
+ rexml = REXML::Document.new('<root type="test"><child>Name</child></root>')
56
+ @wrapper = Peachy::Parsers::REXMLWrapper.new rexml.root
57
+ @expected_wrapper_class = Peachy::Parsers::REXMLWrapper
58
+ end
59
+
60
+ it_should_behave_like "all parser wrappers"
61
+ end
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
+
2
3
  describe "interpreting element and attribute names that are defined in PascalCase" do
3
4
  before(:each) do
4
5
  @proxy = Peachy::Proxy.new <<XML
5
6
  <Root>
6
7
  <TestNode>Check meh.</TestNode>
7
8
  <SecondNode Id="2" RecordLabel="Wall of Sound">Check meh, too.</SecondNode>
8
- <ThirdNode Id="2" RecordLabel="Wall of Sound"><Child>Check meh again.</Child></SecondNode>
9
+ <ThirdNode Id="2" RecordLabel="Wall of Sound"><Child>Check meh again.</Child></ThirdNode>
9
10
  </Root>
10
11
  XML
11
12
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Peachy do
4
+ it "should allow the creation of a new Proxy" do
5
+ proxy = Peachy.proxy '<test>Hello</test>'
6
+ proxy.test.value.should == 'Hello'
7
+ end
8
+ end
9
+
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - NJ Pearman
@@ -14,26 +14,13 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-18 00:00:00 +01:00
17
+ date: 2010-05-26 00:00:00 +01:00
18
18
  default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: nokogiri
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 3
30
- - 3
31
- version: 1.3.3
32
- type: :runtime
33
- version_requirements: *id001
19
+ dependencies: []
20
+
34
21
  description: |
35
22
  Peachy is an XML slurper that sits on top of existing XML parsers. It dynamically
36
- creates object-style hierachies for simple integration of XML data sources.
23
+ creates object-trees for simple integration of XML data sources.
37
24
 
38
25
  email:
39
26
  - n.pearman@gmail.com
@@ -48,18 +35,21 @@ files:
48
35
  - lib/peachy/convention_checks.rb
49
36
  - lib/peachy/childless_proxy_with_attributes.rb
50
37
  - lib/peachy/method_name.rb
51
- - lib/peachy/xml_parser_factory.rb
52
38
  - lib/peachy/method_mask.rb
53
39
  - lib/peachy/proxy_factory.rb
54
40
  - lib/peachy/simple_content.rb
55
41
  - lib/peachy/version.rb
56
42
  - lib/peachy/proxy.rb
43
+ - lib/peachy/parsers/rexml_attribute_wrapper.rb
57
44
  - lib/peachy/parsers/nokogiri_wrapper.rb
45
+ - lib/peachy/parsers/parser_factory.rb
46
+ - lib/peachy/parsers/with_xpath.rb
47
+ - lib/peachy/parsers/parser_wrapper.rb
48
+ - lib/peachy/parsers/rexml_wrapper.rb
58
49
  - lib/peachy/morph_into_array.rb
59
50
  - lib/peachy/my_meta_class.rb
60
51
  - lib/peachy/string_styler.rb
61
52
  - lib/no_matching_xml_part.rb
62
- - lib/no_xml_parser_available.rb
63
53
  - lib/invalid_proxy_parameters.rb
64
54
  - lib/method_not_in_ruby_convention.rb
65
55
  - lib/already_an_only_child.rb
@@ -67,20 +57,20 @@ files:
67
57
  - spec/nokogiri_is_the_available_xml_parser_spec.rb
68
58
  - spec/hyphen_separated_names_spec.rb
69
59
  - spec/elements_referenced_as_collections_spec.rb
70
- - spec/peachy_parsers_nokogiri_spec.rb
71
60
  - spec/simple_content_wrapper_for_Peachy_spec.rb
72
61
  - spec/collections_with_children_as_arrays_spec.rb
73
62
  - spec/method_name_spec.rb
74
63
  - spec/childless_elements_referenced_as_collections_spec.rb
75
64
  - spec/simple_xml_collections_as_arrays_spec.rb
76
65
  - spec/simple_element_referenced_as_collections_spec.rb
77
- - spec/no_xml_parsers_are_available_spec.rb
78
66
  - spec/using_peachy_proxy_incorrectly_spec.rb
79
67
  - spec/inferring_a_method_from_an_attribute_spec.rb
80
- - spec/libxml_is_the_available_xml_parser_spec.rb
81
68
  - spec/camel_case_names_spec.rb
82
69
  - spec/attributes_on_a_parent_node_spec.rb
83
70
  - spec/pascal_case_names_spec.rb
71
+ - spec/peachy_spec.rb
72
+ - spec/only_rexml_is_available_spec.rb
73
+ - spec/parsers/all_parser_wrappers_spec.rb
84
74
  - spec/inferring_a_method_from_element_name_spec.rb
85
75
  - spec/spec_helper.rb
86
76
  - spec/nested_elements_spec.rb
@@ -102,8 +92,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
92
  - - ">="
103
93
  - !ruby/object:Gem::Version
104
94
  segments:
105
- - 0
106
- version: "0"
95
+ - 1
96
+ - 8
97
+ - 7
98
+ version: 1.8.7
107
99
  required_rubygems_version: !ruby/object:Gem::Requirement
108
100
  requirements:
109
101
  - - ">="
@@ -1,10 +0,0 @@
1
- class NoXmlParserAvailable < Exception
2
- def initialize
3
- super <<MESSAGE
4
- Peachy was unable to find any XML parser gems. PEachy expects one of the following
5
- gems to be installed before use:
6
- Nokogiri
7
- LibXML
8
- MESSAGE
9
- end
10
- end
@@ -1,15 +0,0 @@
1
- module Peachy
2
- class XmlParserFactory
3
- def load_parser
4
- return load_up(:nokogiri) if Gem.available? /nokogiri/
5
- return load_up(:libxml) if Gem.available? /libxml/
6
- raise NoXmlParserAvailable.new
7
- end
8
-
9
- private
10
- def load_up xml_parser
11
- require(xml_parser.to_s)
12
- return xml_parser
13
- end
14
- end
15
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Peachy::XmlParserFactory do
4
- before(:each) do
5
- Gem.stubs(:available?).with(/libxml/).returns(true)
6
- Gem.stubs(:available?).with(/nokogiri/).returns(false)
7
- @factory = Peachy::XmlParserFactory.new
8
- @factory.stubs(:require).with('libxml').returns(true)
9
- end
10
-
11
- it "should return LibXML if Nokogiri is not an available gem" do
12
- parser_type = @factory.load_parser
13
- parser_type.should == :libxml
14
- end
15
-
16
- it "should load LibXML if Nokogiri is not an available gem, but LibXML is" do
17
- first_expectation = Gem.expects(:available?).with(/nokogiri/).returns(false)
18
- second_expectation = @factory.expects(:require).with('libxml').returns(true)
19
- parser_type = @factory.load_parser
20
- first_expectation.satisfied?.should be_true
21
- second_expectation.satisfied?.should be_true
22
- end
23
-
24
- it "should not load Nokogiri if Nokogiri is not an available gem" do
25
- expectation = @factory.expects(:require).with('nokogiri').returns(true).never()
26
- parser_type = @factory.load_parser
27
- expectation.satisfied?.should be_true
28
- end
29
- end
30
-
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "no xml parsers are available" do
4
- before(:each) do
5
- Gem.stubs(:available?).returns(false)
6
- @factory = Peachy::XmlParserFactory.new
7
- end
8
-
9
- it "should blow up if no XML parsing library is available" do
10
- lambda { @factory.load_parser }.should raise_error NoXmlParserAvailable
11
- end
12
- end
13
-
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "nokogiri wrapper" do
4
- before(:each) do
5
- @nokogiri_xml = Nokogiri::XML <<XML
6
- <root identity="1234" category="awesomeness">
7
- <child id="1">Hello</child>
8
- <second_child attribute_one="one" attribute_two="two">Contents</second_child>
9
- </root>
10
- XML
11
- @nokogiri = Peachy::Parsers::NokogiriWrapper.new @nokogiri_xml
12
- end
13
-
14
- it "should have all of the methods that I expect" do
15
- @nokogiri.methods.should include 'content'
16
- @nokogiri.methods.should include 'name'
17
- end
18
-
19
- it "should return the expected content" do
20
- @simple_noko = Peachy::Parsers::NokogiriWrapper.new(Nokogiri::XML('<xml>Hello</xml>'))
21
- @simple_noko.content.should == 'Hello'
22
- end
23
-
24
- it "should return the expected name" do
25
- @nokogiri.name.should == 'document'
26
- end
27
- end
28
-