Class: Cartage::Rack::Metadata
- Inherits:
-
Object
- Object
- Cartage::Rack::Metadata
- Defined in:
- lib/cartage/rack/metadata.rb
Overview
A representation for Cartage metadata for use with Cartage::Rack and Cartage::Rack::Simple.
Instance Method Summary collapse
-
#initialize(root_path = nil, required: Cartage::Rack.require_metadata, filter: nil) ⇒ Metadata
constructor
Parse static release metadata from the
root_path(or Dir.pwd) and prepare the Metadata object for resolution. -
#inspect ⇒ Object
:nodoc:.
-
#resolve ⇒ Object
Resolve the metadata content with the application environment.
Constructor Details
#initialize(root_path = nil, required: Cartage::Rack.require_metadata, filter: nil) ⇒ Metadata
Parse static release metadata from the root_path (or Dir.pwd)
and prepare the Metadata object for resolution.
If filter is provided, it should be a callable (a lambda or proc) that
will manipulate the content on resolution.
If required is true (defaults to the value of
Cartage::Rack.require_metadata, which is true for everything except
development and test), then a RuntimeError will be thrown if there is
no static release metadata.
If required is false, then the release metadata can be loaded from the
active environment.
29 30 31 32 33 34 35 36 37 |
# File 'lib/cartage/rack/metadata.rb', line 29 def initialize(root_path = nil, required: Cartage::Rack., filter: nil) @root_path = Pathname(root_path || Dir.pwd) @filter = filter @content = || read_release_hashref fail "Cannot find release-metadata.json or release_hashref" if required && !@content @source ||= :live end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/cartage/rack/metadata.rb', line 48 def inspect # :nodoc: "#{@root_path.expand_path.basename} (#{@source})" end |
#resolve ⇒ Object
Resolve the metadata content with the application environment. If a
filter was provided on object construction, apply it do the merged
content data.
42 43 44 45 46 |
# File 'lib/cartage/rack/metadata.rb', line 42 def resolve content.merge(application_env).tap do |data| @filter&.call(data) end.delete_if(&METADATA_CLEANER) end |