class Aeolus::Image::Factory::Base

Public Class Methods

collection_path(prefix_options = {}, query_options = nil) click to toggle source

Remove format from the url for collections

# File lib/aeolus_image/model/factory/base.rb, line 31
def collection_path(prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
end
config() click to toggle source

This approach does mean you're limited to one server at a time

# File lib/aeolus_image/model/factory/base.rb, line 58
def config
  defined?(@@config) ? @@config : {}
end
config=(conf={}) click to toggle source
# File lib/aeolus_image/model/factory/base.rb, line 61
def config=(conf={})
  @@config = conf
  self.site = @@config[:site]
end
custom_method_collection_url(method_name, options = {}) click to toggle source

Modifying the url formations to make them Factory compliant

# File lib/aeolus_image/model/factory/base.rb, line 85
def self.custom_method_collection_url(method_name, options = {})
  prefix_options, query_options = split_options(options)
  url = "#{prefix(prefix_options)}#{collection_name}/#{method_name}#{query_string(query_options)}"
  url
end
element_path(id, prefix_options = {}, query_options = nil) click to toggle source

Remove format from the url for resources

# File lib/aeolus_image/model/factory/base.rb, line 25
def element_path(id, prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
end
get(method_name, options = {}) click to toggle source

The objects returned from this method are not automatically converted into ActiveResource instances - they are ordinary Hashes. Modifications below ensures that you get ActiveResource instances.

# File lib/aeolus_image/model/factory/base.rb, line 48
def get(method_name, options = {})
  object_array = connection.get(custom_method_collection_url(method_name, options), headers)
  if object_array.class.to_s=="Array"
    object_array.collect! {|record| self.class.new.load(record)}
  else
    self.class.new.load(object_array)
  end
end
instantiate_collection(collection, prefix_options = {}) click to toggle source

For a collection call, ActiveResource formatting is not compliant with Factory's output.

# File lib/aeolus_image/model/factory/base.rb, line 38
def instantiate_collection(collection, prefix_options = {})
  unless collection.kind_of? Array
    [instantiate_record(collection, prefix_options)]
  else
    collection.collect! { |record| instantiate_record(record, prefix_options) }
  end
end
use_oauth?() click to toggle source

Should we use OAuth?

# File lib/aeolus_image/model/factory/base.rb, line 67
def use_oauth?
  config[:consumer_key] && config[:consumer_secret] && config[:site]
end

Public Instance Methods

custom_method_element_url(method_name, options = {}) click to toggle source

Modifying the url formations to make them Factory compliant

# File lib/aeolus_image/model/factory/base.rb, line 79
def custom_method_element_url(method_name, options = {})
  "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/" +
  "#{method_name}#{self.class.send!(:query_string, options)}"
end
get(method_name, options = {}) click to toggle source

Instance Methods: (modifying the ActiveRecord::CustomMethods). This modification is same as defined in above method

# File lib/aeolus_image/model/factory/base.rb, line 74
def get(method_name, options = {})
  self.class.new.load(connection.get(custom_method_element_url(method_name, options), self.class.headers))
end