lib/event/name_resolver.rb in event-bus-0.2.0 vs lib/event/name_resolver.rb in event-bus-0.2.1
- old
+ new
@@ -16,17 +16,21 @@
constantize(event_id)
else
constantize("#{@default_namespace}::#{camel_case(event_id)}")
end
rescue => e
- raise EventNameResolveError, %(Transforming "#{event_id}" into an event class failed: #{e.message}.)
+ raise EventNameResolveError, %(Transforming "#{event_id}" into an event class failed: #{e.message}.\n\n#{e.backtrace.join("\n")})
end
private
def camel_case(underscored_name)
- underscored_name.to_s.split('_').map { |word| word.upcase[0] + word[1..-1] }.join
+ if RUBY_VERSION < '1.9.3'
+ underscored_name.to_s.split('_').map { |word| word.upcase.chars.to_a[0] + word.chars.to_a[1..-1].join }.join
+ else
+ underscored_name.to_s.split('_').map { |word| word.upcase[0] + word[1..-1] }.join
+ end
end
# Thanks ActiveSupport
# (Only needed to support Ruby 1.9.3 and JRuby)
def constantize(camel_cased_word)
@@ -41,10 +45,16 @@
names.inject(Object) do |constant, name|
if constant == Object
constant.const_get(name)
else
candidate = constant.const_get(name)
- next candidate if constant.const_defined?(name, false)
+
+ if RUBY_VERSION < '1.9.3'
+ next candidate if constant.const_defined?(name)
+ else
+ next candidate if constant.const_defined?(name, false)
+ end
+
next candidate unless Object.const_defined?(name)
# Go down the ancestors to check if it is owned directly. The check
# stops when we reach Object or the end of ancestors tree.
# rubocop:disable Style/EachWithObject