Class: Disposable::Rescheme

Inherits:
Object
  • Object
show all
Defined in:
lib/disposable/rescheme.rb

Overview

Rescheme::from allows to copy a schema structure. This will create “fresh” inline schemas instead of inheriting/copying the original classes, making it a replication of the structure, only.

Options allow to customize the copied schema.

:exclude: ignore options from original Definition when copying.

Provided block is run per newly created Definition.

Rescheme.from(...) { |dfn| dfn[:readable] = true }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(*args, &block) ⇒ Object



11
12
13
# File 'lib/disposable/rescheme.rb', line 11

def self.from(*args, &block)
  new.from(*args, &block)
end

Instance Method Details

#from(source_class, options, &block) ⇒ Object

Builds a new representer (structure only) from source_class.



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

def from(source_class, options, &block) # TODO: can we re-use this for all the decorator logic in #validate, etc?
  representer = build_representer(options)

  definitions = options[:definitions_from].call(source_class)

  definitions.each do |dfn|
    next if (options[:exclude_properties]||{}).include?(dfn[:name].to_sym)

    dfn = build_definition!(options, dfn, representer, &block)
    evaluate_block!(options, dfn, &block)
  end

  representer
end