Module: Substation::Utils
- Defined in:
- lib/substation/support/utils.rb
Overview
A collection of utility methods
Class Method Summary collapse
-
.coerce_callable(handler) ⇒ Class, Proc
private
Coerce the given
handler
object. -
.const_get(name) ⇒ Class?
private
Get the constant for the given FQN.
-
.symbolize_keys(hash) ⇒ Hash<Symbol, Object>
private
Converts string keys into symbol keys.
Class Method Details
.coerce_callable(handler) ⇒ Class, Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Coerce the given handler
object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/substation/support/utils.rb', line 56 def self.coerce_callable(handler) case handler when Symbol, String Utils.const_get(handler) when Proc, Class, Chain handler else raise(ArgumentError) end end |
.const_get(name) ⇒ Class?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the constant for the given FQN
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/substation/support/utils.rb', line 14 def self.const_get(name) list = name.to_s.split("::") list.shift if list.first.empty? obj = Object list.each do |const| # This is required because const_get tries to look for constants in the # ancestor chain, but we only want constants that are HERE obj = if obj.const_defined?(const) obj.const_get(const) else obj.const_missing(const) end end obj end |
.symbolize_keys(hash) ⇒ Hash<Symbol, Object>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts string keys into symbol keys
40 41 42 43 44 45 |
# File 'lib/substation/support/utils.rb', line 40 def self.symbolize_keys(hash) hash.each_with_object({}) { |(key, value), normalized_hash| normalized_value = value.is_a?(Hash) ? symbolize_keys(value) : value normalized_hash[key.to_sym] = normalized_value } end |