Sha256: 4cc7daf2d8e498c1b9a7c9d824a8fdbab717a40166523a13a2f65970a24ba4b9

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 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
  end

  ActiveSupport.run_load_hooks(:decanter, self)
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decanter-0.7.1 lib/decanter.rb