Class: Cartage::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/cartage/rack.rb,
lib/cartage/rack/simple.rb

Overview

Cartage::Rack is a simple application that reads an application’s static release metadata and returns it as an (optionally filtered) application/json value, or as a text/plain string if called with .text or .txt.

Direct Known Subclasses

Simple

Defined Under Namespace

Classes: Metadata, Simple

Constant Summary collapse

VERSION =

:nodoc:

'2.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path = nil, &filter) ⇒ Rack

:nodoc:



39
40
41
# File 'lib/cartage/rack.rb', line 39

def initialize(root_path = nil, &filter) # :nodoc:
  @metadata = Cartage::Rack::Metadata.new(root_path, filter: filter)
end

Class Method Details

.mount(root_path = nil) ⇒ Object

Creates a new instance of the Cartage::Rack::Simple application to the specified root_path, or Dir.pwd. This method has been deprecated.



8
9
10
11
12
13
# File 'lib/cartage/rack/simple.rb', line 8

def mount(root_path = nil)
  warn <<-warning
Cartage::Rack.mount(path) is deprecated; use Cartage::Rack::Simple(path) instead.
  warning
  Simple(root_path)
end

.require_metadata(value = (arg = false; nil)) ⇒ Object

When true, Cartage::Rack and Cartage::Rack::Simple will raise an exception if there is no metadata file (release-metadata.json or release_hashref). May be explicitly turned off.

Defaults to true except in development or test environments (based on $RAILS_ENV and $RACK_ENV).



27
28
29
30
# File 'lib/cartage/rack.rb', line 27

def (value = (arg = false; nil)) # rubocop:disable Style/Semicolon
  @require_metadata = value unless arg == false
  @require_metadata || 
end

.Simple(root_path = nil) ⇒ Object

Generate and mount the simple metadata reporter, Cartage::Rack::Simple, for the application at root_path or Dir.pwd.



17
18
19
# File 'lib/cartage/rack/simple.rb', line 17

def Simple(root_path = nil)
  Cartage::Rack::Simple.new(root_path)
end

Instance Method Details

#call(env) ⇒ Object

:nodoc:



43
44
45
46
# File 'lib/cartage/rack.rb', line 43

def call(env) #:nodoc:
  type, body = resolve_content(env)
  [ '200', { 'Content-Type' => type }, [ body ] ]
end

#inspectObject

:nodoc:



48
49
50
# File 'lib/cartage/rack.rb', line 48

def inspect #:nodoc:
  "#{self.class} for #{@metadata.inspect}"
end