class Govuk::DummyContentStore::Content
Attributes
live_repository[R]
repository[R]
Public Class Methods
new(repository, live_repository = nil)
click to toggle source
# File lib/govuk/dummy_content_store/content.rb, line 12 def initialize(repository, live_repository = nil) @repository = repository @live_repository = live_repository end
Public Instance Methods
call(env)
click to toggle source
# File lib/govuk/dummy_content_store/content.rb, line 17 def call(env) example = repository.find_by_base_path(env["PATH_INFO"]) if example present_example(example) elsif live_repository && res = live_repository.find_by_base_path(env["PATH_INFO"]) present_live(res.body) else present_not_found end end
Private Instance Methods
present_example(example)
click to toggle source
# File lib/govuk/dummy_content_store/content.rb, line 29 def present_example(example) headers = { 'Content-Type' => 'application/json; charset=utf-8', 'Content-Length' => example.raw_data.bytesize.to_s, 'Cache-control' => 'no-cache' } [200, headers, [example.raw_data]] end
present_live(body)
click to toggle source
# File lib/govuk/dummy_content_store/content.rb, line 39 def present_live(body) headers = { 'Content-Type' => 'application/json; charset=utf-8', 'Content-Length' => body.size.to_s, 'Cache-control' => 'no-cache' } [200, headers, [body]] end
present_not_found()
click to toggle source
# File lib/govuk/dummy_content_store/content.rb, line 49 def present_not_found body = 'Not found' headers = { 'Content-Type' => 'text/plain', 'Content-Length' => body.size.to_s, 'Cache-control' => 'no-cache' } [404, headers, [body]] end