lib/decanter.rb in decanter-2.1.2 vs lib/decanter.rb in decanter-3.0.0

- old
+ new

@@ -1,44 +1,52 @@ -# frozen_string_literal: true - require 'active_support/all' module Decanter + class << self + def decanter_for(klass_or_sym) decanter_name = case klass_or_sym when Class klass_or_sym.name when Symbol klass_or_sym.to_s.singularize.camelize else - raise ArgumentError, "cannot lookup decanter for #{klass_or_sym} with class #{klass_or_sym.class}" - end + 'Decanter' - decanter_name.constantize + raise ArgumentError.new("cannot lookup decanter for #{klass_or_sym} with class #{klass_or_sym.class}") + end.concat('Decanter') + begin + decanter_name.constantize + rescue + raise NameError.new("uninitialized constant #{decanter_name}") + end end def decanter_from(klass_or_string) constant = case klass_or_string when Class klass_or_string when String - klass_or_string.constantize + begin + klass_or_string.constantize + rescue + raise NameError.new("uninitialized constant #{klass_or_string}") + end else - raise ArgumentError, "cannot find decanter from #{klass_or_string} with class #{klass_or_string.class}" + raise ArgumentError.new("cannot find decanter from #{klass_or_string} with class #{klass_or_string.class}") end unless constant.ancestors.include? Decanter::Base - raise ArgumentError, "#{constant.name} is not a decanter" + raise ArgumentError.new("#{constant.name} is not a decanter") end constant end def configuration - @configuration ||= Decanter::Configuration.new + @config ||= Decanter::Configuration.new end def config yield configuration end @@ -52,6 +60,6 @@ require 'decanter/core' require 'decanter/base' require 'decanter/extensions' require 'decanter/exceptions' require 'decanter/parser' -require 'decanter/railtie' if defined?(::Rails) +require 'decanter/railtie' if defined?(::Rails) \ No newline at end of file