Module: RabbitJobs::Helpers
- Included in:
- Configuration, Consumer::JobConsumer, Job
- Defined in:
- lib/rabbit_jobs/helpers.rb
Instance Method Summary collapse
- #_cleanup_backtrace(trace_lines) ⇒ Object
-
#constantize(camel_cased_word) ⇒ Object
Tries to find a constant with the name specified in the argument string:.
- #symbolize_keys!(hash) ⇒ Object
Instance Method Details
#_cleanup_backtrace(trace_lines) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/rabbit_jobs/helpers.rb', line 5 def _cleanup_backtrace(trace_lines) if defined?(Rails) && Rails.respond_to?(:root) rails_root_path = Rails.root.to_s trace_lines.dup.keep_if { |l| l[rails_root_path] } else trace_lines end end |
#constantize(camel_cased_word) ⇒ Object
Tries to find a constant with the name specified in the argument string:
constantize(“Module”) # => Module constantize(“Test::Unit”) # => Test::Unit
The name is assumed to be the one of a top-level constant, no matter whether it starts with “::” or not. No lexical context is taken into account:
C = ‘outside’ module M
C = 'inside'
C # => 'inside'
constantize("C") # => 'outside', same as ::C
end
NameError is raised when the constant is unknown.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rabbit_jobs/helpers.rb', line 39 def constantize(camel_cased_word) camel_cased_word = camel_cased_word.to_s if camel_cased_word.include?('-') camel_cased_word = classify(camel_cased_word) end names = camel_cased_word.split('::') names.shift if names.empty? || names.first.empty? constant = Object names.each do |name| args = Module.method(:const_get).arity != 1 ? [false] : [] if constant.const_defined?(name, *args) constant = constant.const_get(name) else constant = constant.const_missing(name) end end constant end |
#symbolize_keys!(hash) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/rabbit_jobs/helpers.rb', line 14 def symbolize_keys!(hash) hash.inject({}) do |, (key, value)| [(key.to_sym rescue key) || key] = value end end |