Class: XMLable::Handlers::Element

Inherits:
Base
  • Object
show all
Includes:
Mixins::Described, Mixins::Namespace, Mixins::Tag
Defined in:
lib/xmlable/handlers/element.rb

Direct Known Subclasses

Elements

Instance Attribute Summary

Attributes inherited from Base

#block, #type

Instance Method Summary collapse

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.

See Also:

  • XMLable::Handler::Base#initialize


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

Returns:

  • (#each)


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_proxyClass

Proxy class for elements objects

Returns:

  • (Class)


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

Parameters:

  • element (Nokogiri::XML::Element)

Returns:



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

See Also:

  • XMLable::Handler::Base#inject_wraped


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

#proxyObject

See Also:

  • XMLable::Handler::Base#proxy


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?

Returns:

  • (Boolean)


73
74
75
# File 'lib/xmlable/handlers/element.rb', line 73

def single?
  true
end