Method: Thor::Execution#get_context_value
- Defined in:
- lib/thor/execution.rb
#get_context_value(key, with_source: false) ⇒ Object, Array<(Object, Symbol?, (String | Symbol)?>)
Get the value for a key from the “context”, which is the hierarchy of Thor instance class options, Thor config values and ENV variables.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/thor/execution.rb', line 199 def get_context_value key, with_source: false # 1. First stop is the Thor instance's options (if we have a Thor instance) if thor_instance && thor_instance..key?( key ) if with_source return [thor_instance.[key], :thor_instance_options, key] else return thor_instance.[key] end end # 2. Next, check the config that was handed to `.exec!` if thor_config.key? key if with_source return [thor_config[key], :thor_config, key] else return thor_config[key] end end # 3. Last, check the ENV (returns `nil` if nothing found) get_from_env key, with_source: with_source end |