Class: Lax
- Inherits:
-
Array
show all
- Extended by:
- Enumerable
- Defined in:
- lib/lax.rb
Defined Under Namespace
Modules: AssertionGroup, Output, RakeTask
Classes: Assertion
Constant Summary
collapse
- VERSION =
'0.2.3'
- Lazy =
Class.new Proc
- Run =
->(lax=Lax, fin=->(n){n}) do
fin.call lax.select {|l| l.included_modules.include? AssertionGroup}.map(&:new).flatten
end
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.doc ⇒ Object
Returns the value of attribute doc.
18
19
20
|
# File 'lib/lax.rb', line 18
def doc
@doc
end
|
.lings ⇒ Object
Returns the value of attribute lings.
18
19
20
|
# File 'lib/lax.rb', line 18
def lings
@lings
end
|
.src ⇒ Object
Returns the value of attribute src.
18
19
20
|
# File 'lib/lax.rb', line 18
def src
@src
end
|
Class Method Details
.after(&aft) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/lax.rb', line 64
def after(&aft)
->(m) { define_method(:after) do |*a|
instance_exec(*a, &aft)
m.bind(self).call *a
end }.call instance_method :after
end
|
.assert(doc = nil, &spec) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/lax.rb', line 52
def assert(doc=nil,&spec)
scope do
@doc, @src = doc, spec.source_location
include AssertionGroup
before(&spec)
end
end
|
.before(&bef) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/lax.rb', line 45
def before(&bef)
->(m) { define_method(:before) do |*a|
m.bind(self).call *a
instance_exec(*a, &bef)
end }.call instance_method :before
end
|
.each {|_self| ... } ⇒ Object
20
21
22
23
|
# File 'lib/lax.rb', line 20
def each(&b)
yield self
lings.each {|c| c.each(&b)}
end
|
.fix(hash) ⇒ Object
41
42
43
|
# File 'lib/lax.rb', line 41
def fix(hash)
Struct.new(*hash.keys).new *hash.values
end
|
.inherited(ling) ⇒ Object
12
13
14
15
|
# File 'lib/lax.rb', line 12
def self.inherited(ling)
@lings << ling
ling.lings = []
end
|
.lazy ⇒ Object
37
38
39
|
# File 'lib/lax.rb', line 37
def lazy
Lazy.new
end
|
.let(h) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/lax.rb', line 25
def let(h)
h.each do |key, value|
val = (Lazy===value) ? value : lazy{value}
define_singleton_method(key) do |&b|
b ? assert { that val.call.instance_exec(&b) } : val.call
end
define_method(key) do
(@_memo||={}).has_key?(key)? @_memo[key] : @_memo[key] = val.call
end
end
end
|
.matcher(sym, &p) ⇒ Object
71
72
73
|
# File 'lib/lax.rb', line 71
def matcher(sym,&p)
define_method(sym) { satisfies &p}
end
|
.scope(&b) ⇒ Object
60
61
62
|
# File 'lib/lax.rb', line 60
def scope(&b)
Class.new(self, &b)
end
|
Instance Method Details
#after(*a) ⇒ Object
77
|
# File 'lib/lax.rb', line 77
def after(*a); end
|
#before(*a) ⇒ Object
76
|
# File 'lib/lax.rb', line 76
def before(*a); end
|