lispy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -1
- data/lib/lispy.rb +27 -18
- data/test/lispy_test.rb +28 -8
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/lispy.rb
CHANGED
@@ -1,26 +1,35 @@
|
|
1
1
|
class Lispy
|
2
|
-
VERSION = '0.0.
|
3
|
-
class Builder
|
4
|
-
def _(&block)
|
5
|
-
@output = []
|
6
|
-
@scope = [@output]
|
7
|
-
instance_exec(&block)
|
8
|
-
@output
|
9
|
-
end
|
2
|
+
VERSION = '0.0.3'
|
10
3
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
4
|
+
@@methods_to_keep = /^__/, /class/, /instance_/, /method_missing/, /object_id/
|
5
|
+
|
6
|
+
instance_methods.each do |m|
|
7
|
+
undef_method m unless @@methods_to_keep.find { |r| r.match m }
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(sym, *args, &block)
|
11
|
+
args = (args.length == 1 ? args.first : args)
|
12
|
+
@scope.last << [sym, args]
|
13
|
+
if block
|
14
|
+
# there is some simpler recursive way of doing this, will fix it shortly
|
15
|
+
@scope.last.last << []
|
16
|
+
@scope.push(@scope.last.last.last)
|
17
|
+
instance_exec(&block)
|
18
|
+
@scope.pop
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
22
|
def to_data(&block)
|
24
|
-
|
23
|
+
_(&block)
|
24
|
+
@output
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def _(&block)
|
30
|
+
@output = []
|
31
|
+
@scope = [@output]
|
32
|
+
instance_exec(&block)
|
33
|
+
@output
|
25
34
|
end
|
26
35
|
end
|
data/test/lispy_test.rb
CHANGED
@@ -18,14 +18,34 @@ class LispyTest < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
expected_output = [[:setup, {:workers=>30, :connections=>1024}],
|
22
|
-
[:http, {:access_log=>:off}],
|
23
|
-
[[:server, {:listen=>80}],
|
24
|
-
[[:location, "/"],
|
25
|
-
[[:doc_root, "/var/www/website"]],
|
26
|
-
[:location, "~ .php$"],
|
27
|
-
[[:fcgi, {:port=>8877}], [:script_root, "/var/www/website"]]]]]
|
28
21
|
|
29
|
-
|
22
|
+
expected = [[:setup, {:workers=>30, :connections=>1024}],
|
23
|
+
[:http,
|
24
|
+
{:access_log=>:off},
|
25
|
+
[[:server,
|
26
|
+
{:listen=>80},
|
27
|
+
[[:location, "/", [[:doc_root, "/var/www/website"]]],
|
28
|
+
[:location,
|
29
|
+
"~ .php$",
|
30
|
+
[[:fcgi, {:port=>8877}], [:script_root, "/var/www/website"]]]]]]]]
|
31
|
+
|
32
|
+
assert_equal expected, output
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_moar_lispy
|
36
|
+
output = Lispy.new.to_data do
|
37
|
+
setup
|
38
|
+
setup do
|
39
|
+
lol
|
40
|
+
lol do
|
41
|
+
hi
|
42
|
+
hi
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
expected = [[:setup, []], [:setup, [], [[:lol, []], [:lol, [], [[:hi, []], [:hi, []]]]]]]
|
48
|
+
|
49
|
+
assert_equal expected, output
|
30
50
|
end
|
31
51
|
end
|