Class: Aeolus::Image::Factory::Base
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- Aeolus::Image::Factory::Base
- Defined in:
- lib/aeolus_image/model/factory/base.rb
Direct Known Subclasses
Class Method Summary collapse
-
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
Remove format from the url for collections.
-
.config ⇒ Object
This approach does mean you’re limited to one server at a time.
- .config=(conf = {}) ⇒ Object
-
.custom_method_collection_url(method_name, options = {}) ⇒ Object
Modifying the url formations to make them Factory compliant.
-
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Remove format from the url for resources.
-
.get(method_name, options = {}) ⇒ Object
The objects returned from this method are not automatically converted into ActiveResource instances - they are ordinary Hashes.
-
.instantiate_collection(collection, prefix_options = {}) ⇒ Object
For a collection call, ActiveResource formatting is not compliant with Factory’s output.
-
.use_oauth? ⇒ Boolean
Should we use OAuth?.
Instance Method Summary collapse
-
#custom_method_element_url(method_name, options = {}) ⇒ Object
Modifying the url formations to make them Factory compliant.
-
#get(method_name, options = {}) ⇒ Object
Instance Methods: (modifying the ActiveRecord::CustomMethods).
-
#initialize(attributes = {}, persisted = nil) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(attributes = {}, persisted = nil) ⇒ Base
Returns a new instance of Base.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/aeolus_image/model/factory/base.rb', line 72 def initialize(attributes = {}, persisted = nil) # The !! operator is required to set modified_persisted to false when # persisted == nil && attributes[:id] == nil modified_persisted = (persisted.nil? && attributes[:id]) ? true : !!persisted if ActiveResource::VERSION::MAJOR >= 3 && ActiveResource::VERSION::MINOR >= 1 super(attributes, modified_persisted) else super(attributes) end end |
Class Method Details
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
Remove format from the url for collections
31 32 33 34 |
# File 'lib/aeolus_image/model/factory/base.rb', line 31 def collection_path( = {}, = nil) , = () if .nil? "#{prefix()}#{collection_name}#{query_string()}" end |
.config ⇒ Object
This approach does mean you’re limited to one server at a time
58 59 60 |
# File 'lib/aeolus_image/model/factory/base.rb', line 58 def config defined?(@@config) ? @@config : {} end |
.config=(conf = {}) ⇒ Object
61 62 63 64 |
# 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 = {}) ⇒ Object
Modifying the url formations to make them Factory compliant
97 98 99 100 101 |
# File 'lib/aeolus_image/model/factory/base.rb', line 97 def self.custom_method_collection_url(method_name, = {}) , = () url = "#{prefix()}#{collection_name}/#{method_name}#{query_string()}" url end |
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Remove format from the url for resources
25 26 27 28 |
# File 'lib/aeolus_image/model/factory/base.rb', line 25 def element_path(id, = {}, = nil) , = () if .nil? "#{prefix()}#{collection_name}/#{id}#{query_string()}" end |
.get(method_name, options = {}) ⇒ Object
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.
48 49 50 51 52 53 54 55 |
# File 'lib/aeolus_image/model/factory/base.rb', line 48 def get(method_name, = {}) object_array = connection.get(custom_method_collection_url(method_name, ), 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 = {}) ⇒ Object
For a collection call, ActiveResource formatting is not compliant with Factory’s output.
38 39 40 41 42 43 44 |
# File 'lib/aeolus_image/model/factory/base.rb', line 38 def instantiate_collection(collection, = {}) unless collection.kind_of? Array [instantiate_record(collection, )] else collection.collect! { |record| instantiate_record(record, ) } end end |
.use_oauth? ⇒ Boolean
Should we use OAuth?
67 68 69 |
# File 'lib/aeolus_image/model/factory/base.rb', line 67 def use_oauth? config[:consumer_key] && config[:consumer_secret] && config[:site] end |
Instance Method Details
#custom_method_element_url(method_name, options = {}) ⇒ Object
Modifying the url formations to make them Factory compliant
91 92 93 94 |
# File 'lib/aeolus_image/model/factory/base.rb', line 91 def custom_method_element_url(method_name, = {}) "#{self.class.prefix()}#{self.class.collection_name}/#{id}/" + "#{method_name}#{self.class.send!(:query_string, )}" end |
#get(method_name, options = {}) ⇒ Object
Instance Methods: (modifying the ActiveRecord::CustomMethods). This modification is same as defined in above method
86 87 88 |
# File 'lib/aeolus_image/model/factory/base.rb', line 86 def get(method_name, = {}) self.class.new.load(connection.get(custom_method_element_url(method_name, ), self.class.headers)) end |