Class: BucketsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- BucketsController
- Defined in:
- app/controllers/buckets_controller.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #fork ⇒ Object
- #last ⇒ Object
- #last_response ⇒ Object
- #record ⇒ Object
- #requests_count ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#clear ⇒ Object
25 26 27 28 29 |
# File 'app/controllers/buckets_controller.rb', line 25 def clear bucket.clear_history redirect_to bucket_path(bucket.token) end |
#create ⇒ Object
10 11 12 |
# File 'app/controllers/buckets_controller.rb', line 10 def create redirect_to bucket_path(bucket.token) end |
#destroy ⇒ Object
31 32 33 34 35 |
# File 'app/controllers/buckets_controller.rb', line 31 def destroy bucket.destroy redirect_to root_path end |
#fork ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/buckets_controller.rb', line 14 def fork fork = Bucket.create( owner_token: owner_token, response_builder: bucket.response_builder, name: "Copy of #{bucket.name}", fork: bucket ) redirect_to bucket_path(fork.token) end |
#last ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/controllers/buckets_controller.rb', line 55 def last return render_request_not_found unless last_request = bucket.last_request respond_to do |format| format.html { render plain: last_request.body } format.json { render json: JSON.pretty_generate(last_request.attributes) } end end |
#last_response ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'app/controllers/buckets_controller.rb', line 64 def last_response return render_request_not_found unless last_response = bucket.last_response respond_to do |format| format.html { render plain: last_response.body } format.json { render json: JSON.pretty_generate(last_response.attributes) } end end |
#record ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/buckets_controller.rb', line 73 def record result = RecordRequest.call(bucket: bucket, rack_request: request) recorded_response = result.response response.headers.merge! recorded_response.headers.to_h render plain: body_as_string(recorded_response), status: recorded_response.status end |
#requests_count ⇒ Object
6 7 8 |
# File 'app/controllers/buckets_controller.rb', line 6 def requests_count render json: { requests_count: bucket.requests.count } end |
#show ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/controllers/buckets_controller.rb', line 37 def show bucket.request = bucket.requests.page(params[:page]).per(1).first respond_to do |format| format.html { render } format.json { render json: bucket, serializer: BucketSerializer } end end |
#update ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/controllers/buckets_controller.rb', line 46 def update update_bucket = bucket_params update_bucket[:user_id] = current_user.id if user_signed_in? bucket.update update_bucket redirect_to bucket_path(bucket.token) end |