Class: ActiveResource::Simulator
- Inherits:
-
Object
- Object
- ActiveResource::Simulator
- Defined in:
- lib/active_resource/simulator.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#simulations ⇒ Object
readonly
Returns the value of attribute simulations.
Instance Method Summary collapse
- #create(body = nil, options = {}) ⇒ Object
- #destroy(param, options = {}) ⇒ Object
-
#initialize(model) ⇒ Simulator
constructor
A new instance of Simulator.
- #show(param, body = nil, options = {}) ⇒ Object
- #simulate_request(method, path, body = nil, options = {}) ⇒ Object (also: #simulate)
- #update(param, options = {}) ⇒ Object
Constructor Details
#initialize(model) ⇒ Simulator
Returns a new instance of Simulator.
5 6 7 8 |
# File 'lib/active_resource/simulator.rb', line 5 def initialize(model) @model = model @@simulations = [] end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
10 11 12 |
# File 'lib/active_resource/simulator.rb', line 10 def model @model end |
#simulations ⇒ Object (readonly)
Returns the value of attribute simulations.
10 11 12 |
# File 'lib/active_resource/simulator.rb', line 10 def simulations @simulations end |
Instance Method Details
#create(body = nil, options = {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/active_resource/simulator.rb', line 21 def create(body=nil, ={}) path = .delete(:path) || model.collection_path .reverse_merge!({:status => 201}) simulate_request(:post, path, body, ) end |
#destroy(param, options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/active_resource/simulator.rb', line 39 def destroy(param, ={}) path = .delete(:path) || model.element_path(param) .reverse_merge!({:status => 200}) simulate_request(:delete, path, [:body], ) end |
#show(param, body = nil, options = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/active_resource/simulator.rb', line 27 def show(param, body=nil, ={}) path = .delete(:path) || model.element_path(param) .reverse_merge!({:status => 200}) simulate_request(:get, path, body, ) end |
#simulate_request(method, path, body = nil, options = {}) ⇒ Object Also known as: simulate
13 14 15 16 |
# File 'lib/active_resource/simulator.rb', line 13 def simulate_request(method, path, body=nil, ={}) @@simulations << prepare_simulation(method, path, body, ) load_simulations! end |
#update(param, options = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/active_resource/simulator.rb', line 33 def update(param, ={}) path = .delete(:path) || model.element_path(param) .reverse_merge!({:status => 204}) simulate_request(:put, path, [:body], ) end |