Class: Disposable::Twin::Schema

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

Overview

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

Options allow to customize the copied representer.

:exclude: ignore options from original Definition when copying.

Provided block is run per newly created Definition.

Schema.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/twin/schema.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
# File 'lib/disposable/twin/schema.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)

  source_representer = options[:representer_from].call(source_class)

  source_representer.representable_attrs.each do |dfn|
    dfn = build_definition!(options, dfn, representer, &block)
    evaluate_block!(options, dfn, &block)
  end

  representer
end