Class: Splunker::Models::Resource

Inherits:
Object
  • Object
show all
Includes:
Finders
Defined in:
lib/splunker/models/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Finders

included

Constructor Details

#initialize(xml_doc) ⇒ Resource

Returns a new instance of Resource.



26
27
28
# File 'lib/splunker/models/resource.rb', line 26

def initialize(xml_doc)
  self.attributes = XmlProcessor.hashify(xml_doc)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *arguments) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/splunker/models/resource.rb', line 30

def method_missing(method_symbol, *arguments)
  method_name = method_symbol.to_s
  if method_name =~ /(=|\?)$/
    case $1
    when "=" 
      write_attribute($`, arguments.first)
    when "?" 
      if attributes.include?($`)
        attributes[$`] ? true : false
      else
        raise NoMethodError
      end
    end 
  elsif attributes.include?(method_name)
    return attributes[method_name]
  else
    super
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



10
11
12
# File 'lib/splunker/models/resource.rb', line 10

def attributes
  @attributes
end

Class Method Details

.clientObject



22
23
24
# File 'lib/splunker/models/resource.rb', line 22

def self.client
  Splunker.client
end

.my_service_pathObject



18
19
20
# File 'lib/splunker/models/resource.rb', line 18

def self.my_service_path
  @service_path
end

.service_path(path) ⇒ Object



14
15
16
# File 'lib/splunker/models/resource.rb', line 14

def self.service_path(path)
  @service_path = path
end

Instance Method Details

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

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/splunker/models/resource.rb', line 50

def respond_to?(method_symbol, include_private=false)
  if super
    return true
  else
    method_name = method_symbol.to_s

    if method_name =~ /=$/
      true
    elsif method_name =~ /(\?)$/
      attributes.include?($`)
    else
      attributes.include?(method_name)
    end

  end
end