ruby_traverser 0.1.0 → 0.1.1
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.
- data/README.markdown +91 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mutate/api.rb +4 -4
- data/ruby_traverser.gemspec +4 -4
- metadata +3 -3
data/README.markdown
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# Ruby traverser ##
|
2
2
|
|
3
3
|
A DSL for traversing ruby code as an object model (graph), which lets you find parts of the ruby code of interest.
|
4
|
-
The traverser leverages `ripper2ruby`,
|
4
|
+
The traverser leverages `ripper2ruby`, a library for generating a model from ruby source code. `ripper2ruby` leverages `ripper` which comes with ruby 1.9.
|
5
5
|
|
6
6
|
See the unit tests in the test directory for examples of use.
|
7
7
|
|
8
|
+
## Requirements ##
|
9
|
+
* Ruby 1.9
|
10
|
+
* ripper2ruby >= 0.0.2
|
11
|
+
|
8
12
|
## Finders ##
|
9
13
|
|
10
14
|
* find_module(name)
|
@@ -178,7 +182,92 @@ The API now also supports a wide variety of code mutations using a DSL.
|
|
178
182
|
More information will soon be available here or on the github wiki.
|
179
183
|
Check the test/mutate folder for test demonstrating what is currently possible.
|
180
184
|
|
181
|
-
|
185
|
+
## Example use of Mutation API ##
|
186
|
+
|
187
|
+
Source BEFORE mutations:
|
188
|
+
<pre>
|
189
|
+
class Monty < Abc::Blip
|
190
|
+
end
|
191
|
+
</pre>
|
192
|
+
|
193
|
+
<pre>
|
194
|
+
src = %q{ class Monty < Abc::Blip
|
195
|
+
end}
|
196
|
+
|
197
|
+
def_src = %q{
|
198
|
+
def my_fun
|
199
|
+
end}
|
200
|
+
|
201
|
+
def_code = Ripper::RubyBuilder.build(def_src)
|
202
|
+
code = Ripper::RubyBuilder.build(src)
|
203
|
+
|
204
|
+
# append code examples
|
205
|
+
code.inside_class('Monty', :superclass => 'Abc::Blip') do |b|
|
206
|
+
assert_equal Ruby::Class, b.class
|
207
|
+
gem_abc = b.append_code("gem 'abc'")
|
208
|
+
blip = b.append_code("blip")
|
209
|
+
gem_123 = gem_abc.append_code("gem '123'")
|
210
|
+
gem_123.append_comment("hello")
|
211
|
+
my_def = b.append_code(def_src)
|
212
|
+
|
213
|
+
b.prepend_code("gem '789'")
|
214
|
+
puts b.to_ruby
|
215
|
+
end
|
216
|
+
</pre>
|
217
|
+
|
218
|
+
Source AFTER mutations:
|
219
|
+
<pre>
|
220
|
+
class Monty < Abc::Blip
|
221
|
+
gem '789'
|
222
|
+
gem 'abc'
|
223
|
+
gem '123'
|
224
|
+
blip
|
225
|
+
|
226
|
+
def my_fun
|
227
|
+
end
|
228
|
+
end
|
229
|
+
</pre>
|
230
|
+
|
231
|
+
|
232
|
+
## Replace example ##
|
233
|
+
|
234
|
+
Source BEFORE mutations:
|
235
|
+
<pre>
|
236
|
+
group :test do
|
237
|
+
gem 'ripper', :src
|
238
|
+
my_var = 2
|
239
|
+
end
|
240
|
+
</pre>
|
241
|
+
|
242
|
+
<pre>
|
243
|
+
src = %q{
|
244
|
+
group :test do
|
245
|
+
gem 'ripper', :src
|
246
|
+
my_var = 2
|
247
|
+
end
|
248
|
+
}
|
249
|
+
|
250
|
+
code = Ripper::RubyBuilder.build(src)
|
251
|
+
# replace examples
|
252
|
+
code.inside_block('group', :args => [:test]) do |b|
|
253
|
+
call_node = b.find_call('gem', :args => ['ripper'])
|
254
|
+
assert_equal Ruby::Call, call_node.class
|
255
|
+
call_node.replace(:arg => :src , :replace_code => "{:src => 'unknown'}")
|
256
|
+
call_node.replace(:value => "3")
|
257
|
+
puts b.to_ruby
|
258
|
+
end
|
259
|
+
end
|
260
|
+
</pre>
|
261
|
+
|
262
|
+
Source AFTER mutations:
|
263
|
+
<pre>
|
264
|
+
group :test do
|
265
|
+
gem 'ripper', {:src => 'unknown'}
|
266
|
+
my_var = 3
|
267
|
+
end
|
268
|
+
</pre>
|
269
|
+
|
270
|
+
Note: The mutation API code was developed quickly in a test-driven fashion, but is in need of a major refactoring overhaul sometime soon...
|
182
271
|
|
183
272
|
## Note on Patches/Pull Requests ##
|
184
273
|
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/kristianmandrup/ruby_trav"
|
12
12
|
gem.authors = ["Kristian Mandrup"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 2.0.0"
|
14
|
-
gem.add_dependency "ripper2ruby", "
|
14
|
+
gem.add_dependency "ripper2ruby", ">= 0.0.2"
|
15
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
16
|
|
17
17
|
# add more gem options here
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/mutate/api.rb
CHANGED
@@ -84,13 +84,13 @@ module RubyAPI
|
|
84
84
|
def last_position(elements)
|
85
85
|
last_element = elements.last
|
86
86
|
return position.col
|
87
|
-
return position.col if simple_pos?
|
87
|
+
return position.col if simple_pos?(last_element)
|
88
88
|
return last_element.identifier.position.col if elements && elements.size > 0
|
89
89
|
inside_indent
|
90
90
|
end
|
91
91
|
|
92
|
-
def simple_pos?
|
93
|
-
[Ruby::Token, Ruby::Variable].include?(
|
92
|
+
def simple_pos?(elem)
|
93
|
+
[Ruby::Token, Ruby::Variable].include?(elem.class)
|
94
94
|
end
|
95
95
|
|
96
96
|
def first_indent
|
@@ -104,7 +104,7 @@ module RubyAPI
|
|
104
104
|
|
105
105
|
def first_position(elements)
|
106
106
|
first_element = elements.first
|
107
|
-
return position.col if simple_pos?
|
107
|
+
return position.col if simple_pos?(first_element)
|
108
108
|
return first_element.identifier.position.col if elements && elements.size > 0
|
109
109
|
inside_indent
|
110
110
|
end
|
data/ruby_traverser.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruby_traverser}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
@@ -66,14 +66,14 @@ Gem::Specification.new do |s|
|
|
66
66
|
|
67
67
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
68
68
|
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
69
|
-
s.add_runtime_dependency(%q<ripper2ruby>, ["
|
69
|
+
s.add_runtime_dependency(%q<ripper2ruby>, [">= 0.0.2"])
|
70
70
|
else
|
71
71
|
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
72
|
-
s.add_dependency(%q<ripper2ruby>, ["
|
72
|
+
s.add_dependency(%q<ripper2ruby>, [">= 0.0.2"])
|
73
73
|
end
|
74
74
|
else
|
75
75
|
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
76
|
-
s.add_dependency(%q<ripper2ruby>, ["
|
76
|
+
s.add_dependency(%q<ripper2ruby>, [">= 0.0.2"])
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
segments:
|
42
42
|
- 0
|