srizzo-irber 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.rdoc +13 -10
- data/VERSION +1 -1
- data/features/get_a_generated_source_code_on_the_fly.feature +22 -72
- data/features/print_generated_source_code.feature +52 -0
- data/features/step_definitions/irber_steps.rb +5 -0
- data/features/support/env.rb +0 -1
- data/irber.gemspec +5 -1
- data/lib/irber/src.rb +12 -0
- data/lib/irber/to_code.rb +3 -1
- data/lib/irber.rb +2 -1
- data/spec/custom_helpers.rb +9 -0
- data/spec/irber/src_spec.rb +28 -0
- data/spec/irber/to_code_spec.rb +88 -86
- data/spec/spec_helper.rb +1 -1
- metadata +5 -1
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -26,14 +26,16 @@ Given a class:
|
|
26
26
|
|
27
27
|
Generate source code on the fly:
|
28
28
|
|
29
|
-
>>
|
29
|
+
>> src A
|
30
30
|
class A < Object
|
31
31
|
def a()
|
32
32
|
"a"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
=> nil
|
36
|
-
|
36
|
+
|
37
|
+
|
38
|
+
>> src A, :a
|
37
39
|
def a()
|
38
40
|
"a"
|
39
41
|
end
|
@@ -42,20 +44,21 @@ Generate source code on the fly:
|
|
42
44
|
|
43
45
|
* make an object print itself
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
>> [1,2].puts_it
|
48
|
+
1
|
49
|
+
2
|
50
|
+
|
51
|
+
|
52
|
+
>> [1,2].pp_it
|
53
|
+
[1, 2]
|
51
54
|
|
52
55
|
|
53
56
|
|
54
57
|
|
55
58
|
== FEATURES/PROBLEMS:
|
56
59
|
|
57
|
-
* generate a class or method source code on the fly
|
58
|
-
*
|
60
|
+
* generate a class or method source code on the fly (won't work for all classes and methods e.g: native classes)
|
61
|
+
* make an object print itself
|
59
62
|
|
60
63
|
|
61
64
|
== REQUIREMENTS:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -3,7 +3,8 @@ Feature: get a generated source code on the fly
|
|
3
3
|
As a lazy programmer
|
4
4
|
I want to get a generated source code on the fly
|
5
5
|
|
6
|
-
|
6
|
+
|
7
|
+
Background:
|
7
8
|
Given the definition
|
8
9
|
"""
|
9
10
|
class A
|
@@ -15,33 +16,35 @@ Feature: get a generated source code on the fly
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
"""
|
18
|
-
And
|
19
|
-
When I run "A.to_code"
|
20
|
-
Then I should get the code
|
19
|
+
And the definition
|
21
20
|
"""
|
22
|
-
|
23
|
-
def
|
24
|
-
|
21
|
+
module M
|
22
|
+
def a_method
|
23
|
+
"result"
|
25
24
|
end
|
26
|
-
def self.
|
27
|
-
|
25
|
+
def self.a_module_method
|
26
|
+
"result"
|
28
27
|
end
|
29
28
|
end
|
30
29
|
"""
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
And I have required "irber/to_code"
|
31
|
+
|
32
|
+
|
33
|
+
Scenario: get source for a class
|
34
|
+
When I run "A.to_code"
|
35
|
+
Then I should get the code
|
34
36
|
"""
|
35
|
-
class A
|
36
|
-
def an_instance_method
|
37
|
+
class A < Object
|
38
|
+
def an_instance_method()
|
37
39
|
"result"
|
38
40
|
end
|
39
|
-
def self.a_class_method
|
41
|
+
def self.a_class_method()
|
40
42
|
"result"
|
41
43
|
end
|
42
44
|
end
|
43
45
|
"""
|
44
|
-
|
46
|
+
|
47
|
+
Scenario: get source for an object
|
45
48
|
When I run "A.new.to_code"
|
46
49
|
Then I should get the code
|
47
50
|
"""
|
@@ -55,19 +58,7 @@ Feature: get a generated source code on the fly
|
|
55
58
|
end
|
56
59
|
"""
|
57
60
|
|
58
|
-
Scenario:
|
59
|
-
Given the definition
|
60
|
-
"""
|
61
|
-
module M
|
62
|
-
def a_method
|
63
|
-
"result"
|
64
|
-
end
|
65
|
-
def self.a_module_method
|
66
|
-
"result"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
"""
|
70
|
-
And I have required "irber/to_code"
|
61
|
+
Scenario: get source for a module
|
71
62
|
When I run "M.to_code"
|
72
63
|
Then I should get the code
|
73
64
|
"""
|
@@ -82,19 +73,7 @@ Feature: get a generated source code on the fly
|
|
82
73
|
"""
|
83
74
|
|
84
75
|
|
85
|
-
Scenario:
|
86
|
-
Given the definition
|
87
|
-
"""
|
88
|
-
class A
|
89
|
-
def an_instance_method
|
90
|
-
"result"
|
91
|
-
end
|
92
|
-
def self.a_class_method
|
93
|
-
"result"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
"""
|
97
|
-
And I have required "irber/to_code"
|
76
|
+
Scenario: get source for a class method
|
98
77
|
When I run "A.to_code :a_class_method"
|
99
78
|
Then I should get the code
|
100
79
|
"""
|
@@ -103,19 +82,7 @@ Feature: get a generated source code on the fly
|
|
103
82
|
end
|
104
83
|
"""
|
105
84
|
|
106
|
-
Scenario:
|
107
|
-
Given the definition
|
108
|
-
"""
|
109
|
-
class A
|
110
|
-
def an_instance_method
|
111
|
-
"result"
|
112
|
-
end
|
113
|
-
def self.a_class_method
|
114
|
-
"result"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
"""
|
118
|
-
And I have required "irber/to_code"
|
85
|
+
Scenario: get source for an object method
|
119
86
|
When I run "A.new.to_code :an_instance_method"
|
120
87
|
Then I should get the code
|
121
88
|
"""
|
@@ -125,27 +92,10 @@ Feature: get a generated source code on the fly
|
|
125
92
|
"""
|
126
93
|
|
127
94
|
Scenario: try to get an inexisting method
|
128
|
-
Given the definition
|
129
|
-
"""
|
130
|
-
class A
|
131
|
-
def an_instance_method
|
132
|
-
"result"
|
133
|
-
end
|
134
|
-
def self.a_class_method
|
135
|
-
"result"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
"""
|
139
|
-
And I have required "irber/to_code"
|
140
95
|
When I run "A.new.to_code :an_inexisting_method"
|
141
96
|
Then I should get the error "NameError"
|
142
97
|
|
143
98
|
Scenario: try on native code
|
144
99
|
Given a native implemented class "String"
|
145
|
-
And I have required "irber/to_code"
|
146
100
|
When I run "String.to_code"
|
147
101
|
Then I should get the error "ParseError"
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
@@ -0,0 +1,52 @@
|
|
1
|
+
Feature: print generated source code
|
2
|
+
In order to save time looking for source code
|
3
|
+
As a lazy programmer
|
4
|
+
I want a method that generates and prints source code
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given the definition
|
10
|
+
"""
|
11
|
+
class A
|
12
|
+
def an_instance_method
|
13
|
+
"result"
|
14
|
+
end
|
15
|
+
def self.a_class_method
|
16
|
+
"result"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
"""
|
20
|
+
And I have required "irber/src"
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
Scenario: print source for a class
|
25
|
+
When I run "src A"
|
26
|
+
Then I should have the code printed
|
27
|
+
"""
|
28
|
+
class A < Object
|
29
|
+
def an_instance_method()
|
30
|
+
"result"
|
31
|
+
end
|
32
|
+
def self.a_class_method()
|
33
|
+
"result"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
"""
|
38
|
+
|
39
|
+
Scenario: print source for a class
|
40
|
+
When I run "src A, :an_instance_method"
|
41
|
+
Then I should have the code printed
|
42
|
+
"""
|
43
|
+
def an_instance_method()
|
44
|
+
"result"
|
45
|
+
end
|
46
|
+
|
47
|
+
"""
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
data/features/support/env.rb
CHANGED
data/irber.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{irber}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["srizzo"]
|
@@ -22,15 +22,18 @@ Gem::Specification.new do |s|
|
|
22
22
|
"VERSION",
|
23
23
|
"features/get_a_generated_source_code_on_the_fly.feature",
|
24
24
|
"features/make_an_object_print_itself.feature",
|
25
|
+
"features/print_generated_source_code.feature",
|
25
26
|
"features/step_definitions/irber_steps.rb",
|
26
27
|
"features/support/env.rb",
|
27
28
|
"irber.gemspec",
|
28
29
|
"lib/irber.rb",
|
29
30
|
"lib/irber/printing.rb",
|
31
|
+
"lib/irber/src.rb",
|
30
32
|
"lib/irber/to_code.rb",
|
31
33
|
"spec/custom_helpers.rb",
|
32
34
|
"spec/custom_matchers.rb",
|
33
35
|
"spec/irber/printing_spec.rb",
|
36
|
+
"spec/irber/src_spec.rb",
|
34
37
|
"spec/irber/to_code_spec.rb",
|
35
38
|
"spec/spec_helper.rb"
|
36
39
|
]
|
@@ -44,6 +47,7 @@ Gem::Specification.new do |s|
|
|
44
47
|
"spec/custom_helpers.rb",
|
45
48
|
"spec/custom_matchers.rb",
|
46
49
|
"spec/irber/printing_spec.rb",
|
50
|
+
"spec/irber/src_spec.rb",
|
47
51
|
"spec/irber/to_code_spec.rb",
|
48
52
|
"spec/spec_helper.rb"
|
49
53
|
]
|
data/lib/irber/src.rb
ADDED
data/lib/irber/to_code.rb
CHANGED
data/lib/irber.rb
CHANGED
data/spec/custom_helpers.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require "irber/src"
|
4
|
+
|
5
|
+
class A
|
6
|
+
def an_instance_method
|
7
|
+
"result"
|
8
|
+
end
|
9
|
+
def self.a_class_method
|
10
|
+
"result"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe "Kernel#src" do
|
16
|
+
|
17
|
+
it "should print a class source" do
|
18
|
+
@a = A.new
|
19
|
+
stdout{ src @a }.should == stdout{ puts @a.to_code }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should print a method source" do
|
23
|
+
@a = A.new
|
24
|
+
stdout{ src @a, :an_instance_method }.should == stdout{ puts @a.to_code :an_instance_method }
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
data/spec/irber/to_code_spec.rb
CHANGED
@@ -23,119 +23,121 @@ end
|
|
23
23
|
|
24
24
|
describe Irber::ToCode do
|
25
25
|
|
26
|
-
describe "on classes" do
|
27
|
-
it "should be available on all classes" do
|
28
|
-
A.should respond_to(:to_code)
|
29
|
-
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
27
|
+
describe "#to_code" do
|
28
|
+
|
29
|
+
describe "on classes" do
|
30
|
+
it "should be available on all classes" do
|
31
|
+
A.should respond_to(:to_code)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should generate its source code" do
|
35
|
+
A.to_code.should match_code "
|
36
|
+
class A < Object
|
37
|
+
def an_instance_method()
|
38
|
+
\"result\"
|
39
|
+
end
|
40
|
+
def self.a_class_method()
|
41
|
+
\"result\"
|
42
|
+
end
|
39
43
|
end
|
40
|
-
|
41
|
-
|
44
|
+
"
|
45
|
+
end
|
42
46
|
end
|
43
|
-
end
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
describe "on objects" do
|
49
|
+
it "should be available on all objects" do
|
50
|
+
A.new.should respond_to(:to_code)
|
51
|
+
end
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
it "should generate its source code" do
|
54
|
+
A.new.to_code.should match_code "
|
55
|
+
class A < Object
|
56
|
+
def an_instance_method()
|
57
|
+
\"result\"
|
58
|
+
end
|
59
|
+
def self.a_class_method()
|
60
|
+
\"result\"
|
61
|
+
end
|
55
62
|
end
|
56
|
-
|
57
|
-
|
63
|
+
"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "on modules" do
|
69
|
+
it "should generat its source code" do
|
70
|
+
M.to_code.should match_code "
|
71
|
+
module M
|
72
|
+
def a_method()
|
73
|
+
\"result\"
|
74
|
+
end
|
75
|
+
def self.a_module_method()
|
76
|
+
\"result\"
|
77
|
+
end
|
58
78
|
end
|
59
|
-
|
60
|
-
|
79
|
+
"
|
80
|
+
end
|
61
81
|
end
|
62
|
-
|
63
|
-
end
|
64
82
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def a_method()
|
83
|
+
describe "on class methods" do
|
84
|
+
it "should generate a class instance method source code " do
|
85
|
+
A.to_code(:an_instance_method).should match_code "
|
86
|
+
def an_instance_method()
|
70
87
|
\"result\"
|
71
88
|
end
|
72
|
-
|
89
|
+
"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should generate a class method source code " do
|
93
|
+
A.to_code(:a_class_method).should match_code "
|
94
|
+
def a_class_method()
|
73
95
|
\"result\"
|
74
96
|
end
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "on class methods" do
|
81
|
-
it "should generate a class instance method source code " do
|
82
|
-
A.to_code(:an_instance_method).should match_code "
|
83
|
-
def an_instance_method()
|
84
|
-
\"result\"
|
85
|
-
end
|
86
|
-
"
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should generate a class method source code " do
|
90
|
-
A.to_code(:a_class_method).should match_code "
|
91
|
-
def a_class_method()
|
92
|
-
\"result\"
|
93
|
-
end
|
94
|
-
"
|
97
|
+
"
|
98
|
+
end
|
95
99
|
end
|
96
|
-
end
|
97
100
|
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
describe "on object methods" do
|
103
|
+
it "should generate an object method source code" do
|
104
|
+
A.new.to_code(:an_instance_method).should match_code "
|
105
|
+
def an_instance_method()
|
106
|
+
\"result\"
|
107
|
+
end
|
108
|
+
"
|
109
|
+
end
|
106
110
|
end
|
107
|
-
end
|
108
111
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
describe "on module methods" do
|
113
|
+
it "should generate a module method source code" do
|
114
|
+
M.to_code(:a_method).should match_code "
|
115
|
+
def a_method()
|
116
|
+
\"result\"
|
117
|
+
end
|
118
|
+
"
|
119
|
+
end
|
116
120
|
end
|
117
|
-
end
|
118
121
|
|
119
122
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
+
describe "on inexisting methods" do
|
124
|
+
it "should raise NameError" do
|
125
|
+
lambda{ A.new.to_code(:an_inexisting_method) }.should raise_error(NameError)
|
126
|
+
end
|
123
127
|
end
|
124
|
-
end
|
125
128
|
|
126
129
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
+
describe "on native classes" do
|
131
|
+
it "should raise ParseError" do
|
132
|
+
lambda{ String.to_code }.should raise_error(ParseError)
|
133
|
+
end
|
130
134
|
end
|
131
|
-
end
|
132
135
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
+
describe "on native methods" do
|
137
|
+
it "should raise ParseError" do
|
138
|
+
lambda{ "".to_code :to_s }.should raise_error(ParseError)
|
139
|
+
end
|
136
140
|
end
|
137
141
|
end
|
138
142
|
|
139
|
-
|
140
|
-
|
141
143
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srizzo-irber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- srizzo
|
@@ -51,15 +51,18 @@ files:
|
|
51
51
|
- VERSION
|
52
52
|
- features/get_a_generated_source_code_on_the_fly.feature
|
53
53
|
- features/make_an_object_print_itself.feature
|
54
|
+
- features/print_generated_source_code.feature
|
54
55
|
- features/step_definitions/irber_steps.rb
|
55
56
|
- features/support/env.rb
|
56
57
|
- irber.gemspec
|
57
58
|
- lib/irber.rb
|
58
59
|
- lib/irber/printing.rb
|
60
|
+
- lib/irber/src.rb
|
59
61
|
- lib/irber/to_code.rb
|
60
62
|
- spec/custom_helpers.rb
|
61
63
|
- spec/custom_matchers.rb
|
62
64
|
- spec/irber/printing_spec.rb
|
65
|
+
- spec/irber/src_spec.rb
|
63
66
|
- spec/irber/to_code_spec.rb
|
64
67
|
- spec/spec_helper.rb
|
65
68
|
has_rdoc: true
|
@@ -92,5 +95,6 @@ test_files:
|
|
92
95
|
- spec/custom_helpers.rb
|
93
96
|
- spec/custom_matchers.rb
|
94
97
|
- spec/irber/printing_spec.rb
|
98
|
+
- spec/irber/src_spec.rb
|
95
99
|
- spec/irber/to_code_spec.rb
|
96
100
|
- spec/spec_helper.rb
|