Empact-roxml 2.4.1 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/History.txt +17 -0
  2. data/MIT-LICENSE +1 -1
  3. data/Manifest.txt +27 -6
  4. data/Rakefile +1 -1
  5. data/TODO +33 -14
  6. data/config/website.yml +2 -0
  7. data/examples/amazon.rb +33 -0
  8. data/examples/current_weather.rb +27 -0
  9. data/examples/dashed_elements.rb +20 -0
  10. data/examples/posts.rb +27 -0
  11. data/examples/twitter.rb +37 -0
  12. data/examples/xml/amazon.xml +133 -0
  13. data/examples/xml/current_weather.xml +89 -0
  14. data/examples/xml/dashed_elements.xml +52 -0
  15. data/examples/xml/posts.xml +23 -0
  16. data/examples/xml/twitter.xml +422 -0
  17. data/lib/roxml.rb +31 -5
  18. data/lib/roxml/{options.rb → definition.rb} +60 -88
  19. data/lib/roxml/extensions.rb +3 -0
  20. data/lib/roxml/hash_definition.rb +59 -0
  21. data/lib/roxml/xml.rb +15 -272
  22. data/lib/roxml/xml/{libxml.rb → parsers/libxml.rb} +13 -5
  23. data/lib/roxml/xml/{rexml.rb → parsers/rexml.rb} +13 -4
  24. data/lib/roxml/xml/references.rb +290 -0
  25. data/roxml.gemspec +4 -4
  26. data/spec/examples/amazon_spec.rb +53 -0
  27. data/spec/examples/current_weather_spec.rb +37 -0
  28. data/spec/examples/dashed_elements_spec.rb +20 -0
  29. data/spec/examples/post_spec.rb +24 -0
  30. data/spec/examples/twitter_spec.rb +32 -0
  31. data/spec/spec.opts +1 -0
  32. data/spec/spec_helper.rb +12 -0
  33. data/tasks/rspec.rake +21 -0
  34. data/test/unit/definition_test.rb +160 -0
  35. data/test/unit/inheritance_test.rb +22 -1
  36. data/test/unit/roxml_test.rb +30 -1
  37. data/test/unit/xml_name_test.rb +29 -0
  38. data/test/unit/xml_namespace_test.rb +38 -1
  39. data/website/index.html +98 -0
  40. metadata +30 -9
  41. data/html/index.html +0 -278
  42. data/html/style.css +0 -79
  43. data/test/unit/options_test.rb +0 -103
data/History.txt CHANGED
@@ -1,3 +1,20 @@
1
+ == 2.4.2 (January 31, 2009)
2
+
3
+ * 4 minor enhancements
4
+
5
+ * add :as => Time, DateTime, and Date support
6
+ * support Pathname, IO and URI objects as #from_xml arguments
7
+ * :as => :bool now supports all capitalizations of 'true', 'false', 'yes', 'no', as well as '1' and '0'
8
+ * For basic types (:as => Integer, Float, Date, &c.), interpret empty strings just
9
+ as missing elements (by returning nil), rather than raising. Raise behavior can be
10
+ accessed by supplying your own block or using the :required option.
11
+
12
+ * 3 bug fixes
13
+
14
+ * Arrays of attrs or elements :as => :bool weren't previously supported. An oversight.
15
+ * Don't apply xml_convention if name is explicitly set
16
+ * Protect xpath operators : and / from modification via String#camelcase & such
17
+
1
18
  == 2.4.1 (January 28, 2009)
2
19
 
3
20
  * 3 minor enhancements
data/MIT-LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2004-2008 by Ben Woosley, Zak Mandhro and Anders Engstrom
3
+ Copyright (c) 2004-2009 by Ben Woosley, Zak Mandhro and Anders Engstrom
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6
6
  and associated documentation files (the "Software"), to deal in the Software without restriction,
data/Manifest.txt CHANGED
@@ -4,9 +4,20 @@ Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  TODO
7
- html/index.html
8
- html/style.css
7
+ config/website.yml
8
+ examples/amazon.rb
9
+ examples/current_weather.rb
10
+ examples/dashed_elements.rb
11
+ examples/posts.rb
12
+ examples/twitter.rb
13
+ examples/xml/amazon.xml
14
+ examples/xml/current_weather.xml
15
+ examples/xml/dashed_elements.xml
16
+ examples/xml/posts.xml
17
+ examples/xml/twitter.xml
9
18
  lib/roxml.rb
19
+ lib/roxml/definition.rb
20
+ lib/roxml/extensions.rb
10
21
  lib/roxml/extensions/active_support.rb
11
22
  lib/roxml/extensions/array.rb
12
23
  lib/roxml/extensions/array/conversions.rb
@@ -14,11 +25,20 @@ lib/roxml/extensions/deprecation.rb
14
25
  lib/roxml/extensions/string.rb
15
26
  lib/roxml/extensions/string/conversions.rb
16
27
  lib/roxml/extensions/string/iterators.rb
17
- lib/roxml/options.rb
28
+ lib/roxml/hash_definition.rb
18
29
  lib/roxml/xml.rb
19
- lib/roxml/xml/libxml.rb
20
- lib/roxml/xml/rexml.rb
30
+ lib/roxml/xml/parsers/libxml.rb
31
+ lib/roxml/xml/parsers/rexml.rb
32
+ lib/roxml/xml/references.rb
21
33
  roxml.gemspec
34
+ spec/examples/amazon_spec.rb
35
+ spec/examples/current_weather_spec.rb
36
+ spec/examples/dashed_elements_spec.rb
37
+ spec/examples/post_spec.rb
38
+ spec/examples/twitter_spec.rb
39
+ spec/spec.opts
40
+ spec/spec_helper.rb
41
+ tasks/rspec.rake
22
42
  tasks/test.rake
23
43
  test/bugs/rexml_bugs.rb
24
44
  test/fixtures/book_malformed.xml
@@ -56,9 +76,9 @@ test/mocks/mocks.rb
56
76
  test/release/dependencies_test.rb
57
77
  test/test_helper.rb
58
78
  test/unit/array_test.rb
79
+ test/unit/definition_test.rb
59
80
  test/unit/freeze_test.rb
60
81
  test/unit/inheritance_test.rb
61
- test/unit/options_test.rb
62
82
  test/unit/overriden_output_test.rb
63
83
  test/unit/roxml_test.rb
64
84
  test/unit/string_test.rb
@@ -79,3 +99,4 @@ vendor/override_rake_task/README
79
99
  vendor/override_rake_task/init.rb
80
100
  vendor/override_rake_task/install.rb
81
101
  vendor/override_rake_task/lib/override_rake_task.rb
102
+ website/index.html
data/Rakefile CHANGED
@@ -38,7 +38,7 @@ require 'newgem/tasks' # load /tasks/*.rake
38
38
 
39
39
  Dir['tasks/**/*.rake'].each { |t| load t }
40
40
 
41
- task :default => :test
41
+ task :default => [:test, :spec]
42
42
 
43
43
  ## Provide the username used to upload website etc.
44
44
  #RubyForgeConfig = {
data/TODO CHANGED
@@ -11,32 +11,51 @@ v 2.5
11
11
  * Ensure (perhaps optionally) that references are unambiguous. That is error/warn
12
12
  a singular specification has multiple possible node references
13
13
 
14
- * Ensure support for nodes which aren't merely children, which hang out deep
15
- in the file, but are accessible via xpath
14
+ * Automatically use Date or DateTime for accessors ending in '_on' and '_at', respectively
15
+
16
+ * Add xml_in helper to share :in declarations between several attributes. E.g.:
17
+
18
+ xml_reader :count, :in => 'Attributes', :as => Integer
19
+ xml_reader :something_else, :in => 'Attributes', :as => Date
20
+
21
+ becomes:
22
+
23
+ xml_in 'Attributes' do |xml|
24
+ xml.reader :count, :as => Integer
25
+ xml.reader :something_else, :as => Date
26
+ end
27
+
28
+ * :self => true for sending method_missing to this attribute?
16
29
 
17
30
  v 3.0
18
31
  * remove deprecated functionality
19
32
 
20
- * Perhaps provide cleaner separation between the specification
21
- of type vs its source in the XML. For example,
33
+ * Clarify API via seperation of concerns. :as for Type, :from and :in for location,
34
+ All other options as named options, e.g. :cdata => true rather than :as => :cdata.
35
+ A few not so great examples...:
22
36
 
23
- xml_reader :count, :from => 'Count, :in => 'Attributes', :as => Integer
24
- xml_reader :count, :attr => 'Count, :in => 'Attributes', :as => Integer
37
+ xml_reader :some_objce, MyObject
38
+ xml_reader :size, :attr, :as => Integer
39
+ xml_reader :count, :attr, :as => Integer
25
40
 
26
41
  become:
27
42
 
28
- xml_reader :count, Integer, 'Atributes/Count'
29
- xml_reader :count, Integer, 'Atributes/@Count'
43
+ xml_reader :some_object, :as => MyObject
44
+ xml_reader :count, :size, :as => Integer, :from => :attr
30
45
 
31
- potentially backward-incompatible change. Needs some thought...
46
+ This will significantly simplify the internals and will also cleanly split
47
+ element type, location, name and options, for a more predictable API.
32
48
 
33
- * Back with XmlSimple/FasterXmlSimple to minimize need for specifications
49
+ It also enables multiple declarations on a single call, ala attr_*
34
50
 
35
- * Use lazy evaluation to minimize parsing time for large files
51
+ xml_reader :count, :size, :number, :as => Integer, :from => :attr
36
52
 
37
- Potential:
53
+ * Commandeer #parse to use opposite #from_xml, but in an unrooted, collection-friendly fashion,
54
+ ala HappyMapper's parse
38
55
 
39
- * Add shorthand support to hash declaration
56
+ * Back with http://xml-object.rubyforge.org/doc/ to minimize need for specifications?
57
+
58
+ * Use lazy evaluation to minimize parsing time for large files
40
59
 
41
- * :as => :self for sending method_missing to this attribute
60
+ * Consider class_inheritable_attribute rather than superclass.try stuff.
42
61
 
@@ -0,0 +1,2 @@
1
+ host: empact@rubyforge.org
2
+ remote_dir: /var/www/gforge-projects/roxml
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../spec/spec_helper')
3
+
4
+ # The document `pita.xml` contains both a default namespace and the 'georss'
5
+ # namespace (for the 'point' xml_reader).
6
+ module PITA
7
+ class Base
8
+ include ROXML
9
+ xml_convention :camelcase
10
+ end
11
+
12
+ class Item < Base
13
+ xml_reader :asin, :from => 'ASIN'
14
+ xml_reader :detail_page_url, :from => 'DetailPageURL'
15
+ xml_reader :manufacturer, :in => './'
16
+ # this is the only xml_reader that exists in a different namespace, so it
17
+ # must be explicitly specified
18
+ xml_reader :point, :from => 'georss:point'
19
+ end
20
+
21
+ class ItemSearchResponse < Base
22
+ xml_reader :total_results, :as => Integer, :in => 'Items'
23
+ xml_reader :total_pages, :as => Integer, :in => 'Items'
24
+ xml_reader :items, [Item]
25
+ end
26
+ end
27
+
28
+ unless defined?(Spec)
29
+ item = PITA::ItemSearchResponse.from_xml(xml_for('amazon'))
30
+ item.items.each do |i|
31
+ puts i.asin, i.detail_page_url, i.manufacturer, ''
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../spec/spec_helper')
3
+
4
+ class Base
5
+ include ROXML
6
+ xml_convention :dasherize
7
+ xml_namespace 'aws'
8
+ end
9
+
10
+ class WeatherObservation < Base
11
+ xml_name 'ob'
12
+ xml_reader :temperature, :as => Float, :from => 'aws:temp'
13
+ xml_reader :feels_like, :as => Integer
14
+ xml_reader :current_condition #, :attributes => {:icon => String} # pending
15
+ end
16
+
17
+ class Weather < Base
18
+ xml_reader :observation, WeatherObservation, :required => true
19
+ end
20
+
21
+ unless defined?(Spec)
22
+ current_weather = Weather.from_xml(xml_for('current_weather')).observation
23
+ puts "temperature: #{current_weather.temperature}"
24
+ puts "feels_like: #{current_weather.feels_like}"
25
+ puts "current_condition: #{current_weather.current_condition}"
26
+ # puts "current_condition.icon: #{current_weather.current_condition.icon}" # pending
27
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../spec/spec_helper')
3
+
4
+ module GitHub
5
+ class Commit
6
+ include ROXML
7
+ xml_convention :dasherize
8
+
9
+ xml_reader :url
10
+ xml_reader :tree
11
+ xml_reader :message
12
+ xml_reader :id
13
+ xml_reader :committed_date, :as => Date
14
+ end
15
+ end
16
+
17
+ unless defined?(Spec)
18
+ commit = GitHub::Commit.from_xml(xml_for('dashed_elements'))
19
+ puts commit.committed_date, commit.url, commit.id, ''
20
+ end
data/examples/posts.rb ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../spec/spec_helper')
3
+
4
+ class Post
5
+ include ROXML
6
+
7
+ xml_reader :href, :attr
8
+ xml_reader :hash, :attr
9
+ xml_reader :description, :attr
10
+ xml_reader :tag, :attr
11
+ xml_reader :time, :attr, :as => DateTime
12
+ xml_reader :others, :attr, :as => Integer
13
+ xml_reader :extended, :attr
14
+ end
15
+
16
+ class Posts
17
+ include ROXML
18
+
19
+ xml_reader :posts, [Post]
20
+ end
21
+
22
+ unless defined?(Spec)
23
+ posts = Posts.from_xml(xml_for('posts'))
24
+ posts.posts.each do |post|
25
+ puts post.description, post.href, post.extended, ''
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../spec/spec_helper')
3
+ require 'time'
4
+
5
+ class User
6
+ include ROXML
7
+
8
+ xml_reader :id, :as => Integer
9
+ xml_reader :name
10
+ xml_reader :screen_name
11
+ xml_reader :location
12
+ xml_reader :description
13
+ xml_reader :profile_image_url
14
+ xml_reader :url
15
+ xml_reader :protected?
16
+ xml_reader :followers_count, :as => Integer
17
+ end
18
+
19
+ class Status
20
+ include ROXML
21
+
22
+ xml_reader :id, :as => Integer
23
+ xml_reader :text
24
+ xml_reader :created_at, :as => Time
25
+ xml_reader :source
26
+ xml_reader :truncated?
27
+ xml_reader :in_reply_to_status_id, :as => Integer
28
+ xml_reader :in_reply_to_user_id, :as => Integer
29
+ xml_reader :favorited?
30
+ xml_reader :user, User
31
+ end
32
+
33
+ class Statuses
34
+ include ROXML
35
+
36
+ xml_reader :statuses, [Status]
37
+ end
@@ -0,0 +1,133 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05" xmlns:georss="http://www.georss.org/georss">
3
+ <OperationRequest>
4
+ <HTTPHeaders>
5
+ <Header Name="UserAgent">
6
+ </Header>
7
+ </HTTPHeaders>
8
+ <RequestId>16WRJBVEM155Q026KCV1</RequestId>
9
+ <Arguments>
10
+ <Argument Name="SearchIndex" Value="Books"></Argument>
11
+ <Argument Name="Service" Value="AWSECommerceService"></Argument>
12
+ <Argument Name="Title" Value="Ruby on Rails"></Argument>
13
+ <Argument Name="Operation" Value="ItemSearch"></Argument>
14
+ <Argument Name="AWSAccessKeyId" Value="dontbeaswoosh"></Argument>
15
+ </Arguments>
16
+ <RequestProcessingTime>0.064924955368042</RequestProcessingTime>
17
+ </OperationRequest>
18
+ <Items>
19
+ <Request>
20
+ <IsValid>True</IsValid>
21
+ <ItemSearchRequest>
22
+ <SearchIndex>Books</SearchIndex>
23
+ <Title>Ruby on Rails</Title>
24
+ </ItemSearchRequest>
25
+ </Request>
26
+ <TotalResults>22</TotalResults>
27
+ <TotalPages>3</TotalPages>
28
+ <Item>
29
+ <ASIN>0321480791</ASIN>
30
+ <georss:point>38.5351715088 -121.7948684692</georss:point>
31
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=0321480791%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321480791%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
32
+ <ItemAttributes>
33
+ <Author>Michael Hartl</Author>
34
+ <Author>Aurelius Prochazka</Author>
35
+ <Manufacturer>Addison-Wesley Professional</Manufacturer>
36
+ <ProductGroup>Book</ProductGroup>
37
+ <Title>RailsSpace: Building a Social Networking Website with Ruby on Rails (Addison-Wesley Professional Ruby Series)</Title>
38
+ </ItemAttributes>
39
+ </Item>
40
+ <Item>
41
+ <ASIN>047022388X</ASIN>
42
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=047022388X%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/047022388X%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
43
+ <ItemAttributes>
44
+ <Author>Noel Rappin</Author>
45
+ <Manufacturer>Wrox</Manufacturer>
46
+ <ProductGroup>Book</ProductGroup>
47
+ <Title>Professional Ruby on Rails</Title>
48
+ </ItemAttributes>
49
+ </Item>
50
+ <Item>
51
+ <ASIN>1590598814</ASIN>
52
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=1590598814%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/1590598814%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
53
+ <ItemAttributes>
54
+ <Author>Ola Bini</Author>
55
+ <Manufacturer>Apress</Manufacturer>
56
+ <ProductGroup>Book</ProductGroup>
57
+ <Title>Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java</Title>
58
+ </ItemAttributes>
59
+ </Item>
60
+ <Item>
61
+ <ASIN>0596101325</ASIN>
62
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=0596101325%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596101325%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
63
+ <ItemAttributes>
64
+ <Author>Bruce Tate</Author>
65
+ <Author>Curt Hibbs</Author>
66
+ <Manufacturer>O'Reilly Media, Inc.</Manufacturer>
67
+ <ProductGroup>Book</ProductGroup>
68
+ <Title>Ruby on Rails: Up and Running</Title>
69
+ </ItemAttributes>
70
+ </Item>
71
+ <Item>
72
+ <ASIN>0470081201</ASIN>
73
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=0470081201%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0470081201%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
74
+ <ItemAttributes>
75
+ <Author>Barry Burd</Author>
76
+ <Manufacturer>For Dummies</Manufacturer>
77
+ <ProductGroup>Book</ProductGroup>
78
+ <Title>Ruby on Rails For Dummies (For Dummies (Computer/Tech))</Title>
79
+ </ItemAttributes>
80
+ </Item>
81
+ <Item>
82
+ <ASIN>0975841955</ASIN>
83
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=0975841955%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0975841955%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
84
+ <ItemAttributes>
85
+ <Author>Patrick Lenz</Author>
86
+ <Manufacturer>SitePoint</Manufacturer>
87
+ <ProductGroup>Book</ProductGroup>
88
+ <Title>Build Your Own Ruby on Rails Web Applications</Title>
89
+ </ItemAttributes>
90
+ </Item>
91
+ <Item>
92
+ <ASIN>0470069155</ASIN>
93
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=0470069155%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0470069155%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
94
+ <ItemAttributes>
95
+ <Author>Steve, Ph.D. Holzner</Author>
96
+ <Manufacturer>Wrox</Manufacturer>
97
+ <ProductGroup>Book</ProductGroup>
98
+ <Title>Beginning Ruby on Rails (Wrox Beginning Guides)</Title>
99
+ </ItemAttributes>
100
+ </Item>
101
+ <Item>
102
+ <ASIN>1590597362</ASIN>
103
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=1590597362%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/1590597362%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
104
+ <ItemAttributes>
105
+ <Author>Christian Hellsten</Author>
106
+ <Author>Jarkko Laine</Author>
107
+ <Manufacturer>Apress</Manufacturer>
108
+ <ProductGroup>Book</ProductGroup>
109
+ <Title>Beginning Ruby on Rails E-Commerce: From Novice to Professional (Rails)</Title>
110
+ </ItemAttributes>
111
+ </Item>
112
+ <Item>
113
+ <ASIN>1590597524</ASIN>
114
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=1590597524%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/1590597524%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
115
+ <ItemAttributes>
116
+ <Author>Justin Williams</Author>
117
+ <Manufacturer>friends of ED</Manufacturer>
118
+ <ProductGroup>Book</ProductGroup>
119
+ <Title>Rails Solutions: Ruby on Rails Made Easy (Solutions)</Title>
120
+ </ItemAttributes>
121
+ </Item>
122
+ <Item>
123
+ <ASIN>0321517067</ASIN>
124
+ <DetailPageURL>http://www.amazon.com/gp/redirect.html%3FASIN=0321517067%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0321517067%253FSubscriptionId=dontbeaswoosh</DetailPageURL>
125
+ <ItemAttributes>
126
+ <Author>Aurelius Prochazka</Author>
127
+ <Manufacturer>Addison-Wesley Professional</Manufacturer>
128
+ <ProductGroup>Book</ProductGroup>
129
+ <Title>RailsSpace Ruby on Rails Tutorial (Video Training) (LiveLessons)</Title>
130
+ </ItemAttributes>
131
+ </Item>
132
+ </Items>
133
+ </ItemSearchResponse>