class StackerBee::Middleware::CleanResponse

Public Instance Methods

after(env) click to toggle source
# File lib/stacker_bee/middleware/clean_response.rb, line 4
def after(env)
  body = env.response.body

  return unless hash?(body)

  if contains_count?(body)
    env.response.body = remove_count(body)
  elsif single_hash?(body)
    env.response.body = first_hash(body)
  end
end
contains_count?(body) click to toggle source
# File lib/stacker_bee/middleware/clean_response.rb, line 20
def contains_count?(body)
  body.size == 2 && body.key?('count')
end
content_types() click to toggle source
# File lib/stacker_bee/middleware/clean_response.rb, line 36
def content_types
  /javascript/
end
first_hash(body) click to toggle source
# File lib/stacker_bee/middleware/clean_response.rb, line 32
def first_hash(body)
  body.values.first
end
hash?(body) click to toggle source
# File lib/stacker_bee/middleware/clean_response.rb, line 16
def hash?(body)
  body.respond_to?(:keys)
end
remove_count(body) click to toggle source
# File lib/stacker_bee/middleware/clean_response.rb, line 24
def remove_count(body)
  body.reject { |key, _| key == 'count' }.values.first
end
single_hash?(body) click to toggle source
# File lib/stacker_bee/middleware/clean_response.rb, line 28
def single_hash?(body)
  body.size == 1 && body.values.first.respond_to?(:keys)
end