module XMLable::Mixins::RootStorage
RootStorage
module contains the logic to manage with XML root element
Public Class Methods
included(base)
click to toggle source
# File lib/xmlable/mixins/root_storage.rb, line 7 def self.included(base) base.send(:extend, ClassMethods) end
Public Instance Methods
[](key)
click to toggle source
Get root object by key
@param [String] key
# File lib/xmlable/mixins/root_storage.rb, line 103 def [](key) root if key?(key) end
[]=(key, val)
click to toggle source
Set root object value
@param [String] key @param [Object] val
# File lib/xmlable/mixins/root_storage.rb, line 113 def []=(key, val) self.root = val if key?(key) end
__empty?()
click to toggle source
Is the current object empty?
@return [Boolean]
Calls superclass method
# File lib/xmlable/mixins/root_storage.rb, line 41 def __empty? return false unless super __empty(root) end
__root_handler()
click to toggle source
Cureent root object's handler
@return [XMLable::Handlers::Root, XMLable::Handlers::RootNone]
# File lib/xmlable/mixins/root_storage.rb, line 122 def __root_handler self.class.__root_handler end
__root_object_initialize(h, value)
click to toggle source
Initialize root object with params
@param [XMLable::Handlers::Root, XMLable::Handlers::RootNone] h root's handler @param [Object] value
# File lib/xmlable/mixins/root_storage.rb, line 71 def __root_object_initialize(h, value) return self.root = value unless value.is_a?(Hash) value.each do |key, val| root[key].__initialize_with(val) end end
__set_root(node)
click to toggle source
Set XML root element
@param [Nokogiri::XML::Element, nil] node
# File lib/xmlable/mixins/root_storage.rb, line 16 def __set_root(node) unless node.is_a?(Nokogiri::XML::Element) node = Nokogiri::XML::Element.new(__root_handler.tag.to_s, @__node) @__node.root = node end node.instance_variable_set(:@__handler, __root_handler) @root = __root_handler.from_xml_element(node) if __root_handler.namespace_prefix node.namespace = node.namespace_scopes.find do |n| n.prefix == __root_handler.namespace_prefix end end end
key?(key)
click to toggle source
Does this object has root object with given key?
@return [Boolean]
Calls superclass method
# File lib/xmlable/mixins/root_storage.rb, line 92 def key?(key) names = ['root', __root_handler.method_name] return __root_handler if names.include?(key.to_s) super end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/xmlable/mixins/root_storage.rb, line 30 def method_missing(name, *args, &block) return super unless key?(name) return root unless name.to_s.end_with?('=') self.root = args.first end
root()
click to toggle source
Get root object
@return [XMLable::Mixins::Object]
# File lib/xmlable/mixins/root_storage.rb, line 51 def root __set_root(nil) unless instance_variable_defined?(:@root) @root end
root!()
click to toggle source
Get unwraped root object's value
@return [Object]
# File lib/xmlable/mixins/root_storage.rb, line 61 def root! root.__object end
root=(val)
click to toggle source
Set root object content
@param [Object] val
# File lib/xmlable/mixins/root_storage.rb, line 83 def root=(val) @root.__overwrite_content(val) end