lispy 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/Rakefile +5 -1
  2. data/lib/lispy.rb +27 -18
  3. data/test/lispy_test.rb +28 -8
  4. metadata +2 -2
data/Rakefile CHANGED
@@ -6,5 +6,9 @@ task :default do
6
6
  end
7
7
 
8
8
  task :run_tests do
9
- require 'test/lispy_test'
9
+ if RUBY_VERSION =~ /^1.9/
10
+ require_relative 'test/lispy_test' # for fuck's sake.
11
+ else
12
+ require 'test/lispy_test'
13
+ end
10
14
  end
@@ -1,26 +1,35 @@
1
1
  class Lispy
2
- VERSION = '0.0.2'
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
- def method_missing(sym, *args, &block)
12
- args = (args.length == 1 ? args.first : args)
13
- @scope.last << [sym, args]
14
- if block
15
- @scope.last << []
16
- @scope.push(@scope.last.last)
17
- instance_exec(&block)
18
- @scope.pop
19
- end
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
- Builder.new._(&block)
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
@@ -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
- assert_equal output, expected_output
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Allen