Class: Capsium::Reactor::ContentApi

Inherits:
Object
  • Object
show all
Includes:
Responses
Defined in:
lib/capsium/reactor/content_api.rb,
sig/capsium/reactor/content_api.rbs

Overview

Content writes over the mount's overlay (ARCHITECTURE.md section 5a): PUT creates/overwrites a content file, DELETE records a tombstone. Text bodies only for v1.

Constant Summary collapse

WRITE_METHODS =

Returns:

%w[PUT DELETE].freeze
CONTENT_PREFIX =

Returns:

"#{Package::CONTENT_DIR}/".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Responses

#respond_error, #respond_forbidden, #respond_json, #respond_method_not_allowed, #respond_not_found, #respond_not_implemented, #respond_text

Constructor Details

#initialize(mount) ⇒ ContentApi

Returns a new instance of ContentApi.

Parameters:



22
23
24
# File 'lib/capsium/reactor/content_api.rb', line 22

def initialize(mount)
  @mount = mount
end

Class Method Details

.write_method?(method) ⇒ Boolean

Parameters:

Returns:



18
19
20
# File 'lib/capsium/reactor/content_api.rb', line 18

def self.write_method?(method)
  WRITE_METHODS.include?(method)
end

Instance Method Details

#handle(inner_path, request, response) ⇒ Object

Parameters:

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/capsium/reactor/content_api.rb', line 26

def handle(inner_path, request, response)
  return read_only(response) unless @mount.writable?

  route = @mount.routes.resolve(inner_path)
  return guard_route(route, inner_path, response) if route && !writable_route?(route)

  case request.request_method
  when "PUT" then put_content(inner_path, route, request, response)
  when "DELETE" then delete_content(inner_path, route, response)
  else respond_method_not_allowed(response)
  end
end