Module: SumsUp::Core

Defined in:
lib/sums_up/core.rb,
lib/sums_up/core/parser.rb,
lib/sums_up/core/matcher.rb,
lib/sums_up/core/strings.rb,
lib/sums_up/core/variant.rb,
lib/sums_up/core/sum_type.rb,
lib/sums_up/core/functions.rb

Overview

Core functionality which builds modules for sum types and classes for variants.

Defined Under Namespace

Modules: Functions, Parser, Strings Classes: Matcher, SumType, Variant

Class Method Summary collapse

Class Method Details

.define(*no_arg_variants, **arg_variants, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sums_up/core.rb', line 16

def define(*no_arg_variants, **arg_variants, &block)
  variant_specs = Parser.parse_variant_specs!(no_arg_variants, arg_variants)
  variant_names = variant_specs.keys

  variant_classes = variant_specs.map do |name, members|
    others = variant_names - [name]
    matcher_class = Matcher.build_matcher_class(name, others)

    Variant.build_variant_class(name, others, members, matcher_class)
  end

  SumType
    .build(variant_classes)
    .tap { |sum_type| sum_type.module_eval(&block) if block }
end