Module: DynamicSchema::Definable::ClassMethods

Defined in:
lib/dynamic_schema/definable.rb

Instance Method Summary collapse

Instance Method Details

#builderObject



28
29
30
# File 'lib/dynamic_schema/definable.rb', line 28

def builder 
  @_builder ||= DynamicSchema.define( &schema )
end

#schema(&block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dynamic_schema/definable.rb', line 10

def schema( &block )
  @_schema ||= [] 
  if block_given? 
    # note that the memoized builder is reset when schema is called with a new block so 
    # that additions to the schema are incorporated into future builder ( but this does
    # not work if the schema is updated on a superclass after this class' builder has 
    # been returned )
    @_builder = nil 
    @_schema << block 
  end
  schema_blocks = _collect_schema
  proc do
    schema_blocks.each do | block |
      instance_eval( &block )
    end
  end
end