Module: Decanter

Defined in:
lib/decanter/parser/compose_parser.rb,
lib/decanter.rb,
lib/decanter/base.rb,
lib/decanter/core.rb,
lib/decanter/parser.rb,
lib/decanter/version.rb,
lib/decanter/exceptions.rb,
lib/decanter/extensions.rb,
lib/decanter/parser/base.rb,
lib/decanter/parser/core.rb,
lib/decanter/parser/utils.rb,
lib/decanter/configuration.rb,
lib/decanter/parser/date_parser.rb,
lib/decanter/parser/hash_parser.rb,
lib/decanter/parser/pass_parser.rb,
lib/decanter/parser/array_parser.rb,
lib/decanter/parser/float_parser.rb,
lib/decanter/parser/phone_parser.rb,
lib/decanter/parser/value_parser.rb,
lib/decanter/parser/string_parser.rb,
lib/decanter/parser/boolean_parser.rb,
lib/decanter/parser/integer_parser.rb,
lib/decanter/parser/datetime_parser.rb,
lib/generators/decanter/install_generator.rb

Overview

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

Defined Under Namespace

Modules: Core, Extensions, Generators, Parser Classes: Base, Configuration, Error, MissingRequiredInputValue, ParseError, Railtie, UnhandledKeysError

Constant Summary collapse

VERSION =
'3.1.0'.freeze

Class Method Summary collapse

Class Method Details

.config {|configuration| ... } ⇒ Object

Yields:



50
51
52
# File 'lib/decanter.rb', line 50

def config
  yield configuration
end

.configurationObject



46
47
48
# File 'lib/decanter.rb', line 46

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

.decanter_for(klass_or_sym) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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.concat('Decanter')
  begin
    decanter_name.constantize
  rescue
    raise NameError.new("uninitialized constant #{decanter_name}")
  end
end

.decanter_from(klass_or_string) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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