Class: Timber::Contexts::Release
- Inherits:
-
Timber::Context
- Object
- Timber::Context
- Timber::Contexts::Release
- Defined in:
- lib/timber/contexts/release.rb
Overview
To automatically set this context, see Release.from_env.
The release context tracks application releases / versions / deploys.
Instance Attribute Summary collapse
-
#commit_hash ⇒ Object
readonly
Returns the value of attribute commit_hash.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.from_env ⇒ Object
Builds a release context based on environment variables.
Instance Method Summary collapse
-
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
-
#initialize(attributes) ⇒ Release
constructor
A new instance of Release.
Constructor Details
#initialize(attributes) ⇒ Release
Returns a new instance of Release.
38 39 40 41 42 |
# File 'lib/timber/contexts/release.rb', line 38 def initialize(attributes) @commit_hash = attributes[:commit_hash] @created_at = attributes[:created_at] @version = attributes[:version] end |
Instance Attribute Details
#commit_hash ⇒ Object (readonly)
Returns the value of attribute commit_hash.
36 37 38 |
# File 'lib/timber/contexts/release.rb', line 36 def commit_hash @commit_hash end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
36 37 38 |
# File 'lib/timber/contexts/release.rb', line 36 def created_at @created_at end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
36 37 38 |
# File 'lib/timber/contexts/release.rb', line 36 def version @version end |
Class Method Details
.from_env ⇒ Object
Builds a release context based on environment variables. Simply add the ‘RELEASE_COMMIT`, `RELEASE_CREATED_AT`, or the `RELEASE_VERSION` env vars to get this context automatially. All are optional, but at least one must be present.
If you’re on Heroku, simply enable dyno metadata to get this automatically: devcenter.heroku.com/articles/dyno-metadata
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/timber/contexts/release.rb', line 21 def from_env commit_hash = ENV['RELEASE_COMMIT'] || ENV['HEROKU_SLUG_COMMIT'] created_at = ENV['RELEASE_CREATED_AT'] || ENV['HEROKU_RELEASE_CREATED_AT'] version = ENV['RELEASE_VERSION'] || ENV['HEROKU_RELEASE_VERSION'] if commit_hash || created_at || version Timber::Config.instance.debug { "Release env vars detected, adding to context" } new(commit_hash: commit_hash, created_at: created_at, version: version) else Timber::Config.instance.debug { "Release env vars _not_ detected" } nil end end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
45 46 47 |
# File 'lib/timber/contexts/release.rb', line 45 def as_json( = {}) {commit_hash: commit_hash, created_at: created_at, version: version} end |