muffins 0.0.5 → 0.0.6
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/.rvmrc +1 -0
- data/README.md +15 -22
- data/Rakefile +1 -1
- data/lib/muffins.rb +13 -35
- data/lib/muffins/class_methods.rb +60 -0
- data/lib/muffins/document.rb +38 -0
- data/lib/muffins/mapping.rb +24 -59
- data/lib/muffins/mapping_parent.rb +27 -0
- data/lib/muffins/version.rb +1 -1
- data/muffins.gemspec +15 -17
- data/spec/fixtures/books.html +23 -0
- data/spec/fixtures/books.xml +11 -0
- data/spec/muffins/document_spec.rb +46 -0
- data/spec/muffins/mapping_parent_spec.rb +33 -0
- data/spec/muffins/mapping_spec.rb +29 -266
- data/spec/muffins_spec.rb +43 -103
- data/spec/spec_helper.rb +1 -4
- metadata +30 -59
- data/features/basic_parsing.feature +0 -33
- data/features/nested_parsing.feature +0 -37
- data/features/non_primitive_typing.feature +0 -36
- data/features/specified_pathnames.feature +0 -33
- data/features/specified_typing.feature +0 -33
- data/features/step_definitions/application_steps.rb +0 -52
- data/features/support/env.rb +0 -16
- data/lib/muffins/mapping_decorator.rb +0 -22
- data/spec/muffins/mapping_decorator_spec.rb +0 -46
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
require 'rspec'
|
4
|
-
require 'nokogiri'
|
5
|
-
require 'activesupport'
|
6
|
-
|
7
|
-
require File.expand_path('../../lib/muffins', __FILE__)
|
8
4
|
|
9
5
|
def fixture_file(filename)
|
10
6
|
File.read(File.dirname(__FILE__) + "/fixtures/#{filename}")
|
11
7
|
end
|
12
8
|
|
9
|
+
require File.expand_path('../../lib/muffins', __FILE__)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muffins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,93 +9,68 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-11-12 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: activesupport
|
17
|
-
requirement: &23551300 !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.3.10
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: *23551300
|
26
14
|
- !ruby/object:Gem::Dependency
|
27
15
|
name: nokogiri
|
28
|
-
requirement: &
|
16
|
+
requirement: &70280505680060 !ruby/object:Gem::Requirement
|
29
17
|
none: false
|
30
18
|
requirements:
|
31
19
|
- - ~>
|
32
20
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
21
|
+
version: 1.5.0
|
34
22
|
type: :runtime
|
35
23
|
prerelease: false
|
36
|
-
version_requirements: *
|
24
|
+
version_requirements: *70280505680060
|
37
25
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement: &
|
26
|
+
name: virtus
|
27
|
+
requirement: &70280505679580 !ruby/object:Gem::Requirement
|
40
28
|
none: false
|
41
29
|
requirements:
|
42
30
|
- - ~>
|
43
31
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
45
|
-
type: :
|
46
|
-
prerelease: false
|
47
|
-
version_requirements: *23550180
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: cucumber
|
50
|
-
requirement: &23549740 !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
|
-
requirements:
|
53
|
-
- - ~>
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0.10'
|
56
|
-
type: :development
|
32
|
+
version: 0.0.9
|
33
|
+
type: :runtime
|
57
34
|
prerelease: false
|
58
|
-
version_requirements: *
|
35
|
+
version_requirements: *70280505679580
|
59
36
|
- !ruby/object:Gem::Dependency
|
60
37
|
name: rspec
|
61
|
-
requirement: &
|
38
|
+
requirement: &70280505679060 !ruby/object:Gem::Requirement
|
62
39
|
none: false
|
63
40
|
requirements:
|
64
41
|
- - ~>
|
65
42
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
43
|
+
version: 2.7.0
|
67
44
|
type: :development
|
68
45
|
prerelease: false
|
69
|
-
version_requirements: *
|
70
|
-
description: An Object to XML/HTML mapping library using Nokogiri
|
46
|
+
version_requirements: *70280505679060
|
47
|
+
description: An Object to XML/HTML mapping library using Virtus and Nokogiri
|
71
48
|
email:
|
72
|
-
- ryan
|
49
|
+
- ryan@ryanclosner.com
|
73
50
|
executables: []
|
74
51
|
extensions: []
|
75
52
|
extra_rdoc_files: []
|
76
53
|
files:
|
77
54
|
- .gitignore
|
55
|
+
- .rvmrc
|
78
56
|
- Gemfile
|
79
57
|
- README.md
|
80
58
|
- Rakefile
|
81
|
-
- features/basic_parsing.feature
|
82
|
-
- features/nested_parsing.feature
|
83
|
-
- features/non_primitive_typing.feature
|
84
|
-
- features/specified_pathnames.feature
|
85
|
-
- features/specified_typing.feature
|
86
|
-
- features/step_definitions/application_steps.rb
|
87
|
-
- features/support/env.rb
|
88
59
|
- lib/muffins.rb
|
60
|
+
- lib/muffins/class_methods.rb
|
61
|
+
- lib/muffins/document.rb
|
89
62
|
- lib/muffins/mapping.rb
|
90
|
-
- lib/muffins/
|
63
|
+
- lib/muffins/mapping_parent.rb
|
91
64
|
- lib/muffins/version.rb
|
92
65
|
- muffins.gemspec
|
93
|
-
- spec/
|
66
|
+
- spec/fixtures/books.html
|
67
|
+
- spec/fixtures/books.xml
|
68
|
+
- spec/muffins/document_spec.rb
|
69
|
+
- spec/muffins/mapping_parent_spec.rb
|
94
70
|
- spec/muffins/mapping_spec.rb
|
95
71
|
- spec/muffins_spec.rb
|
96
72
|
- spec/spec_helper.rb
|
97
|
-
|
98
|
-
homepage: https://rubygems.org/gems/muffins
|
73
|
+
homepage: http://rubygems.org/gems/muffins
|
99
74
|
licenses: []
|
100
75
|
post_install_message:
|
101
76
|
rdoc_options: []
|
@@ -115,19 +90,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
90
|
version: '0'
|
116
91
|
requirements: []
|
117
92
|
rubyforge_project: muffins
|
118
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.8.10
|
119
94
|
signing_key:
|
120
95
|
specification_version: 3
|
121
|
-
summary: An Object to XML/HTML mapping library
|
96
|
+
summary: An Object to XML/HTML mapping library.
|
122
97
|
test_files:
|
123
|
-
-
|
124
|
-
-
|
125
|
-
-
|
126
|
-
-
|
127
|
-
- features/specified_typing.feature
|
128
|
-
- features/step_definitions/application_steps.rb
|
129
|
-
- features/support/env.rb
|
130
|
-
- spec/muffins/mapping_decorator_spec.rb
|
98
|
+
- spec/fixtures/books.html
|
99
|
+
- spec/fixtures/books.xml
|
100
|
+
- spec/muffins/document_spec.rb
|
101
|
+
- spec/muffins/mapping_parent_spec.rb
|
131
102
|
- spec/muffins/mapping_spec.rb
|
132
103
|
- spec/muffins_spec.rb
|
133
104
|
- spec/spec_helper.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
Feature: Basic Parsing
|
2
|
-
As an XML mapping library
|
3
|
-
I'd like to be awesome at mapping
|
4
|
-
So I can get hella downloads
|
5
|
-
|
6
|
-
Background:
|
7
|
-
Given the following xml:
|
8
|
-
"""
|
9
|
-
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
10
|
-
<books>
|
11
|
-
<book>
|
12
|
-
<asin>1400079985</asin>
|
13
|
-
<title>War and Peace (Vintage Classics)</title>
|
14
|
-
</book>
|
15
|
-
<book>
|
16
|
-
<asin>1143035008</asin>
|
17
|
-
<title>Anna Karenina (Oprah's Book Club)</title>
|
18
|
-
</book>
|
19
|
-
</books>
|
20
|
-
"""
|
21
|
-
|
22
|
-
Scenario: I parse the xml
|
23
|
-
Given that base_path has been set to 'book'
|
24
|
-
And the following mappings have been defined:
|
25
|
-
| name |
|
26
|
-
| asin |
|
27
|
-
| title |
|
28
|
-
When I parse the xml
|
29
|
-
Then I should have 2 books
|
30
|
-
And the following values should be returned:
|
31
|
-
| asin | title |
|
32
|
-
| 1400079985 | War and Peace (Vintage Classics) |
|
33
|
-
| 1143035008 | Anna Karenina (Oprah's Book Club) |
|
@@ -1,37 +0,0 @@
|
|
1
|
-
Feature: Nested Parsing
|
2
|
-
As an XML mapping library
|
3
|
-
I'd like to be awesome at mapping
|
4
|
-
So I can get hella downloads
|
5
|
-
|
6
|
-
Background:
|
7
|
-
Given the following xml:
|
8
|
-
"""
|
9
|
-
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
10
|
-
<books>
|
11
|
-
<book>
|
12
|
-
<asin>1400079985</asin>
|
13
|
-
<itemattributes>
|
14
|
-
<title>War and Peace (Vintage Classics)</title>
|
15
|
-
</itemattributes>
|
16
|
-
</book>
|
17
|
-
<book>
|
18
|
-
<asin>1143035008</asin>
|
19
|
-
<itemattributes>
|
20
|
-
<title>Anna Karenina (Oprah's Book Club)</title>
|
21
|
-
</itemattributes>
|
22
|
-
</book>
|
23
|
-
</books>
|
24
|
-
"""
|
25
|
-
Scenario: I parse the xml
|
26
|
-
Given that base_path has been set to 'book'
|
27
|
-
And the following mappings have been defined:
|
28
|
-
| name | within |
|
29
|
-
| asin | |
|
30
|
-
| title | itemattributes |
|
31
|
-
When I parse the xml
|
32
|
-
Then I should have 2 books
|
33
|
-
And the following values should be returned:
|
34
|
-
| asin | title |
|
35
|
-
| 1400079985 | War and Peace (Vintage Classics) |
|
36
|
-
| 1143035008 | Anna Karenina (Oprah's Book Club) |
|
37
|
-
|
@@ -1,36 +0,0 @@
|
|
1
|
-
Feature: Non-Primitive Typing
|
2
|
-
As an XML mapping library
|
3
|
-
I'd like to be awesome at mapping
|
4
|
-
So I can get hella downloads
|
5
|
-
|
6
|
-
Background:
|
7
|
-
Given the following xml:
|
8
|
-
"""
|
9
|
-
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
10
|
-
<books>
|
11
|
-
<book>
|
12
|
-
<asin>1400079985</asin>
|
13
|
-
<title>War and Peace (Vintage Classics)</title>
|
14
|
-
<similarproducts>
|
15
|
-
<product>
|
16
|
-
<asin>1143035008</asin>
|
17
|
-
<title>Anna Karenina (Oprah's Book Club)</title>
|
18
|
-
</product>
|
19
|
-
</similarproducts>
|
20
|
-
</book>
|
21
|
-
</books>
|
22
|
-
"""
|
23
|
-
|
24
|
-
Scenario: I parse the xml
|
25
|
-
Given that base_path has been set to 'book'
|
26
|
-
And the following mappings have been defined:
|
27
|
-
| name | type |
|
28
|
-
| asin | |
|
29
|
-
| title | |
|
30
|
-
| similarproducts | Product |
|
31
|
-
When I parse the xml
|
32
|
-
Then I should have 1 books
|
33
|
-
And the following values should be returned:
|
34
|
-
| asin | title |
|
35
|
-
| 1400079985 | War and Peace (Vintage Classics) |
|
36
|
-
And 'similarproducts' should return 1 instances of Product
|
@@ -1,33 +0,0 @@
|
|
1
|
-
Feature: Specified Pathnames
|
2
|
-
As an XML mapping library
|
3
|
-
I'd like to be awesome at mapping
|
4
|
-
So I can get hella downloads
|
5
|
-
|
6
|
-
Background:
|
7
|
-
Given the following xml:
|
8
|
-
"""
|
9
|
-
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
10
|
-
<BOOKS>
|
11
|
-
<BOOK>
|
12
|
-
<ASIN>1400079985</ASIN>
|
13
|
-
<TITLE>War and Peace (Vintage Classics)</TITLE>
|
14
|
-
</BOOK>
|
15
|
-
<BOOK>
|
16
|
-
<ASIN>1143035008</ASIN>
|
17
|
-
<TITLE>Anna Karenina (Oprah's Book Club)</TITLE>
|
18
|
-
</BOOK>
|
19
|
-
</BOOKS>
|
20
|
-
"""
|
21
|
-
Scenario: I parse the xml
|
22
|
-
Given that base_path has been set to 'BOOK'
|
23
|
-
And the following mappings have been defined:
|
24
|
-
| name | to |
|
25
|
-
| asin | ASIN |
|
26
|
-
| title | TITLE |
|
27
|
-
When I parse the xml
|
28
|
-
Then I should have 2 books
|
29
|
-
And the following values should be returned:
|
30
|
-
| asin | title |
|
31
|
-
| 1400079985 | War and Peace (Vintage Classics) |
|
32
|
-
| 1143035008 | Anna Karenina (Oprah's Book Club) |
|
33
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
Feature: Specified Typing
|
2
|
-
As an XML mapping library
|
3
|
-
I'd like to be awesome at mapping
|
4
|
-
So I can get hella downloads
|
5
|
-
|
6
|
-
Background:
|
7
|
-
Given the following xml:
|
8
|
-
"""
|
9
|
-
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
10
|
-
<books>
|
11
|
-
<book>
|
12
|
-
<asin>1400079985</asin>
|
13
|
-
<title>War and Peace (Vintage Classics)</title>
|
14
|
-
</book>
|
15
|
-
<book>
|
16
|
-
<asin>1143035008</asin>
|
17
|
-
<title>Anna Karenina (Oprah's Book Club)</title>
|
18
|
-
</book>
|
19
|
-
</books>
|
20
|
-
"""
|
21
|
-
Scenario: I parse the xml
|
22
|
-
Given that base_path has been set to 'book'
|
23
|
-
And the following mappings have been defined:
|
24
|
-
| name | type |
|
25
|
-
| asin | Integer |
|
26
|
-
| title | String |
|
27
|
-
When I parse the xml
|
28
|
-
Then I should have 2 books
|
29
|
-
And the following data types should be returned:
|
30
|
-
| asin | title |
|
31
|
-
| Integer | String |
|
32
|
-
| Integer | String |
|
33
|
-
|
@@ -1,52 +0,0 @@
|
|
1
|
-
Given /^the following xml:$/ do |doc|
|
2
|
-
@xml = Nokogiri::XML(doc)
|
3
|
-
end
|
4
|
-
|
5
|
-
Given /^that base_path has been set to '(.*?)'$/ do |base_path|
|
6
|
-
Book.base_path base_path
|
7
|
-
end
|
8
|
-
|
9
|
-
Given /^the following mappings have been defined:$/ do |table|
|
10
|
-
table.hashes.each do |options|
|
11
|
-
name = options.delete('name')
|
12
|
-
Book.map name, options
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
When /^I parse the xml$/ do
|
18
|
-
@books = Book.parse(@xml)
|
19
|
-
end
|
20
|
-
|
21
|
-
Then /^I should have (\d+) books$/ do |count|
|
22
|
-
@books.count.should == count.to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
Then /^the following values should be returned:$/ do |table|
|
26
|
-
@books.count.times do |count|
|
27
|
-
book = @books[count]
|
28
|
-
|
29
|
-
table.hashes[count].each_pair do |key, value|
|
30
|
-
book.send(key).should == value
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
Then /^the following data types should be returned:$/ do |table|
|
36
|
-
@books.count.times do |count|
|
37
|
-
book = @books[count]
|
38
|
-
|
39
|
-
table.hashes[count].each_pair do |key, value|
|
40
|
-
type = value.constantize
|
41
|
-
book.send(key).should be_a(type)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
Then /^'(.*?)' should return (\d+) instances of (.*?)$/ do |method, count, type|
|
47
|
-
@books.each do |book|
|
48
|
-
products = book.send(method)
|
49
|
-
products.count.should == count.to_i
|
50
|
-
products.each {|p| p.should be_a(type.constantize) }
|
51
|
-
end
|
52
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module Muffins
|
2
|
-
class MappingDecorator
|
3
|
-
|
4
|
-
attr_reader :base_path, :object
|
5
|
-
|
6
|
-
def initialize(base_path, object)
|
7
|
-
@base_path = base_path
|
8
|
-
@object = object
|
9
|
-
end
|
10
|
-
|
11
|
-
def map(name, options = {})
|
12
|
-
options[:within] =
|
13
|
-
if options[:within]
|
14
|
-
"#{base_path} > #{options[:within]}"
|
15
|
-
else
|
16
|
-
base_path
|
17
|
-
end
|
18
|
-
|
19
|
-
object.map(name, options)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Muffins
|
4
|
-
describe MappingDecorator do
|
5
|
-
|
6
|
-
let(:object) do
|
7
|
-
class Book
|
8
|
-
include Muffins
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:base_path) { 'foo' }
|
13
|
-
let(:name) { 'bar' }
|
14
|
-
|
15
|
-
let(:decorator_options) { {} }
|
16
|
-
|
17
|
-
let(:nested_path) { 'foobar' }
|
18
|
-
|
19
|
-
subject { MappingDecorator.new(base_path, object) }
|
20
|
-
|
21
|
-
describe "#map" do
|
22
|
-
context "options[:within] is nil" do
|
23
|
-
|
24
|
-
let(:mapping_options) { {:within => base_path } }
|
25
|
-
|
26
|
-
it "sets options[:within] to the base_path" do
|
27
|
-
object.should_receive(:map).with(name, mapping_options)
|
28
|
-
subject.map(name, decorator_options)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "options[:within] is not nil" do
|
33
|
-
|
34
|
-
let(:mapping_options) { {:within => "#{base_path} > #{nested_path}"} }
|
35
|
-
|
36
|
-
let(:decorator_options) { {:within => nested_path} }
|
37
|
-
|
38
|
-
|
39
|
-
it "sets options[:within] to the 'base_path > nested_path'" do
|
40
|
-
object.should_receive(:map).with(name, mapping_options)
|
41
|
-
subject.map(name, decorator_options)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|