srizzo-irber 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -0
- data/README.markdown +95 -0
- data/VERSION +1 -1
- data/features/get_a_generated_source_code_on_the_fly.feature +8 -8
- data/features/{make_an_object_print_itself.feature → make_any_object_inspect_itself.feature} +11 -3
- data/features/print_an_objects_api.feature +67 -0
- data/features/print_generated_source_code.feature +3 -3
- data/features/step_definitions/irber_steps.rb +9 -0
- data/irber.gemspec +21 -11
- data/lib/irber.rb +3 -2
- data/lib/irber/api.rb +57 -0
- data/lib/irber/papi.rb +22 -0
- data/lib/irber/psrc.rb +11 -0
- data/lib/irber/{printing.rb → self_inspect.rb} +13 -3
- data/lib/irber/signature.rb +45 -0
- data/lib/irber/src.rb +45 -7
- data/spec/irber/api_spec.rb +66 -0
- data/spec/irber/papi_spec.rb +43 -0
- data/spec/irber/psrc_spec.rb +33 -0
- data/spec/irber/self_inspect_spec.rb +90 -0
- data/spec/irber/signature_spec.rb +66 -0
- data/spec/irber/src_spec.rb +140 -18
- metadata +21 -11
- data/README.rdoc +0 -73
- data/lib/irber/to_code.rb +0 -50
- data/spec/irber/printing_spec.rb +0 -52
- data/spec/irber/to_code_spec.rb +0 -143
data/spec/irber/src_spec.rb
CHANGED
@@ -2,27 +2,149 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
require "irber/src"
|
4
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
5
|
|
6
|
+
module Irber
|
7
|
+
module Src
|
8
|
+
|
9
|
+
class A
|
10
|
+
def an_instance_method
|
11
|
+
"result"
|
12
|
+
end
|
13
|
+
def self.a_class_method
|
14
|
+
"result"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module M
|
19
|
+
def a_method
|
20
|
+
"result"
|
21
|
+
end
|
22
|
+
def self.a_module_method
|
23
|
+
"result"
|
24
|
+
end
|
25
|
+
end
|
14
26
|
|
15
|
-
|
27
|
+
|
28
|
+
describe Irber::Src do
|
16
29
|
|
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
30
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
describe "#src" do
|
32
|
+
|
33
|
+
describe "on classes" do
|
34
|
+
it "should be available on all classes" do
|
35
|
+
A.should respond_to(:src)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should generate its source code" do
|
39
|
+
A.src.should match_code "
|
40
|
+
class Irber::Src::A < Object
|
41
|
+
def an_instance_method()
|
42
|
+
\"result\"
|
43
|
+
end
|
44
|
+
def self.a_class_method()
|
45
|
+
\"result\"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "on objects" do
|
53
|
+
it "should be available on all objects" do
|
54
|
+
A.new.should respond_to(:src)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should generate its source code" do
|
58
|
+
A.new.src.should match_code "
|
59
|
+
class Irber::Src::A < Object
|
60
|
+
def an_instance_method()
|
61
|
+
\"result\"
|
62
|
+
end
|
63
|
+
def self.a_class_method()
|
64
|
+
\"result\"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "on modules" do
|
73
|
+
it "should generat its source code" do
|
74
|
+
M.src.should match_code "
|
75
|
+
module Irber::Src::M
|
76
|
+
def a_method()
|
77
|
+
\"result\"
|
78
|
+
end
|
79
|
+
def self.a_module_method()
|
80
|
+
\"result\"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "on class methods" do
|
88
|
+
it "should generate a class instance method source code " do
|
89
|
+
A.src(:an_instance_method).should match_code "
|
90
|
+
def an_instance_method()
|
91
|
+
\"result\"
|
92
|
+
end
|
93
|
+
"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should generate a class method source code " do
|
97
|
+
A.src(:a_class_method).should match_code "
|
98
|
+
def a_class_method()
|
99
|
+
\"result\"
|
100
|
+
end
|
101
|
+
"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
describe "on object methods" do
|
107
|
+
it "should generate an object method source code" do
|
108
|
+
A.new.src(:an_instance_method).should match_code "
|
109
|
+
def an_instance_method()
|
110
|
+
\"result\"
|
111
|
+
end
|
112
|
+
"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "on module methods" do
|
117
|
+
it "should generate a module method source code" do
|
118
|
+
M.src(:a_method).should match_code "
|
119
|
+
def a_method()
|
120
|
+
\"result\"
|
121
|
+
end
|
122
|
+
"
|
123
|
+
end
|
124
|
+
end
|
26
125
|
|
27
126
|
|
28
|
-
|
127
|
+
describe "on inexisting methods" do
|
128
|
+
it "should raise NameError" do
|
129
|
+
lambda{ A.new.src(:an_inexisting_method) }.should raise_error(NameError)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
describe "on native classes" do
|
135
|
+
it "should raise ParseError" do
|
136
|
+
lambda{ String.src }.should raise_error(ParseError)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "on native methods" do
|
141
|
+
it "should raise ParseError" do
|
142
|
+
lambda{ "".src :to_s }.should raise_error(ParseError)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- srizzo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,30 +40,37 @@ extensions: []
|
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
42
|
- LICENSE
|
43
|
-
- README.
|
43
|
+
- README.markdown
|
44
44
|
files:
|
45
45
|
- .document
|
46
46
|
- .gitignore
|
47
47
|
- History.txt
|
48
48
|
- LICENSE
|
49
|
-
- README.
|
49
|
+
- README.markdown
|
50
50
|
- Rakefile
|
51
51
|
- VERSION
|
52
52
|
- features/get_a_generated_source_code_on_the_fly.feature
|
53
|
-
- features/
|
53
|
+
- features/make_any_object_inspect_itself.feature
|
54
|
+
- features/print_an_objects_api.feature
|
54
55
|
- features/print_generated_source_code.feature
|
55
56
|
- features/step_definitions/irber_steps.rb
|
56
57
|
- features/support/env.rb
|
57
58
|
- irber.gemspec
|
58
59
|
- lib/irber.rb
|
59
|
-
- lib/irber/
|
60
|
+
- lib/irber/api.rb
|
61
|
+
- lib/irber/papi.rb
|
62
|
+
- lib/irber/psrc.rb
|
63
|
+
- lib/irber/self_inspect.rb
|
64
|
+
- lib/irber/signature.rb
|
60
65
|
- lib/irber/src.rb
|
61
|
-
- lib/irber/to_code.rb
|
62
66
|
- spec/custom_helpers.rb
|
63
67
|
- spec/custom_matchers.rb
|
64
|
-
- spec/irber/
|
68
|
+
- spec/irber/api_spec.rb
|
69
|
+
- spec/irber/papi_spec.rb
|
70
|
+
- spec/irber/psrc_spec.rb
|
71
|
+
- spec/irber/self_inspect_spec.rb
|
72
|
+
- spec/irber/signature_spec.rb
|
65
73
|
- spec/irber/src_spec.rb
|
66
|
-
- spec/irber/to_code_spec.rb
|
67
74
|
- spec/spec_helper.rb
|
68
75
|
has_rdoc: true
|
69
76
|
homepage: http://github.com/srizzo/irber
|
@@ -94,7 +101,10 @@ summary: Little tools to enhance your irb experience
|
|
94
101
|
test_files:
|
95
102
|
- spec/custom_helpers.rb
|
96
103
|
- spec/custom_matchers.rb
|
97
|
-
- spec/irber/
|
104
|
+
- spec/irber/api_spec.rb
|
105
|
+
- spec/irber/papi_spec.rb
|
106
|
+
- spec/irber/psrc_spec.rb
|
107
|
+
- spec/irber/self_inspect_spec.rb
|
108
|
+
- spec/irber/signature_spec.rb
|
98
109
|
- spec/irber/src_spec.rb
|
99
|
-
- spec/irber/to_code_spec.rb
|
100
110
|
- spec/spec_helper.rb
|
data/README.rdoc
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
== DESCRIPTION:
|
2
|
-
|
3
|
-
Little tools to enhance your irb experience
|
4
|
-
|
5
|
-
== INSTALL:
|
6
|
-
|
7
|
-
* sudo gem install srizzo-irber
|
8
|
-
* add to your ~/.irbrc
|
9
|
-
|
10
|
-
require 'irber'
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
== BASIC USAGE:
|
15
|
-
|
16
|
-
* generate a class or method source code on the fly
|
17
|
-
|
18
|
-
Given a class:
|
19
|
-
|
20
|
-
class A
|
21
|
-
def a
|
22
|
-
"a"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
Generate source code on the fly:
|
28
|
-
|
29
|
-
>> src A
|
30
|
-
class A < Object
|
31
|
-
def a()
|
32
|
-
"a"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
=> nil
|
36
|
-
|
37
|
-
|
38
|
-
>> src A, :a
|
39
|
-
def a()
|
40
|
-
"a"
|
41
|
-
end
|
42
|
-
=> nil
|
43
|
-
|
44
|
-
|
45
|
-
* make an object print itself
|
46
|
-
|
47
|
-
>> [1,2].puts_it
|
48
|
-
1
|
49
|
-
2
|
50
|
-
|
51
|
-
|
52
|
-
>> [1,2].pp_it
|
53
|
-
[1, 2]
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
== FEATURES/PROBLEMS:
|
59
|
-
|
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
|
62
|
-
|
63
|
-
|
64
|
-
== REQUIREMENTS:
|
65
|
-
|
66
|
-
* ParseTree
|
67
|
-
* Ruby2Ruby
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
== Copyright
|
72
|
-
|
73
|
-
Copyright (c) 2009 Samuel Rizzo. See LICENSE for details.
|
data/lib/irber/to_code.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'parse_tree'
|
2
|
-
require 'ruby2ruby'
|
3
|
-
|
4
|
-
module Irber
|
5
|
-
module ToCode
|
6
|
-
|
7
|
-
class ParseError < StandardError; end
|
8
|
-
|
9
|
-
module InstanceMethods
|
10
|
-
def to_code method = nil
|
11
|
-
|
12
|
-
if method
|
13
|
-
|
14
|
-
if (the_method = self.method(method) rescue nil)
|
15
|
-
receiver = the_method.owner
|
16
|
-
elsif (the_method = self.instance_method(method) if self.respond_to? :instance_method)
|
17
|
-
receiver = the_method.owner
|
18
|
-
else
|
19
|
-
throw NameError.new "couldn't find method `#{method}' for `#{self}' "
|
20
|
-
end
|
21
|
-
|
22
|
-
Ruby2Ruby.new.process(ParseTree.translate(receiver, method)) rescue raise ParseError.new("couldn't parse method")
|
23
|
-
|
24
|
-
else
|
25
|
-
if self.class == Class || self.class == Module
|
26
|
-
receiver = self
|
27
|
-
else
|
28
|
-
receiver = self.class
|
29
|
-
end
|
30
|
-
|
31
|
-
Ruby2Ruby.new.process(ParseTree.translate(receiver)) rescue raise ParseError.new("couldn't parse class")
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.included(receiver)
|
39
|
-
receiver.send :include, InstanceMethods
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
class Object
|
47
|
-
include Irber::ToCode
|
48
|
-
end
|
49
|
-
|
50
|
-
|
data/spec/irber/printing_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
require "irber/printing"
|
4
|
-
|
5
|
-
class O
|
6
|
-
def to_s
|
7
|
-
"O#to_s"
|
8
|
-
end
|
9
|
-
def inspect
|
10
|
-
"O#inspect"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
describe Irber::Printing do
|
16
|
-
|
17
|
-
before(:each) do
|
18
|
-
@a = O.new
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#puts_it" do
|
22
|
-
it "should be available on all objects" do
|
23
|
-
Object.new.should respond_to(:puts_it)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should puts itself" do
|
27
|
-
stdout{ @a.puts_it }.should == stdout{ puts @a }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#p_it" do
|
32
|
-
it "should be available on all objects" do
|
33
|
-
Object.new.should respond_to(:p_it)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should puts itself" do
|
37
|
-
stdout{ @a.p_it }.should == stdout{ p @a }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#pp_it" do
|
42
|
-
it "should be available on all objects" do
|
43
|
-
Object.new.should respond_to(:pp_it)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should puts itself" do
|
47
|
-
stdout{ @a.pp_it }.should == stdout{ pp @a }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
end
|
data/spec/irber/to_code_spec.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
require "irber/to_code"
|
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
|
-
module M
|
15
|
-
def a_method
|
16
|
-
"result"
|
17
|
-
end
|
18
|
-
def self.a_module_method
|
19
|
-
"result"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
describe Irber::ToCode do
|
25
|
-
|
26
|
-
|
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
|
43
|
-
end
|
44
|
-
"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "on objects" do
|
49
|
-
it "should be available on all objects" do
|
50
|
-
A.new.should respond_to(:to_code)
|
51
|
-
end
|
52
|
-
|
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
|
62
|
-
end
|
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
|
78
|
-
end
|
79
|
-
"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
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()
|
87
|
-
\"result\"
|
88
|
-
end
|
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()
|
95
|
-
\"result\"
|
96
|
-
end
|
97
|
-
"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
|
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
|
110
|
-
end
|
111
|
-
|
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
|
120
|
-
end
|
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
|
127
|
-
end
|
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
|
134
|
-
end
|
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
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|