Class: Adva::Static::Import::Request
- Inherits:
-
Object
- Object
- Adva::Static::Import::Request
- Defined in:
- lib/adva/static/import/request.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #controller ⇒ Object
- #create? ⇒ Boolean
- #destroy? ⇒ Boolean
-
#initialize(source, record, attributes) ⇒ Request
constructor
A new instance of Request.
- #params ⇒ Object
- #path ⇒ Object
- #public_path ⇒ Object
- #update? ⇒ Boolean
Constructor Details
#initialize(source, record, attributes) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 |
# File 'lib/adva/static/import/request.rb', line 7 def initialize(source, record, attributes) @source = source @record = record @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/adva/static/import/request.rb', line 5 def attributes @attributes end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
5 6 7 |
# File 'lib/adva/static/import/request.rb', line 5 def record @record end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/adva/static/import/request.rb', line 5 def source @source end |
Instance Method Details
#controller ⇒ Object
46 47 48 49 50 51 |
# File 'lib/adva/static/import/request.rb', line 46 def controller @controller ||= controller_name.constantize.new.tap do |controller| controller.request = ActionDispatch::TestRequest.new controller.params = params_for(controller) end end |
#create? ⇒ Boolean
34 35 36 |
# File 'lib/adva/static/import/request.rb', line 34 def create? !update? && !destroy? end |
#destroy? ⇒ Boolean
42 43 44 |
# File 'lib/adva/static/import/request.rb', line 42 def destroy? record.persisted? && !source.exist? end |
#params ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/adva/static/import/request.rb', line 13 def params @params ||= begin key = model_name.underscore.to_sym if destroy? params = { '_method' => 'delete', key => { :id => record.id } } else params = { model_name.underscore.to_sym => attributes } params.merge!('_method' => 'put') if update? end stringify(params) end end |
#path ⇒ Object
26 27 28 |
# File 'lib/adva/static/import/request.rb', line 26 def path controller.polymorphic_path(controller.resources) end |
#public_path ⇒ Object
30 31 32 |
# File 'lib/adva/static/import/request.rb', line 30 def public_path controller.public_url_for(controller.resources, :routing_type => :path) end |
#update? ⇒ Boolean
38 39 40 |
# File 'lib/adva/static/import/request.rb', line 38 def update? record.persisted? && source.exist? end |