Class: Coreimpact::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/coreimpact/module.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml_module) ⇒ Module

Returns a new instance of Module.

[View source]

3
4
5
# File 'lib/coreimpact/module.rb', line 3

def initialize(xml_module)
  @xml = xml_module
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Example XML: <property type=“container” key=“Modules”>

<property type="container" key="<Title>">
  <property type="bool" key="agent_deployed">false</property>
  <property type="string" key="description">
    Some description.
  </property>
  <property type="string" key="port">443</property>
  <property type="bool" key="tried_to_install_agent">false</property>
</property>

</property>

[View source]

28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/coreimpact/module.rb', line 28

def method_missing(method, *args)
  # We could remove this check and return nil for any non-recognized tag.
  # The problem would be that it would make tricky to debug problems with
  # typos. For instance: <>.potr would return nil instead of raising an
  # exception
  unless supported_tags.include?(method)
    super
    return
  end

  @xml.at_xpath("./property[@type='container']/property[@key='#{method}']").text || 'n/a'
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)
[View source]

11
12
13
14
15
# File 'lib/coreimpact/module.rb', line 11

def respond_to?(method, include_private = false)
  return true if supported_tags.include?(method.to_sym)

  super
end

#supported_tagsObject

[View source]

7
8
9
# File 'lib/coreimpact/module.rb', line 7

def supported_tags
  [:agent_deployed, :description, :port, :tried_to_install_agent]
end