Class: Kaal::RuntimeContext
- Inherits:
-
Object
- Object
- Kaal::RuntimeContext
- Defined in:
- lib/kaal/runtime/runtime_context.rb
Overview
Resolves environment and path information for plain-Ruby runtime loading.
Constant Summary collapse
- DEFAULT_ENVIRONMENT_NAME =
'development'- ENVIRONMENT_KEYS =
%w[KAAL_ENV RAILS_ENV APP_ENV RACK_ENV].freeze
Instance Attribute Summary collapse
-
#environment_name ⇒ Object
readonly
Returns the value of attribute environment_name.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(root_path:, environment_name:) ⇒ RuntimeContext
constructor
A new instance of RuntimeContext.
- #resolve_path(path) ⇒ Object
Constructor Details
#initialize(root_path:, environment_name:) ⇒ RuntimeContext
Returns a new instance of RuntimeContext.
30 31 32 33 |
# File 'lib/kaal/runtime/runtime_context.rb', line 30 def initialize(root_path:, environment_name:) @root_path = Pathname.new(root_path) @environment_name = environment_name.to_s end |
Instance Attribute Details
#environment_name ⇒ Object (readonly)
Returns the value of attribute environment_name.
15 16 17 |
# File 'lib/kaal/runtime/runtime_context.rb', line 15 def environment_name @environment_name end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
15 16 17 |
# File 'lib/kaal/runtime/runtime_context.rb', line 15 def root_path @root_path end |
Class Method Details
.default(env: ENV, root_path: Dir.pwd) ⇒ Object
17 18 19 |
# File 'lib/kaal/runtime/runtime_context.rb', line 17 def self.default(env: ENV, root_path: Dir.pwd) new(root_path: root_path, environment_name: environment_name_from(env)) end |
.environment_name_from(env) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/kaal/runtime/runtime_context.rb', line 21 def self.environment_name_from(env) ENVIRONMENT_KEYS.each do |key| value = env[key].to_s.strip return value unless value.empty? end DEFAULT_ENVIRONMENT_NAME end |
Instance Method Details
#resolve_path(path) ⇒ Object
35 36 37 38 39 |
# File 'lib/kaal/runtime/runtime_context.rb', line 35 def resolve_path(path) return path.to_s if Pathname.new(path).absolute? root_path.join(path).to_s end |