module Decanter

A parser that composes the results of multiple parsers. Intended for internal use only.

Constants

VERSION

Public Class Methods

config() { |configuration| ... } click to toggle source
# File lib/decanter.rb, line 50
def config
  yield configuration
end
configuration() click to toggle source
# File lib/decanter.rb, line 46
def configuration
  @config ||= Decanter::Configuration.new
end
decanter_for(klass_or_sym) click to toggle source
# File lib/decanter.rb, line 7
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.new("cannot lookup decanter for #{klass_or_sym} with class #{klass_or_sym.class}")
    end + 'Decanter'
  begin
    decanter_name.constantize
  rescue
    raise NameError.new("uninitialized constant #{decanter_name}")
  end
end
decanter_from(klass_or_string) click to toggle source
# File lib/decanter.rb, line 24
def decanter_from(klass_or_string)
  constant =
    case klass_or_string
    when Class
      klass_or_string
    when String
      begin
        klass_or_string.constantize
      rescue
        raise NameError.new("uninitialized constant #{klass_or_string}")
      end
    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