document_builder 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDY1MjliOTFlMDFiNjVjOTdlMDBkOGU4NDBhYTEzM2IyMDRmNWViOA==
4
+ NDQ1MmRhN2FkMzIwNGEyZTcwYjk3OWE4YjRlMDc5NzBiNmM3M2ZkOA==
5
5
  data.tar.gz: !binary |-
6
- ZDM3ZWE4Y2ZkNjU1NzI2MTJlMzFhYzZjYTkzYWRiMTUwYzNiYjdhNQ==
6
+ ODk4OWExNDgwN2ZkYWE3ZDFlZTlmZjliNzZlOWNkMmE0Y2YzMTA3NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTc0NDAzOWZmYWM0NGFiNmIxYjdmNjdlNjBlOGI5NTU2YTkxNDllNTI0NWVk
10
- Y2MwMjliOTMxMDcwODE1ZWZhNWRhMzNkY2E4ODkxYjRjMzYxODBhMjdiY2Q1
11
- ODEzNWU0OGU2ZDU4OWM1NDJmNmUzNTIyMGRkOTg3Mjk2YjRlMDE=
9
+ YzVkYWE3NzA1MjBlN2FlMDRkOTBmODIwYjdhZjE2MWNhMDNlMjZjYzlhZTU2
10
+ ZGNkZjcwOWQ4NDYxYTViNTQ0Y2VhZDIyZTEwYjNkOTI4NGRlYTgyMDlhYjBl
11
+ MjY2MDJhYzE4ZGNlZWZhNjIyOTE3NDljNWMyZjdkZDM5NTJhOWY=
12
12
  data.tar.gz: !binary |-
13
- ZjY5MDM2Y2M1MzU2YmIxNjlkYmFhMTZmMTc1MTM1MDFhZTQ1NWY4ODVjNWMy
14
- Nzc5NTc2ZTM5ODFjZGY3MGY1ZGEzYjRmNTJhZmY5YmZlZDRhOTAyZGMwYzgx
15
- ODY1MTUyYjdlZTlkNDAzNmNiYzRmNTc3ZDA0ZTY5MTc3YjYxYmY=
13
+ N2M0NDk3M2I0ZmU4MThlNmNkODQ2OTAzNzdhZDBjMWE4NGFlMTg3MTJiOWM3
14
+ MzAwOWUzZTg4Y2MzYWY1ZTlhMDEyODc5MWQ2ZDlhMmI1ZDVkZGNjYzRlNDdl
15
+ MTNhNTEyOWJkNjUyZjY3YTRhMmQ1MTc3MjljY2U4ODNiZjA3NjI=
@@ -1,9 +1,12 @@
1
1
  module DocumentBuilder
2
2
  module Model
3
3
  module ClassMethods
4
- def add_attribute(name, attribute)
4
+ def attributes
5
5
  @attributes ||= {}
6
- @attributes[name.to_sym] = attribute
6
+ end
7
+
8
+ def add_attribute(name, attribute)
9
+ attributes[name.to_sym] = attribute
7
10
  end
8
11
 
9
12
  def property(name, selector: nil, type: nil)
@@ -22,12 +25,6 @@ module DocumentBuilder
22
25
  @root = selector
23
26
  end
24
27
 
25
- def inherited(subclass)
26
- subclass.instance_variable_set(:@attributes, @attributes)
27
- subclass.instance_variable_set(:@root, @root)
28
- super
29
- end
30
-
31
28
  def call(document)
32
29
  self.new(document)
33
30
  end
@@ -57,7 +54,7 @@ module DocumentBuilder
57
54
  end
58
55
 
59
56
  def attributes
60
- self.class.instance_variable_get(:@attributes)
57
+ self.class.attributes
61
58
  end
62
59
 
63
60
  def get_attribute(name)
@@ -1,3 +1,3 @@
1
1
  module DocumentBuilder
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -2,19 +2,9 @@ require 'spec_helper'
2
2
  require 'nokogiri'
3
3
 
4
4
  RSpec.describe DocumentBuilder::Model do
5
- DOCUMENT = <<-XML
6
- <root>
7
- <collection>
8
- <inner-list-item>Inner Item 1</inner-list-item>
9
- <inner-list-item>Inner Item 2</inner-list-item>
10
- </collection>
11
- <outer-list-item>Outer Item 1</outer-list-item>
12
- <outer-list-item>Outer Item 2</outer-list-item>
13
- <property>Some Property</property>
14
- </root>
15
- XML
16
-
17
- let(:document) { Nokogiri::XML(DOCUMENT) }
5
+ class EmptyDocument
6
+ include DocumentBuilder::Model
7
+ end
18
8
 
19
9
  class ListItem
20
10
  include DocumentBuilder::Model
@@ -29,25 +19,57 @@ RSpec.describe DocumentBuilder::Model do
29
19
  property :property, selector: "//property", type: TextProperty
30
20
  end
31
21
 
32
- subject { SomeDocument.new(document) }
22
+ context 'for an xml document' do
23
+ let(:xml) {
24
+ <<-XML
25
+ <root>
26
+ <collection>
27
+ <inner-list-item>Inner Item 1</inner-list-item>
28
+ <inner-list-item>Inner Item 2</inner-list-item>
29
+ </collection>
30
+ <outer-list-item>Outer Item 1</outer-list-item>
31
+ <outer-list-item>Outer Item 2</outer-list-item>
32
+ <property>Some Property</property>
33
+ </root>
34
+ XML
35
+ }
33
36
 
34
- it 'returns the root' do
35
- expect(subject.root).to eq "//root"
36
- end
37
+ let(:document) { Nokogiri::XML(xml) }
37
38
 
38
- it 'returns an innner collection' do
39
- expect(subject.collection).to be_a DocumentBuilder::Collection
40
- expect(subject.collection.first).to be_a ListItem
41
- expect(subject.collection.first.name).to eq "Inner Item 1"
42
- end
39
+ subject { SomeDocument.new(document) }
40
+
41
+ it 'returns the root' do
42
+ expect(subject.root).to eq "//root"
43
+ end
43
44
 
44
- it 'returns an outer collection' do
45
- expect(subject.outer_collection).to be_a DocumentBuilder::Collection
46
- expect(subject.outer_collection.first).to be_a ListItem
47
- expect(subject.outer_collection.first.name).to eq "Outer Item 1"
45
+ it 'returns an innner collection' do
46
+ expect(subject.collection).to be_a DocumentBuilder::Collection
47
+ expect(subject.collection.first).to be_a ListItem
48
+ expect(subject.collection.first.name).to eq "Inner Item 1"
49
+ end
50
+
51
+ it 'returns an outer collection' do
52
+ expect(subject.outer_collection).to be_a DocumentBuilder::Collection
53
+ expect(subject.outer_collection.first).to be_a ListItem
54
+ expect(subject.outer_collection.first.name).to eq "Outer Item 1"
55
+ end
56
+
57
+ it 'returns a property' do
58
+ expect(subject.property).to eq "Some Property"
59
+ end
48
60
  end
49
61
 
50
- it 'returns a property' do
51
- expect(subject.property).to eq "Some Property"
62
+
63
+ context 'for an empty document' do
64
+ let(:document) { Nokogiri::XML("") }
65
+ subject { EmptyDocument.new(document) }
66
+
67
+ it 'returns an empty document' do
68
+ expect(subject).to be_a EmptyDocument
69
+ end
70
+
71
+ it 'is serialized' do
72
+ expect(subject.to_s).to be_a String
73
+ end
52
74
  end
53
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: document_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Schmitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport