Sha256: a888c4cb5fa4b83edca0346dcac84c698f53a28f29ceb1dac870ec6829d39f13

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

require 'active_support/all'

module Decanter

  class << self

    def decanter_for(klass_or_sym)
      case klass_or_sym
      when Class
        klass_or_sym.name
      when Symbol
        klass_or_sym.to_s.singularize.camelize
      else
        raise ArgumentError.new("cannot lookup decanter for #{klass_or_sym} with class #{klass_or_sym.class}")
      end.concat('Decanter').constantize
    end

    def decanter_from(klass_or_string)
      constant =
        case klass_or_string
        when Class
          klass_or_string
        when String
          klass_or_string.constantize
        else
          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.new("#{constant.name} is not a decanter")
      end

      constant
    end

    def configuration
      @config ||= Decanter::Configuration.new
    end

    def config
      yield configuration
    end
  end

  ActiveSupport.run_load_hooks(:decanter, self)
end

require 'decanter/version'
require 'decanter/configuration'
require 'decanter/core'
require 'decanter/base'
require 'decanter/extensions'
require 'decanter/parser'
require 'decanter/railtie' if defined?(::Rails)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decanter-0.8.2 lib/decanter.rb
decanter-0.8.1 lib/decanter.rb
decanter-0.8.0 lib/decanter.rb
decanter-0.7.2 lib/decanter.rb