Module: Val::DSL

Included in:
Val
Defined in:
lib/val.rb

Instance Method Summary collapse

Instance Method Details

#is(array) ⇒ Object



8
9
10
# File 'lib/val.rb', line 8

def is array
  @claims << Claim.new(array)
end

#is_a(type) ⇒ Object



12
13
14
# File 'lib/val.rb', line 12

def is_a type
  is [:is_a?, type]
end

#key(name, *conditions) ⇒ Object



16
17
18
19
# File 'lib/val.rb', line 16

def key name, *conditions
  conditions = [NotNil] if conditions.empty?
  @claims += conditions.map { |condition| Key.new name, condition }
end

#m(name, &block) ⇒ Object



33
34
35
36
37
# File 'lib/val.rb', line 33

def m name, &block
  message = Message.new name
  message.instance_exec &block if block_given?
  @claims << message
end

#NOT(question) ⇒ Object



27
28
29
30
# File 'lib/val.rb', line 27

def NOT question
  claim = -> it { not it.send question }
  @claims << claim
end

#OR(*values) ⇒ Object



22
23
24
25
# File 'lib/val.rb', line 22

def OR *values
  claim = -> it { values.any? &[:===, it] }
  @claims << claim
end

#val(&block) ⇒ Object



3
4
5
# File 'lib/val.rb', line 3

def val &block
  self.class.new &block
end