saxaphone 0.5.1 → 0.5.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.
@@ -26,6 +26,7 @@ module Saxaphone
26
26
  def end_element(name)
27
27
  ending_element = element_stack.pop
28
28
  if element_stack.empty?
29
+ p "root"
29
30
  self.root_element = ending_element
30
31
  else
31
32
  element_stack.last.add_element(ending_element)
@@ -7,7 +7,18 @@ module Saxaphone
7
7
  class ElementHandler < Struct.new(:class_name, :proc)
8
8
  end
9
9
 
10
+ @element_handlers = {}
11
+ @stored_attributes = Set.new
12
+
10
13
  class << self
14
+ attr_accessor :element_handlers
15
+ attr_accessor :stored_attributes
16
+
17
+ def inherited(base)
18
+ base.element_handlers = element_handlers.dup
19
+ base.stored_attributes = stored_attributes.dup
20
+ end
21
+
11
22
  # A block can be passed to <tt>setup</tt>,
12
23
  # which is called after the element is initialized.
13
24
  #
@@ -144,25 +155,16 @@ module Saxaphone
144
155
  # Notice that the "price" attribute is not stored.
145
156
  #
146
157
  def store_attributes(*attribute_names)
147
- @stored_attributes = attribute_names.flatten.to_set
158
+ self.stored_attributes += attribute_names.flatten.to_set
148
159
  end
149
160
 
150
161
  def handler_for(element_name)
151
162
  element_handlers[element_name] || element_handlers['*']
152
163
  end
153
164
 
154
- def stored_attributes
155
- @stored_attributes ||= Set.new
156
- end
157
-
158
165
  def parse(xml)
159
166
  Saxaphone::Document.parse(xml, self)
160
167
  end
161
-
162
- private
163
- def element_handlers
164
- @element_handlers ||= {}
165
- end
166
168
  end
167
169
 
168
170
  attr_accessor :name, :content, :attributes
data/test/element_test.rb CHANGED
@@ -121,7 +121,25 @@ class Saxaphone::ElementTest < MiniTest::Spec
121
121
  element.add_element(child_element)
122
122
  # silence?
123
123
  end
124
-
124
+
125
+ def test_attributes_inherited
126
+ parent = Class.new(Saxaphone::Element) do
127
+ has_element 'foo'
128
+ store_attributes 'faz'
129
+ end
130
+
131
+ child = Class.new(parent) do
132
+ has_element 'bar'
133
+ store_attributes 'baz'
134
+ end
135
+
136
+ assert_equal ['foo'].to_set, parent.element_handlers.keys.to_set
137
+ assert_equal ['faz'].to_set, parent.stored_attributes
138
+
139
+ assert_equal ['foo', 'bar'].to_set, child.element_handlers.keys.to_set
140
+ assert_equal ['faz', 'baz'].to_set, child.stored_attributes
141
+ end
142
+
125
143
  private
126
144
  def define_element(&block)
127
145
  Class.new(Saxaphone::Element, &block).new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxaphone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-21 00:00:00.000000000 Z
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70243549160060 !ruby/object:Gem::Requirement
16
+ requirement: &70257440543260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70243549160060
24
+ version_requirements: *70257440543260
25
25
  description: Use objects
26
26
  email: developer@matthewhiggins.com
27
27
  executables: []