Module: Ccd::Dsl

Defined in:
lib/ccd/dsl.rb

Defined Under Namespace

Classes: CardinalityError

Instance Method Summary collapse

Instance Method Details

#constraint(*args) ⇒ Object



16
17
18
# File 'lib/ccd/dsl.rb', line 16

def constraint(*args)
  add_constraint(*args)
end

#dump(path) ⇒ Object



20
21
22
23
24
# File 'lib/ccd/dsl.rb', line 20

def dump(path)
  File.open(File.join(path, "#{self.name.underscore}.yml"), 'w') do |f|
    f.puts defaults.to_yaml
  end
end

#validate!(object) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/ccd/dsl.rb', line 26

def validate!(object)
  (@cardinalities || {}).each do |name, card|
    case card
      when '1..1'
        value = name.split('.').reduce(object) { |obj, chunk| obj.__send__(chunk) }
        raise CardinalityError.new(object, name) unless value
    end
  end
end