class Almodovar::Resource

Public Class Methods

from_xml(xml, auth = nil) click to toggle source
# File lib/almodovar/resource.rb, line 10
def self.from_xml(xml, auth = nil)
  new(nil, auth, Nokogiri::XML.parse(xml).root)
end
new(url, auth, xml = nil, options = {}) click to toggle source
# File lib/almodovar/resource.rb, line 14
def initialize(url, auth, xml = nil, options = {})
  @url = url
  @auth = auth
  @xml = xml
  @options = options
end

Public Instance Methods

method_missing(meth, *args, &blk) click to toggle source
# File lib/almodovar/resource.rb, line 21
def method_missing(meth, *args, &blk)
  resource_object(meth).send(meth, *args, &blk)
end
respond_to?(meth, include_all=false) click to toggle source
Calls superclass method
# File lib/almodovar/resource.rb, line 25
def respond_to?(meth, include_all=false)
  super || resource_object(meth).respond_to?(meth, include_all)
end
to_xml(options = {}) click to toggle source
# File lib/almodovar/to_xml.rb, line 12
def to_xml(options = {})
  options[:builder].tag!(:link, rel: options[:root], href: url)
end

Private Instance Methods

collection_call?(meth, *args) click to toggle source
# File lib/almodovar/resource.rb, line 36
def collection_call?(meth, *args)
  ([].respond_to?(meth) && !["delete", "id", "[]"].include?(meth.to_s)) ||
  ResourceCollection.instance_methods(false).map(&:to_s).include?(meth.to_s) ||
  (meth.to_s == "[]" && args.size == 1 && args.first.is_a?(Fixnum))
end
get!() click to toggle source
# File lib/almodovar/resource.rb, line 31
def get!
  klass = xml['type'] == 'array' ? ResourceCollection : SingleResource
  @resource_object = klass.new(@url, @auth, @xml, @options)
end
resource_class(meth, *args) click to toggle source
# File lib/almodovar/resource.rb, line 46
def resource_class(meth, *args)
  @resource_class ||= collection_call?(meth, *args) ? ResourceCollection : SingleResource
end
resource_object(meth) click to toggle source
# File lib/almodovar/resource.rb, line 42
def resource_object(meth)
  @resource_object ||= resource_class(meth).new(@url, @auth, @xml, @options)
end