Class: ROXML::XMLRef

Inherits:
Object
  • Object
show all
Defined in:
lib/roxml/xml/references.rb

Overview

Internal base class that represents an XML - Class binding.

Direct Known Subclasses

XMLAttributeRef, XMLTextRef

Instance Method Summary collapse

Constructor Details

#initialize(opts, instance) ⇒ XMLRef

Returns a new instance of XMLRef.



11
12
13
14
# File 'lib/roxml/xml/references.rb', line 11

def initialize(opts, instance)
  @opts = opts
  @instance = instance
end

Instance Method Details

#nameObject



27
28
29
# File 'lib/roxml/xml/references.rb', line 27

def name
  opts.name_explicit? ? opts.name : conventionize(opts.name)
end

#to_xml(instance) ⇒ Object



16
17
18
19
# File 'lib/roxml/xml/references.rb', line 16

def to_xml(instance)
  val = instance.__send__(accessor)
  opts.to_xml.respond_to?(:call) ? opts.to_xml.call(val) : val
end

#update_xml(xml, value) ⇒ Object



21
22
23
24
25
# File 'lib/roxml/xml/references.rb', line 21

def update_xml(xml, value)
  returning wrap(xml) do |xml|
    write_xml(xml, value)
  end
end

#value_in(xml) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/roxml/xml/references.rb', line 35

def value_in(xml)
  xml = XML::Node.from(xml)
  value = fetch_value(xml)
  value = default if value.nil?

  freeze(apply_blocks(value))
end

#xpath_nameObject



31
32
33
# File 'lib/roxml/xml/references.rb', line 31

def xpath_name
  namespacify(name)
end