Class: DynamicsCRM::Metadata::XmlDocument
- Inherits:
-
Object
- Object
- DynamicsCRM::Metadata::XmlDocument
- Defined in:
- lib/dynamics_crm/metadata/xml_document.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#initialize(document) ⇒ XmlDocument
constructor
A new instance of XmlDocument.
-
#method_missing(method, *args, &block) ⇒ Object
Allows access to attributes in underlying XML document.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(document) ⇒ XmlDocument
Returns a new instance of XmlDocument.
7 8 9 |
# File 'lib/dynamics_crm/metadata/xml_document.rb', line 7 def initialize(document) @document = document end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Allows access to attributes in underlying XML document.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dynamics_crm/metadata/xml_document.rb', line 12 def method_missing(method, *args, &block) value = nil return value if @document.nil? camel_name = method.to_s element = @document.get_elements("./[local-name() = '#{camel_name}']").first if element && element.children.size == 1 && element.children.first.is_a?(REXML::Text) value = element.text elsif element value = XmlDocument.new(element) else # This returns if no XML element was found to avoid nil errors. value = OpenStruct.new end # Return wrapper to support method_method missing. return value end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
6 7 8 |
# File 'lib/dynamics_crm/metadata/xml_document.rb', line 6 def document @document end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
32 33 34 35 |
# File 'lib/dynamics_crm/metadata/xml_document.rb', line 32 def respond_to_missing?(method_name, include_private = false) camel_name = method_name.to_s @document.get_elements("d:#{camel_name}").any? || super end |