Module: Scripter::EnvVariables
- Included in:
- Base
- Defined in:
- lib/scripter/env_variables.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #env_variables ⇒ Object
- #raw_env_variables ⇒ Object
-
#type_cast_env_variable(name, value) ⇒ Object
You can override this method in order to add additional typecasts for custom params, but don’t forget to call super in else block of your switch statement.
Class Method Details
.included(receiver) ⇒ Object
5 6 7 |
# File 'lib/scripter/env_variables.rb', line 5 def self.included(receiver) receiver.extend ClassMethods end |
Instance Method Details
#env_variables ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/scripter/env_variables.rb', line 25 def env_variables @env_variables ||= begin env_variables = raw_env_variables.map do |key, value| nomalized_key = key.downcase.to_sym [nomalized_key, type_cast_env_variable(nomalized_key, value)] end Hash[env_variables] end end |
#raw_env_variables ⇒ Object
21 22 23 |
# File 'lib/scripter/env_variables.rb', line 21 def raw_env_variables Hash[command_line_arguments.select{|arg| arg.include?('=')}.map{|arg| arg.split("=")}] end |
#type_cast_env_variable(name, value) ⇒ Object
You can override this method in order to add additional typecasts for custom params, but don’t forget to call super in else block of your switch statement
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/scripter/env_variables.rb', line 37 def type_cast_env_variable(name, value) case name when :date ::Date.parse(value, false) unless value.to_s.empty? when :dry_run, :force_run, :use_cache !value.to_s.empty? else value end end |