Class: Propr::Dsl::Property

Inherits:
Object show all
Defined in:
lib/propr/dsl/property.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, m) ⇒ Property

Returns a new instance of Property.



28
29
30
31
# File 'lib/propr/dsl/property.rb', line 28

def initialize(block, m)
  @context, @m =
    Kernel.eval("self", block.binding), m
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



55
56
57
# File 'lib/propr/dsl/property.rb', line 55

def method_missing(name, *args, &block)
  @context.__send__(name, *args, &block)
end

Instance Attribute Details

#mObject (readonly)

Properties shouldn’t be monadic, as all random data is generated elsewhere and passed as arguments to the property. However, this provides a workaround: m.eval, m.unit, m.bind, etc where ‘m` is given as an argument to `wrap`.



10
11
12
# File 'lib/propr/dsl/property.rb', line 10

def m
  @m
end

Class Method Details

.wrap(block, m = Propr::Random) ⇒ Object

Generates a new function, which should return a Boolean



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/propr/dsl/property.rb', line 13

def self.wrap(block, m = Propr::Random)
  case block.arity
  when 0; lambda{|| new(block, m).instance_exec(&block) }
  when 1; lambda{|a| new(block, m).instance_exec(a,&block) }
  when 2; lambda{|a,b| new(block, m).instance_exec(a,b,&block) }
  when 3; lambda{|a,b,c| new(block, m).instance_exec(a,b,c,&block) }
  when 4; lambda{|a,b,c,d| new(block, m).instance_exec(a,b,c,d &block) }
  when 5; lambda{|a,b,c,d,e| new(block, m).instance_exec(a,b,c,d,e,&block) }
  when 6; lambda{|a,b,c,d,e,f| new(block, m).instance_exec(a,b,c,d,e,f,&block) }
  when 7; lambda{|a,b,c,d,e,f,g| new(block, m).instance_exec(a,b,c,d,e,f,g,&block) }
  when 8; lambda{|a,b,c,d,e,f,g,h| new(block, m).instance_exec(a,b,c,d,e,f,g,h,&block) }
  else    lambda{|*args| new(block, m).instance_exec(*args,&block) }
  end
end

Instance Method Details

#error?(type = Exception) ⇒ Boolean

Returns:



33
34
35
36
37
38
39
40
# File 'lib/propr/dsl/property.rb', line 33

def error?(type = Exception)
  begin
    yield
    false
  rescue => e
    e.is_a?(type)
  end
end

#guard(*conditions) ⇒ Object



42
43
44
45
46
47
# File 'lib/propr/dsl/property.rb', line 42

def guard(*conditions)
  if index = conditions.index{|x| not x }
    raise GuardFailure,
      "guard condition #{index} was false"
  end
end

#label(value) ⇒ Object



49
50
51
# File 'lib/propr/dsl/property.rb', line 49

def label(value)
  # @todo
end