Class: XMLable::Handlers::Element
- Includes:
- Mixins::Described, Mixins::Namespace, Mixins::Tag
- Defined in:
- lib/xmlable/handlers/element.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#container_for_xml_element(parent) ⇒ #each
Create elements container for XML element.
-
#container_proxy ⇒ Class
Proxy class for elements objects.
-
#from_xml_element(element) ⇒ XMLable::Mixins::Object
Create element object from the XML element.
-
#initialize(name, opts = {}, &block) ⇒ Element
constructor
A new instance of Element.
- #inject_wraped(klass) ⇒ Object
- #proxy ⇒ Object
-
#single? ⇒ Boolean
Is this handler for multiple elements objects or not?.
Methods inherited from Base
#block_settings?, build, #method_name, #options, #options?, #type_class, #wrapped_type?
Constructor Details
#initialize(name, opts = {}, &block) ⇒ Element
Returns a new instance of Element.
11 12 13 14 |
# File 'lib/xmlable/handlers/element.rb', line 11 def initialize(name, opts = {}, &block) @container_type = opts.delete(:container) || Array super(name, opts, &block) end |
Instance Method Details
#container_for_xml_element(parent) ⇒ #each
Create elements container for XML element
32 33 34 35 36 37 |
# File 'lib/xmlable/handlers/element.rb', line 32 def container_for_xml_element(parent) container_proxy.new.tap do |c| c.__set_parent_node(parent) c.__set_handler(self) end end |
#container_proxy ⇒ Class
Proxy class for elements objects
21 22 23 |
# File 'lib/xmlable/handlers/element.rb', line 21 def container_proxy @container_proxy ||= Builder.container_proxy_for(@container_type) end |
#from_xml_element(element) ⇒ XMLable::Mixins::Object
Create element object from the XML element
84 85 86 |
# File 'lib/xmlable/handlers/element.rb', line 84 def from_xml_element(element) Builder.build_element(element, self) end |
#inject_wraped(klass) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/xmlable/handlers/element.rb', line 42 def inject_wraped(klass) klass.class_eval do include XMLable::Mixins::ContentStorage include XMLable::Mixins::AttributesStorage include XMLable::Mixins::ElementsStorage include XMLable::Mixins::NamespaceDefinitionsStorage include XMLable::Mixins::BareValue include XMLable::Mixins::Instantiable end klass end |
#proxy ⇒ Object
57 58 59 60 61 62 |
# File 'lib/xmlable/handlers/element.rb', line 57 def proxy @proxy ||= type_class.tap do |p| p.__default_namespace = namespace_prefix p.class_eval(&@block) if block_settings? end end |
#single? ⇒ Boolean
Is this handler for multiple elements objects or not?
73 74 75 |
# File 'lib/xmlable/handlers/element.rb', line 73 def single? true end |