Class: BucketsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/buckets_controller.rb

Instance Method Summary collapse

Instance Method Details

#clearObject



24
25
26
27
28
# File 'app/controllers/buckets_controller.rb', line 24

def clear
  bucket.clear_history

  redirect_to bucket_path(bucket.token)
end

#createObject



6
7
8
9
10
11
12
13
# File 'app/controllers/buckets_controller.rb', line 6

def create
  new_bucket = { owner_token: owner_token }
  new_bucket[:user_id] = current_user.id if user_signed_in?

  bucket = Bucket.create(new_bucket)

  redirect_to bucket_path(bucket.token)
end

#destroyObject



30
31
32
33
34
# File 'app/controllers/buckets_controller.rb', line 30

def destroy
  bucket.destroy

  redirect_to root_path
end

#forkObject



15
16
17
18
19
20
21
22
# File 'app/controllers/buckets_controller.rb', line 15

def fork
  forked_bucket = Bucket.create(owner_token:       owner_token,
                                response_builder:  bucket.response_builder,
                                name:              "Copy of #{bucket.name}",
                                fork:              bucket)

  redirect_to bucket_path(forked_bucket.token)
end

#lastObject



49
50
51
52
53
54
55
56
# File 'app/controllers/buckets_controller.rb', line 49

def last
  return render_request_not_found unless last_request = bucket.last_request

  respond_to do |format|
    format.html { render text: last_request.body }
    format.json { render json: JSON.pretty_generate(last_request.attributes) }
  end
end

#last_responseObject



58
59
60
61
62
63
64
65
# File 'app/controllers/buckets_controller.rb', line 58

def last_response
  return render_request_not_found unless last_response = bucket.last_response

  respond_to do |format|
    format.html { render text: last_response.body }
    format.json { render json: JSON.pretty_generate(last_response.attributes) }
  end
end

#recordObject



67
68
69
70
71
72
73
74
75
# File 'app/controllers/buckets_controller.rb', line 67

def record
  result = RecordRequest.call(bucket: bucket, rack_request: request)
  recorded_response = result.response

  response.headers.merge! recorded_response.headers.to_h

  render text: body_as_string(recorded_response),
         status: recorded_response.status
end

#showObject



36
37
38
# File 'app/controllers/buckets_controller.rb', line 36

def show
  @requests = bucket.requests.page(params[:page]).per 1
end

#updateObject



40
41
42
43
44
45
46
47
# File 'app/controllers/buckets_controller.rb', line 40

def update
  update_bucket = bucket_params
  update_bucket[:user_id] = current_user.id if user_signed_in?

  bucket.update_attributes update_bucket

  redirect_to bucket_path(bucket.token)
end