-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from mtaylor/initial_factory_integration
Initial factory integration
- Loading branch information
Showing
27 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
lib/generators/image_management/templates/intializers/image_management_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
############################## Image Management Engine Initializer ################################ | ||
|
||
# Image Factory URL | ||
ImageManagement::ImageFactory::Base.site = "http://localhost:8075/imagefactory" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require "active_resource" | ||
require File.join(File.dirname(__FILE__), 'model', 'base') | ||
require File.join(File.dirname(__FILE__), 'model', 'target_image') | ||
require File.join(File.dirname(__FILE__), 'model', 'provider_image') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module ImageManagement | ||
module ImageFactory | ||
class Base < ActiveResource::Base | ||
self.format = :json | ||
# TODO Verify Image Factory Certification Concerns that warrent removing SSL Verfication | ||
self.ssl_options = {:verify_mode => OpenSSL::SSL::VERIFY_NONE} | ||
|
||
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 | ||
|
||
# This approach does mean you're limited to one server at a time | ||
def config | ||
defined?(@@config) ? @@config : {} | ||
end | ||
def config=(conf={}) | ||
@@config = conf | ||
self.site = @@config[:site] | ||
end | ||
|
||
# Should we use OAuth? | ||
def use_oauth? | ||
config[:consumer_key] && config[:consumer_secret] && config[:site] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module ImageManagement | ||
module ImageFactory | ||
class ProviderImage < Base | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module ImageManagement | ||
module ImageFactory | ||
class TargetImage < Base | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require "image_management/engine" | ||
require "image_management/engine" | ||
require "image_factory/image_factory.rb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryGirl.define do | ||
factory :base_image, :class => ImageManagement::BaseImage do | ||
association :template, :factory => :template | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module ImageManagement | ||
FactoryGirl.define do | ||
factory :image_version, :class => ImageManagement::ImageVersion do | ||
association :base_image, :factory => :base_image | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FactoryGirl.define do | ||
factory :target_image, :class => ImageManagement::TargetImage do | ||
association :image_version, :factory => :image_version | ||
target 'Mock' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryGirl.define do | ||
factory :template, :class => ImageManagement::Template do | ||
location 'http://localhost:3000/templates/1' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# Setup Rails Envinronment | ||
ENV["RAILS_ENV"] = "test" | ||
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) | ||
|
||
require File.expand_path("../../lib/image_factory/image_factory.rb", __FILE__) | ||
require 'rspec' | ||
require 'factory_girl' | ||
|
||
Dir.glob(File.dirname(__FILE__) + "/factories/*/*").each do |factory| | ||
require factory | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.color_enabled = true | ||
config.formatter = 'documentation' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
############################## Image Management Engine Initializer ################################ | ||
|
||
# Image Factory URL | ||
ImageManagement::ImageFactory::Base.site = "http://localhost:8075/imagefactory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters