peachy 0.3.5 → 0.4.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 +12 -0
- data/README.rdoc +24 -1
- data/lib/peachy.rb +3 -2
- data/lib/peachy/method_name.rb +5 -5
- data/lib/peachy/parsers/nokogiri_wrapper.rb +2 -2
- data/lib/peachy/parsers/parser_factory.rb +3 -2
- data/lib/peachy/string_styler.rb +4 -0
- data/lib/peachy/version.rb +1 -1
- data/spec/{all_parser_wrappers_spec.rb → all_parser_wrappers_group.rb} +0 -0
- data/spec/method_name_spec.rb +7 -2
- data/spec/{mimc_spec.rb → mimic_spec.rb} +0 -0
- data/spec/nokigiri_wrapper_spec.rb +1 -0
- data/spec/{simple_content_wrapper_for_Peachy_spec.rb → simple_content_wrapper_for_peachy_spec.rb} +0 -0
- metadata +7 -7
data/History.txt
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
+
== 0.3.5
|
2
|
+
|
3
|
+
* Improved compatibility for Ruby 1.9
|
4
|
+
* Method names are treated as symbols rather than strings
|
5
|
+
|
6
|
+
== 0.3.4
|
7
|
+
|
8
|
+
* Minor refactorings.
|
9
|
+
|
1
10
|
== 0.3.3
|
11
|
+
|
2
12
|
* Minor improvements
|
3
13
|
* Added some more documentation to methods.
|
4
14
|
* Removed whiny-ness from specs.
|
@@ -6,12 +16,14 @@
|
|
6
16
|
* Added some guard clauses on specs that are impacted when Nokogiri is not installed.
|
7
17
|
|
8
18
|
== 0.3.2
|
19
|
+
|
9
20
|
* Minor improvements
|
10
21
|
* Better support for Ruby 1.8.6
|
11
22
|
* Better implementation of MorphIntoArray, which introduced the Mimic module.
|
12
23
|
* Standardised to_s implementations to return the encapsulated XML from Proxies.
|
13
24
|
|
14
25
|
== 0.3.1
|
26
|
+
|
15
27
|
* Minor improvements
|
16
28
|
* Should now work on 1.8.6, so removed minimum rqeuirement of Ruby version 1.8.7
|
17
29
|
* Tweaked some implementation details.
|
data/README.rdoc
CHANGED
@@ -58,6 +58,11 @@ available; otherwise REXML will be loaded and used at runtime.
|
|
58
58
|
It is possible to extend out the parser support, for example Hpricot or LibXML,
|
59
59
|
so let me know if there are any other XML parsers that you'd like Peachy to support.
|
60
60
|
|
61
|
+
A quick note about Nokogiri and XML namespaces: when Nokogiri creates a new XML node,
|
62
|
+
it currently strips all namespaces from the document. This simplification of the
|
63
|
+
underlying XML is necessary so that the interface that Peachy presents to the user is
|
64
|
+
still straightforward even when namespaces are set within the XML.
|
65
|
+
|
61
66
|
=== Elements and Attributes
|
62
67
|
Currently, elements and attributes are accessed in almost exactly the same way;
|
63
68
|
call a method on your current node matching the attribute or element name that
|
@@ -75,9 +80,27 @@ E.g.
|
|
75
80
|
Peachy is just for slurping XML, so this convention should make it easy to know
|
76
81
|
how to access the property that you're after, be they elements or attributes.
|
77
82
|
|
83
|
+
=== Collections
|
84
|
+
Peachy allows collections to be traversed as arrays in the following way:
|
85
|
+
proxy = Peachy::Proxy.new('<peachy><node>One</node><node>Two</node><node>Three</node></peachy>')
|
86
|
+
puts "First node: " + proxy.peachy.node[0].value
|
87
|
+
=> First node: One
|
88
|
+
puts "Second node: " + proxy.peachy.node[1].value
|
89
|
+
=> Second node: Two
|
90
|
+
|
91
|
+
Note that a child of a Peachy Proxy can be either an array, or another proxy, and never
|
92
|
+
both. The intent is that a consumer of some XML would expect something to be a single child
|
93
|
+
all of the time, or a collection all of the time. It doesn't make sense to treat a particular
|
94
|
+
node as a singleton in some circumstances and a collection containing one element in others.
|
95
|
+
|
78
96
|
=== No method name match
|
79
97
|
By default, Peachy will raise a NoMatchingXmlPart error if a method call does not
|
80
98
|
match a child node of the current location. It's possible to globally switch of
|
81
99
|
this behaviour and return nil when no child node is found. This might be
|
82
100
|
desirable if you cannot be certain of the XML that you are trying to interpret
|
83
|
-
until runtime.
|
101
|
+
until runtime.
|
102
|
+
|
103
|
+
Toggle between silent and noisy messages in Peachy using:
|
104
|
+
|
105
|
+
Peachy.be_quiet
|
106
|
+
Peachy.be_loud
|
data/lib/peachy.rb
CHANGED
@@ -51,11 +51,12 @@ module Peachy
|
|
51
51
|
@whine = true
|
52
52
|
end
|
53
53
|
|
54
|
-
#
|
54
|
+
# Indicates whether Peachy will #whine when it runs or not.
|
55
55
|
def self.whiny?
|
56
56
|
return @whine
|
57
57
|
end
|
58
58
|
|
59
|
+
# Creates a new proxy from the XML string passed to it.
|
59
60
|
def self.proxy xml
|
60
61
|
create_factory unless defined? @factory
|
61
62
|
return Proxy.new(@factory.make_from(xml))
|
@@ -67,4 +68,4 @@ module Peachy
|
|
67
68
|
@factory.load_parser
|
68
69
|
return @factory
|
69
70
|
end
|
70
|
-
end
|
71
|
+
end
|
data/lib/peachy/method_name.rb
CHANGED
@@ -12,10 +12,10 @@ module Peachy
|
|
12
12
|
# The valid varations are the underlying method name, plus all variations
|
13
13
|
# provided by methods defined in the StringStyler module.
|
14
14
|
def variations
|
15
|
-
variation_methods.inject([
|
15
|
+
variation_methods.inject([]) {|array, method| array << send(method)}.uniq
|
16
16
|
end
|
17
17
|
|
18
|
-
def as_xpath
|
18
|
+
def as_xpath
|
19
19
|
variations.map {|variation| "./#{variation}" } * '|'
|
20
20
|
end
|
21
21
|
|
@@ -32,10 +32,10 @@ module Peachy
|
|
32
32
|
end
|
33
33
|
|
34
34
|
# Checks whether the method name matches the Ruby convention of lowercase with
|
35
|
-
# underscores.
|
36
|
-
# or numbers
|
35
|
+
# underscores. The only exception is using NS to indicate the end of an XML namespace.
|
36
|
+
# Note that this method does not allow question marks, exclamation marks or numbers.
|
37
37
|
def matches_convention?
|
38
|
-
@method_name =~ /^[a-z]+(?:_[a-z]+){0,}
|
38
|
+
@method_name =~ /^[a-z]+(?:_[a-z]+){0,}(?:NS[a-z]+(?:_[a-z]+){0,})?$/
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -11,7 +11,7 @@ module Peachy
|
|
11
11
|
# returning nil if no element or attribute matching the method name is found
|
12
12
|
# in the children of the current location in the DOM.
|
13
13
|
def find_matches method_name
|
14
|
-
matches = xpath
|
14
|
+
matches = xpath method_name.as_xpath
|
15
15
|
matches.any? ? matches : nil
|
16
16
|
end
|
17
17
|
|
@@ -47,4 +47,4 @@ module Peachy
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -23,7 +23,8 @@ module Peachy
|
|
23
23
|
end
|
24
24
|
|
25
25
|
Parsers =
|
26
|
-
[{:gem => 'nokogiri',
|
26
|
+
[{:gem => 'nokogiri',
|
27
|
+
:implementation => lambda {|xml| NokogiriWrapper.new(Nokogiri::XML(xml).remove_namespaces!)}}]
|
27
28
|
|
28
29
|
DefaultParser =
|
29
30
|
{
|
@@ -32,4 +33,4 @@ module Peachy
|
|
32
33
|
}
|
33
34
|
end
|
34
35
|
end
|
35
|
-
end
|
36
|
+
end
|
data/lib/peachy/string_styler.rb
CHANGED
data/lib/peachy/version.rb
CHANGED
File without changes
|
data/spec/method_name_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Peachy::MethodName" do
|
4
4
|
before(:each) do
|
5
5
|
@method_name = Peachy::MethodName.new 'method_name'
|
6
6
|
end
|
@@ -57,4 +57,9 @@ describe "how to use Peachy::MethodName" do
|
|
57
57
|
method_name = Peachy::MethodName.new('method_Name')
|
58
58
|
lambda { method_name.check_for_convention }.should raise_error(MethodNotInRubyConvention)
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class MultipleNamespacesNotAllowed < Exception
|
63
|
+
def initialize method_name
|
64
|
+
end
|
65
|
+
end
|
File without changes
|
data/spec/{simple_content_wrapper_for_Peachy_spec.rb → simple_content_wrapper_for_peachy_spec.rb}
RENAMED
File without changes
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
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:
|
17
|
+
date: 2011-01-16 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -57,19 +57,18 @@ files:
|
|
57
57
|
- lib/already_an_only_child.rb
|
58
58
|
- spec/nodes_with_children_spec.rb
|
59
59
|
- spec/nokigiri_wrapper_spec.rb
|
60
|
+
- spec/all_parser_wrappers_group.rb
|
60
61
|
- spec/method_name_spec.rb
|
61
|
-
- spec/mimc_spec.rb
|
62
62
|
- spec/pascal_case_names_spec.rb
|
63
63
|
- spec/rexml_wrapper_spec.rb
|
64
|
+
- spec/mimic_spec.rb
|
64
65
|
- spec/simple_element_referenced_as_collections_spec.rb
|
65
66
|
- spec/make_peachy_quiet_spec.rb
|
66
67
|
- spec/inferring_a_method_from_an_attribute_spec.rb
|
67
68
|
- spec/camel_case_names_spec.rb
|
68
69
|
- spec/collections_with_children_as_arrays_spec.rb
|
69
70
|
- spec/nokogiri_is_the_available_xml_parser_spec.rb
|
70
|
-
- spec/simple_content_wrapper_for_Peachy_spec.rb
|
71
71
|
- spec/simple_xml_collections_as_arrays_spec.rb
|
72
|
-
- spec/all_parser_wrappers_spec.rb
|
73
72
|
- spec/nested_elements_spec.rb
|
74
73
|
- spec/inferring_a_method_from_element_name_spec.rb
|
75
74
|
- spec/rexml_attribute_wrapper_spec.rb
|
@@ -82,6 +81,7 @@ files:
|
|
82
81
|
- spec/spec_helper.rb
|
83
82
|
- spec/childless_elements_referenced_as_collections_spec.rb
|
84
83
|
- spec/hyphen_separated_names_spec.rb
|
84
|
+
- spec/simple_content_wrapper_for_peachy_spec.rb
|
85
85
|
- README.rdoc
|
86
86
|
- History.txt
|
87
87
|
has_rdoc: true
|