Class: Fafactory
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- Fafactory
- Defined in:
- lib/fafactory.rb
Class Method Summary collapse
-
.clear_definitions ⇒ Object
Clears definitions (mainly useful for testing).
-
.create(service, model, options) ⇒ Object
Constructs a new instance based on the given service and model.
-
.create_instance(service, model, data) ⇒ Object
Creates a new instance of a remote model using the data provided.
-
.define(service, model, defaults) ⇒ Object
Defines a new object definition.
-
.find(service, model, id) ⇒ Object
Loads an instance of a remote model based on the id given.
- .purge(*services) ⇒ Object
Instance Method Summary collapse
-
#create(options) ⇒ Object
Creates a new remote instance based on the given parameters.
-
#initialize(service, model, defaults) ⇒ Fafactory
constructor
Set up a new fafactory with the given defaults.
Constructor Details
Class Method Details
.clear_definitions ⇒ Object
Clears definitions (mainly useful for testing)
69 70 71 |
# File 'lib/fafactory.rb', line 69 def self.clear_definitions @definitions = {} if defined? @definitions end |
.create(service, model, options) ⇒ Object
Constructs a new instance based on the given service and model
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fafactory.rb', line 17 def self.create(service, model, ) model = camelize_model(model) # define a blank definition if we don't already have a definition @definitions ||= {} if @definitions[service] == nil || @definitions[service][model] == nil define(service, model, {}) end @definitions[service][model].create() end |
.create_instance(service, model, data) ⇒ Object
Creates a new instance of a remote model using the data provided.
45 46 47 48 49 50 51 |
# File 'lib/fafactory.rb', line 45 def self.create_instance(service, model, data) Fafactory.configure_site(service) result = Fafactory.post :create_instance, nil, { :model => camelize_model(model), :data => data }.to_xml return Hash.from_xml(result.body) end |
.define(service, model, defaults) ⇒ Object
Defines a new object definition
6 7 8 9 10 11 12 13 14 |
# File 'lib/fafactory.rb', line 6 def self.define(service, model, defaults) @definitions ||= {} model = camelize_model(model) factory = Fafactory.new(service, model, defaults) @definitions[service] ||= {} @definitions[service][model] = factory end |
Instance Method Details
#create(options) ⇒ Object
Creates a new remote instance based on the given parameters
39 40 41 42 |
# File 'lib/fafactory.rb', line 39 def create() Fafactory.create_instance(@service, @model, .merge(@defaults))[Fafactory.underscore_model(@model)] end |