sourcerer 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/VERSION +1 -1
- data/lib/sourcerer/source_code.rb +31 -0
- data/test/test.rb +14 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71bdf6600dc7d324f5b52f69cda8bc1566de74e7
|
4
|
+
data.tar.gz: 4e30731f8d8b819d9238a53eca15fd0739e9fc50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a35e6d65c2615ebde06cb4712b9816575899663ced5a73f6af49260f4d6882d0ce098ef9ae68daa80a17344145b19b2e6d96bfeec893832e92857a33b4bd137d
|
7
|
+
data.tar.gz: d71e5e08eea5d214833e50f3c072d2e1593b04aee4a33eec728367b3d3e34e857e5d7ace9ecb46e3130773b8c2cf694cc0508df67310985ac85f99e9e0edfefb
|
data/README.md
CHANGED
@@ -78,6 +78,18 @@ Gemfile:
|
|
78
78
|
|
79
79
|
```
|
80
80
|
|
81
|
+
### SourceCode
|
82
|
+
|
83
|
+
you can invoke the :body & :params methods on the source code to trim out the code string parts
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
|
87
|
+
proc_obj.source.body
|
88
|
+
proc_obj.source.params
|
89
|
+
|
90
|
+
|
91
|
+
```
|
92
|
+
|
81
93
|
### after words
|
82
94
|
|
83
95
|
if you find any bug please report to me :)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
@@ -1,7 +1,38 @@
|
|
1
1
|
module Sourcerer
|
2
2
|
class SourceCode < String
|
3
3
|
|
4
|
+
def parameters
|
5
|
+
@parameters || self.dismantle.parameters
|
6
|
+
end
|
7
|
+
alias :args :parameters
|
8
|
+
alias :params :parameters
|
4
9
|
|
10
|
+
def body
|
11
|
+
@body || self.dismantle.body
|
12
|
+
end
|
13
|
+
|
14
|
+
def dismantle
|
15
|
+
|
16
|
+
self_dup= self.dup
|
17
|
+
|
18
|
+
#TODO: optionable args search for comments
|
19
|
+
parameters_var= self.scan(/\s*Proc\.new\s*{\s*\|(.*)\|/)
|
20
|
+
if parameters_var.empty?
|
21
|
+
@parameters= ""
|
22
|
+
else
|
23
|
+
@parameters= parameters_var[0][0]
|
24
|
+
self_dup.sub!(parameters_var[0][0],"")
|
25
|
+
self_dup.sub!( self_dup.split("\n")[0], self_dup.split("\n")[0].gsub("|","") )
|
26
|
+
end
|
27
|
+
|
28
|
+
self_dup.slice! /\s*Proc\.new\s*{[\s\n]*/
|
29
|
+
self_dup[self_dup.length-1]=""
|
30
|
+
|
31
|
+
@body= self_dup
|
32
|
+
|
33
|
+
return self
|
34
|
+
|
35
|
+
end
|
5
36
|
|
6
37
|
end
|
7
38
|
end
|
data/test/test.rb
CHANGED
@@ -22,28 +22,6 @@ asd = Proc.new { |var, opts={}, *args, &block|
|
|
22
22
|
|
23
23
|
}
|
24
24
|
|
25
|
-
puts asdf.source
|
26
|
-
puts asd.source
|
27
|
-
puts method(:test).source
|
28
|
-
|
29
|
-
|
30
|
-
#> output
|
31
|
-
test= Proc.new do |sym,options={},*params,&block|
|
32
|
-
|
33
|
-
puts "some awsome code here" # comment
|
34
|
-
puts "yo"
|
35
|
-
|
36
|
-
end # Proc
|
37
|
-
|
38
|
-
puts test.source
|
39
|
-
# Proc.new { |sym,options={},*params,&block|
|
40
|
-
#
|
41
|
-
# puts "some awsome code here"
|
42
|
-
# puts "yo"
|
43
|
-
#
|
44
|
-
# }
|
45
|
-
|
46
|
-
|
47
25
|
class HelloWorld
|
48
26
|
|
49
27
|
#> TODO: comment remove from args
|
@@ -61,5 +39,18 @@ class HelloWorld
|
|
61
39
|
|
62
40
|
end
|
63
41
|
|
64
|
-
|
42
|
+
#> output
|
43
|
+
test2= Proc.new do |sym,options={},*params,&block|
|
44
|
+
|
45
|
+
puts "some awsome code here" # comment
|
46
|
+
puts "yo"
|
47
|
+
|
48
|
+
end # Proc
|
49
|
+
|
50
|
+
puts asdf.source.body
|
51
|
+
puts asd.source.body
|
52
|
+
puts asd.source.params
|
53
|
+
# puts method(:test).source
|
54
|
+
# puts test2.source
|
55
|
+
# puts HelloWorld.method(:hello).source
|
65
56
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sourcerer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " DSL for for simple to use proc source generating from methods, unbound
|
14
14
|
methods and of course Proc/lambda. It will allow you to play with the source or
|