Class: Ditto::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/ditto/entity.rb

Constant Summary collapse

PROPS =
[ :mandatory, :unique, :related ].freeze

Class Method Summary collapse

Class Method Details

.checkObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ditto/entity.rb', line 12

def self.check
  nrel = 0
  nerr = 0
  nkey = 0
  puts "Entities:"
  @entities.each do |name,fields|
	puts name
	fields.each do |field, props|
	  symprops = Array(props).select{|p| p.is_a? Symbol}
	  duffprops = symprops - PROPS
	  unless duffprops.empty?
 puts "unknown properties: #{duffprops.join(' ,')}"
 nerr += 1
	  end
	  nkey += symprops.count(:unique)
	  nrel += symprops.count(:related)
	end
  end
  puts "#{@entities.size} entities, #{nrel} relationships, #{nerr} errors"
  return nerr
end

.define_entity(name, details) ⇒ Object



7
8
9
10
11
# File 'lib/ditto/entity.rb', line 7

def self.define_entity name, details
  raise "Entity details must be a hash!" unless details.kind_of? Hash
  raise "Entity #{name.to_sym} already exists" if @entities.has_key?(name.to_sym)
  @entities[name.to_sym] = details
end