Module: Paradocs::DSL::ClassMethods

Defined in:
lib/paradocs/dsl.rb

Instance Method Summary collapse

Instance Method Details

#inherited(subclass) ⇒ Object



40
41
42
43
44
# File 'lib/paradocs/dsl.rb', line 40

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

#paradocs_after_define_schema(sc) ⇒ Object



63
64
65
# File 'lib/paradocs/dsl.rb', line 63

def paradocs_after_define_schema(sc)
  # noop hook
end

#schema(*args, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/paradocs/dsl.rb', line 46

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

  return current_schema unless new_schema

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

#schema=(sc) ⇒ Object



32
33
34
# File 'lib/paradocs/dsl.rb', line 32

def schema=(sc)
  @schemas[Paradocs.config.default_schema_name] = sc
end

#schemas=(sc) ⇒ Object



36
37
38
# File 'lib/paradocs/dsl.rb', line 36

def schemas=(sc)
  @schemas = sc
end