Class: Resourceful::Model::Xml

Inherits:
Base
  • Object
show all
Defined in:
lib/resourceful/model/xml.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

agent, #attributes, #data, #destroy, find, #new_record?, #save, #update_attributes

Constructor Details

#initialize(xml = nil) ⇒ Xml

Returns a new instance of Xml.



31
32
33
34
# File 'lib/resourceful/model/xml.rb', line 31

def initialize(xml=nil)
  raise Resourceful::Exceptions::ModelError, "trying to initialize a Resourceful::Model::Xml model with '#{xml.class.name}' data" unless xml.nil? || xml.kind_of?(Nokogiri::XML::NodeSet) || xml.kind_of?(Nokogiri::XML::Element)
  @data = xml
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



8
9
10
# File 'lib/resourceful/model/xml.rb', line 8

def xml
  @xml
end

Class Method Details

.get(path, params, search, force = false, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/resourceful/model/xml.rb', line 10

def self.get(path, params, search, force=false, &block)
  opts = {
    :format => 'xml',
    :params => params || {},
    :force => force,
    :on_response => block
  }
  new(super(path, opts).search(search))
end

.get_collection(path, params, search, force = false, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/resourceful/model/xml.rb', line 19

def self.get_collection(path, params, search, force=false, &block)
  opts = {
    :format => 'xml',
    :params => params || {},
    :force => force,
    :on_response => block
  }
  super(path, opts) do |data|
    data.search(search)
  end
end