Module: Parametric::DSL::ClassMethods

Defined in:
lib/parametric/dsl.rb

Instance Method Summary collapse

Instance Method Details

#inherited(subclass) ⇒ Object



43
44
45
46
47
# File 'lib/parametric/dsl.rb', line 43

def inherited(subclass)
  subclass.schemas = @schemas.each_with_object({}) do |(key, sc), hash|
    hash[key] = sc.merge(Parametric::Schema.new)
  end
end

#parametric_after_define_schema(sc) ⇒ Object



65
66
67
# File 'lib/parametric/dsl.rb', line 65

def parametric_after_define_schema(sc)
  # noop hook
end

#schema(*args, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/parametric/dsl.rb', line 49

def schema(*args, &block)
  options = args.last.is_a?(Hash) ? args.last : {}
  key = args.first.is_a?(Symbol) ? args.first : DEFAULT_SCHEMA_NAME
  current_schema = @schemas.fetch(key) { Parametric::Schema.new }
  new_schema = if block_given? || options.any?
    Parametric::Schema.new(options, &block)
  elsif args.first.respond_to?(:schema)
    args.first
  end

  return current_schema unless new_schema

  @schemas[key] = current_schema ? current_schema.merge(new_schema) : new_schema
  parametric_after_define_schema(@schemas[key])
end

#schema=(sc) ⇒ Object



35
36
37
# File 'lib/parametric/dsl.rb', line 35

def schema=(sc)
  @schemas[DEFAULT_SCHEMA_NAME] = sc
end

#schemas=(sc) ⇒ Object



39
40
41
# File 'lib/parametric/dsl.rb', line 39

def schemas=(sc)
  @schemas = sc
end