From: Martyn Taylor mtaylor@redhat.com
--- lib/aeolus_image/model/factory/base.rb | 63 ++++++++++++++++++++++ lib/aeolus_image/model/factory/build.rb | 8 +++ lib/aeolus_image/model/factory/builder.rb | 8 +++ lib/aeolus_image/model/factory/image.rb | 8 +++ lib/aeolus_image/model/factory/provider_image.rb | 11 ++++ lib/aeolus_image/model/factory/target_image.rb | 11 ++++ 6 files changed, 109 insertions(+), 0 deletions(-) create mode 100644 lib/aeolus_image/model/factory/base.rb create mode 100644 lib/aeolus_image/model/factory/build.rb create mode 100644 lib/aeolus_image/model/factory/builder.rb create mode 100644 lib/aeolus_image/model/factory/image.rb create mode 100644 lib/aeolus_image/model/factory/provider_image.rb create mode 100644 lib/aeolus_image/model/factory/target_image.rb
diff --git a/lib/aeolus_image/model/factory/base.rb b/lib/aeolus_image/model/factory/base.rb new file mode 100644 index 0000000..614a25f --- /dev/null +++ b/lib/aeolus_image/model/factory/base.rb @@ -0,0 +1,63 @@ +module Aeolus + module Image + module Factory + class Base < ActiveResource::Base + self.format = :json + + class << self + ## Remove format from the url for resources + 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 + + ## Remove format from the url for collections + 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 + + ## For a collection call, ActiveResource formatting is not + ## compliant with Factory's output. + 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 + + ## 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. + 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 + end + + ## Instance Methods: (modifying the ActiveRecord::CustomMethods). + ## This modification is same as defined in above method + def get(method_name, options = {}) + self.class.new.load(connection.get(custom_method_element_url(method_name, options), self.class.headers)) + end + + # Modifying the url formations to make them Factory compliant + 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 + + # Modifying the url formations to make them Factory compliant + 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 + end + end + end +end \ No newline at end of file diff --git a/lib/aeolus_image/model/factory/build.rb b/lib/aeolus_image/model/factory/build.rb new file mode 100644 index 0000000..b238cea --- /dev/null +++ b/lib/aeolus_image/model/factory/build.rb @@ -0,0 +1,8 @@ +module Aeolus + module Image + module Factory + class Build < Base + end + end + end +end \ No newline at end of file diff --git a/lib/aeolus_image/model/factory/builder.rb b/lib/aeolus_image/model/factory/builder.rb new file mode 100644 index 0000000..5476456 --- /dev/null +++ b/lib/aeolus_image/model/factory/builder.rb @@ -0,0 +1,8 @@ +module Aeolus + module Image + module Factory + class Builder < Base + end + end + end +end \ No newline at end of file diff --git a/lib/aeolus_image/model/factory/image.rb b/lib/aeolus_image/model/factory/image.rb new file mode 100644 index 0000000..712457f --- /dev/null +++ b/lib/aeolus_image/model/factory/image.rb @@ -0,0 +1,8 @@ +module Aeolus + module Image + module Factory + class Image < Base + end + end + end +end \ No newline at end of file diff --git a/lib/aeolus_image/model/factory/provider_image.rb b/lib/aeolus_image/model/factory/provider_image.rb new file mode 100644 index 0000000..9022c06 --- /dev/null +++ b/lib/aeolus_image/model/factory/provider_image.rb @@ -0,0 +1,11 @@ +module Aeolus + module Image + module Factory + class ProviderImage < Base + def self.status(id) + Aeolus::Image::Factory::Builder.find(id).status + end + end + end + end +end \ No newline at end of file diff --git a/lib/aeolus_image/model/factory/target_image.rb b/lib/aeolus_image/model/factory/target_image.rb new file mode 100644 index 0000000..4c87006 --- /dev/null +++ b/lib/aeolus_image/model/factory/target_image.rb @@ -0,0 +1,11 @@ +module Aeolus + module Image + module Factory + class TargetImage < Base + def self.status(id) + Aeolus::Image::Factory::Builder.find(id).status + end + end + end + end +end \ No newline at end of file
aeolus-devel@lists.fedorahosted.org