Module: DbAgile::Core::Schema::Computations::Split

Included in:
DbAgile::Core::Schema::Computations
Defined in:
lib/dbagile/core/schema/computations/split.rb

Constant Summary collapse

DEFAULT_OPTIONS =

Default split options

{}

Instance Method Summary collapse

Instance Method Details

#split(schema, options, &block) ⇒ Object

Computes set difference between schemas.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dbagile/core/schema/computations/split.rb', line 11

def split(schema, options, &block)

  # Build the split hash
  split_hash = Hash.new{|h,k| h[k] = []}
  schema.visit{|object, parent|
    if object.part?
      kind = block.call(object)
      split_hash[kind] << object
    end
  }
  
  # Rebuild schemas now
  schemas = {}
  split_hash.keys.each{|kind|
    split_proc    = lambda{|obj| split_hash[kind].include?(obj)}
    split_options = {:identifier => kind}
    schemas[kind] = Schema::filter(schema, split_options, &split_proc)
  }
  schemas
end