sourcerer 0.5.0.pre.beta
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.
- checksums.yaml +15 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +72 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/examples/fun_with_procs_and_methods.rb +74 -0
- data/files.rb +24 -0
- data/lib/source.rb +4 -0
- data/lib/sourcerer.rb +14 -0
- data/lib/sourcerer/file.rb +23 -0
- data/lib/sourcerer/method.rb +77 -0
- data/lib/sourcerer/proc.rb +44 -0
- data/lib/sourcerer/proc_source.rb +103 -0
- data/lib/sourcerer/proc_source_body.rb +14 -0
- data/lib/sourcerer/proc_source_params.rb +37 -0
- data/lib/sourcerer/string.rb +25 -0
- data/sourcerer.gemspec +28 -0
- data/test/test.rb +0 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzY4ZWNjZDY5OWY5NzM0MDFmNzZmMjQ4ODA5MDY4YjM1Mzg1ODhiMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODZkMTk1Zjg1NWRlY2RkOTA0ZmE0ZDljMDg3MjRjZDYzZTQ4N2VmOA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzkxNTJlOWM0MTRjN2MwY2FhNGU4NmU5NGFlMzMzNmYxZjhiNjk2MWI1ZGU1
|
10
|
+
MGJkNTk0MTdlMWYyMzg3NTIwYzkwODBhMjNhNWRiZGQxZGM0MDQ0YmM4ZjJm
|
11
|
+
MTJkMTkyYTNiNDUyZTgyYTYyZGNjMTAzMzZlZmEwNTIwYmQxNjg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjJjNjlkYWViMjE5MGRhZTkwNTA3MDk5MTY5ZjliNzEyNGQ3YTdhMzIwOTQ5
|
14
|
+
MGE1NGJkMTE0NzFkN2JkMTc0YmQ3ZmFiMWU5YWZiOWIwNjYxNWU0MDAyNzJk
|
15
|
+
NjcyZmEzMDUyNzQ3NWU1M2NlYjEzZTBjODQ4MWQzOTAwNDFlNDY=
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "jeweler", "~> 1.8.7"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.0.0)
|
5
|
+
i18n (~> 0.6, >= 0.6.4)
|
6
|
+
minitest (~> 4.2)
|
7
|
+
multi_json (~> 1.3)
|
8
|
+
thread_safe (~> 0.1)
|
9
|
+
tzinfo (~> 0.3.37)
|
10
|
+
addressable (2.3.5)
|
11
|
+
atomic (1.1.14)
|
12
|
+
builder (3.2.2)
|
13
|
+
faraday (0.8.8)
|
14
|
+
multipart-post (~> 1.2.0)
|
15
|
+
git (1.2.6)
|
16
|
+
github_api (0.10.1)
|
17
|
+
addressable
|
18
|
+
faraday (~> 0.8.1)
|
19
|
+
hashie (>= 1.2)
|
20
|
+
multi_json (~> 1.4)
|
21
|
+
nokogiri (~> 1.5.2)
|
22
|
+
oauth2
|
23
|
+
hashie (2.0.5)
|
24
|
+
highline (1.6.20)
|
25
|
+
httpauth (0.2.0)
|
26
|
+
i18n (0.6.5)
|
27
|
+
jeweler (1.8.8)
|
28
|
+
builder
|
29
|
+
bundler (~> 1.0)
|
30
|
+
git (>= 1.2.5)
|
31
|
+
github_api (= 0.10.1)
|
32
|
+
highline (>= 1.6.15)
|
33
|
+
nokogiri (= 1.5.10)
|
34
|
+
rake
|
35
|
+
rdoc
|
36
|
+
json (1.8.1)
|
37
|
+
jwt (0.1.8)
|
38
|
+
multi_json (>= 1.5)
|
39
|
+
minitest (4.7.5)
|
40
|
+
multi_json (1.8.2)
|
41
|
+
multi_xml (0.5.5)
|
42
|
+
multipart-post (1.2.0)
|
43
|
+
nokogiri (1.5.10)
|
44
|
+
oauth2 (0.9.2)
|
45
|
+
faraday (~> 0.8)
|
46
|
+
httpauth (~> 0.2)
|
47
|
+
jwt (~> 0.1.4)
|
48
|
+
multi_json (~> 1.0)
|
49
|
+
multi_xml (~> 0.5)
|
50
|
+
rack (~> 1.2)
|
51
|
+
rack (1.5.2)
|
52
|
+
rake (10.1.0)
|
53
|
+
rdoc (3.12.2)
|
54
|
+
json (~> 1.4)
|
55
|
+
shoulda (3.5.0)
|
56
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
57
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
58
|
+
shoulda-context (1.1.5)
|
59
|
+
shoulda-matchers (2.4.0)
|
60
|
+
activesupport (>= 3.0.0)
|
61
|
+
thread_safe (0.1.3)
|
62
|
+
atomic
|
63
|
+
tzinfo (0.3.38)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
bundler (~> 1.0)
|
70
|
+
jeweler (~> 1.8.7)
|
71
|
+
rdoc (~> 3.12)
|
72
|
+
shoulda
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Adam Luzsi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join "bundler","gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0-beta
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative "../lib/sourcerer.rb"
|
2
|
+
|
3
|
+
test= Proc.new do |*params|
|
4
|
+
|
5
|
+
puts "some awsome code here"
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def hello_this sym
|
10
|
+
puts "this is the Body!"
|
11
|
+
end
|
12
|
+
|
13
|
+
# todo -> more advanced regex for params
|
14
|
+
# ,options={},*args, &block
|
15
|
+
|
16
|
+
|
17
|
+
method_source= method(:hello_this).source
|
18
|
+
#Proc.new{ |sup,yo,lazy=nil,*params|
|
19
|
+
#
|
20
|
+
# puts "this is the Body!"
|
21
|
+
#
|
22
|
+
#}
|
23
|
+
|
24
|
+
proc_source= test.source
|
25
|
+
#Proc.new{ |*params|
|
26
|
+
#
|
27
|
+
# puts "some awsome code here"
|
28
|
+
#
|
29
|
+
#}
|
30
|
+
|
31
|
+
# example for terminal run
|
32
|
+
puts method_source,"---"
|
33
|
+
puts method_source.body,"---"
|
34
|
+
puts method_source.params,"---"
|
35
|
+
puts method_source.parameters.inspect,"---"
|
36
|
+
|
37
|
+
puts "\n"
|
38
|
+
|
39
|
+
merged_proc= ( method_source.body +
|
40
|
+
proc_source.body
|
41
|
+
).build(*(method_source.params+proc_source.params))
|
42
|
+
puts merged_proc
|
43
|
+
puts merged_proc.to_proc
|
44
|
+
puts merged_proc.to_proc.source
|
45
|
+
|
46
|
+
|
47
|
+
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
48
|
+
|
49
|
+
class A
|
50
|
+
|
51
|
+
class << self
|
52
|
+
|
53
|
+
def hello test=nil
|
54
|
+
puts "world!"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.singleton test=nil
|
60
|
+
puts "singleton"
|
61
|
+
end
|
62
|
+
|
63
|
+
def instance hello= "wolrd"
|
64
|
+
puts "instance"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
puts A.instance_method(:instance).source
|
70
|
+
|
71
|
+
puts A.method(:singleton).source
|
72
|
+
|
73
|
+
|
74
|
+
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
data/files.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
### Get Files from dir
|
2
|
+
begin
|
3
|
+
|
4
|
+
files_to_be_loaded = %w[version.rb]
|
5
|
+
|
6
|
+
SpecFiles= Array.new
|
7
|
+
|
8
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),"**","*"))].sort.uniq.each do |one_file_name|
|
9
|
+
one_file_name = File.expand_path one_file_name
|
10
|
+
file_name = one_file_name[(File.expand_path(File.dirname(__FILE__)).to_s.length+1)..(one_file_name.length-1)]
|
11
|
+
|
12
|
+
if !one_file_name.include?("pkg")
|
13
|
+
if !File.directory? file_name
|
14
|
+
SpecFiles.push file_name
|
15
|
+
STDOUT.puts file_name if $DEBUG
|
16
|
+
if files_to_be_loaded.include? one_file_name.split(File::SEPARATOR).last
|
17
|
+
load one_file_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/source.rb
ADDED
data/lib/sourcerer.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
module Sourcerer
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__),"sourcerer","proc_source")
|
5
|
+
require File.join(File.dirname(__FILE__),"sourcerer","proc_source_body")
|
6
|
+
require File.join(File.dirname(__FILE__),"sourcerer","proc_source_params")
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__),"sourcerer","string")
|
9
|
+
require File.join(File.dirname(__FILE__),"sourcerer","file")
|
10
|
+
|
11
|
+
require File.join(File.dirname(__FILE__),"sourcerer","method")
|
12
|
+
require File.join(File.dirname(__FILE__),"sourcerer","proc")
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class File
|
2
|
+
|
3
|
+
# start read the file object on each line
|
4
|
+
# optionable an integer value to start read line at
|
5
|
+
# compatible with mac (i am linux user, so not tested)
|
6
|
+
def each_line_from(start_at=1,&block)
|
7
|
+
unless [Integer,Fixnum,Bignum].include?(start_at.class)
|
8
|
+
raise ArgumentError, "invalid line index"
|
9
|
+
end
|
10
|
+
begin
|
11
|
+
line_num= 1
|
12
|
+
text= self.read
|
13
|
+
text.gsub!(/\r\n?/, "\n")
|
14
|
+
text.each_line do |*line|
|
15
|
+
if line_num >= start_at
|
16
|
+
block.call *line
|
17
|
+
end
|
18
|
+
line_num += 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Sourcerer
|
2
|
+
|
3
|
+
module MethodDSL
|
4
|
+
|
5
|
+
|
6
|
+
# creatue a raw eval-able process source, so you can set
|
7
|
+
# the right bindings using the .to_proc call from String methods
|
8
|
+
def source
|
9
|
+
|
10
|
+
# defaults
|
11
|
+
begin
|
12
|
+
return_string= Sourcerer::ProcSource.new
|
13
|
+
block= 0
|
14
|
+
end
|
15
|
+
|
16
|
+
unless Sourcerer::ProcSource.source_cache[self.inspect].nil?
|
17
|
+
return Sourcerer::ProcSource.source_cache[self.inspect]
|
18
|
+
else
|
19
|
+
|
20
|
+
if self.source_location.nil?
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
|
24
|
+
File.open(File.expand_path(self.source_location[0])
|
25
|
+
).each_line_from self.source_location[1] do |line|
|
26
|
+
block += line.source_formater_for_line_sub
|
27
|
+
return_string.concat(line)
|
28
|
+
break if block == 0
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
|
33
|
+
if return_string.split("\n")[0].include? '('
|
34
|
+
return_string.sub!('(',' ')
|
35
|
+
return_string.sub!(')',' ')
|
36
|
+
end
|
37
|
+
|
38
|
+
args_to_replace = return_string.split("\n")[0].match(/\s*def\s*\S*\s*(.*)/).captures[0]
|
39
|
+
|
40
|
+
if args_to_replace != String.new
|
41
|
+
return_string.sub!(args_to_replace,"|#{args_to_replace}|")
|
42
|
+
end
|
43
|
+
|
44
|
+
rescue TypeError,NoMethodError
|
45
|
+
return nil
|
46
|
+
end
|
47
|
+
|
48
|
+
return_string.sub!(/\s*\bdef\s*[\w\S]*/,'Proc.new{')
|
49
|
+
return_string.sub!(/}[^}]*$/,"}")
|
50
|
+
|
51
|
+
if !return_string.include?('Proc.new')
|
52
|
+
return_string.sub!(/^[^{]*(?!={)/,'Proc.new')
|
53
|
+
end
|
54
|
+
|
55
|
+
if !self.source_location.nil?
|
56
|
+
Sourcerer::ProcSource.source_cache[self.inspect]= return_string
|
57
|
+
end
|
58
|
+
|
59
|
+
return return_string
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
alias :source_string :source
|
64
|
+
alias :proc_source :source
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
class Method
|
72
|
+
include Sourcerer::MethodDSL
|
73
|
+
end
|
74
|
+
|
75
|
+
class UnboundMethod
|
76
|
+
include Sourcerer::MethodDSL
|
77
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Proc
|
2
|
+
|
3
|
+
# create a raw eval-able process source, so you can set
|
4
|
+
# the right bindings using the .to_proc call from String methods
|
5
|
+
def source
|
6
|
+
|
7
|
+
# defaults
|
8
|
+
begin
|
9
|
+
return_string= Sourcerer::ProcSource.new
|
10
|
+
block= 0
|
11
|
+
end
|
12
|
+
|
13
|
+
unless Sourcerer::ProcSource.source_cache[self.inspect].nil?
|
14
|
+
return Sourcerer::ProcSource.source_cache[self.inspect]
|
15
|
+
else
|
16
|
+
|
17
|
+
if self.source_location.nil?
|
18
|
+
return "Proc.new { }"
|
19
|
+
end
|
20
|
+
|
21
|
+
File.open(File.expand_path(self.source_location[0])
|
22
|
+
).each_line_from self.source_location[1] do |line|
|
23
|
+
block += line.source_formater_for_line_sub
|
24
|
+
return_string.concat(line)
|
25
|
+
break if block == 0
|
26
|
+
end
|
27
|
+
|
28
|
+
return_string.sub!(/^[\w\W]*Proc.new\s*{/,'Proc.new{')
|
29
|
+
return_string.sub!(/}[^}]*$/,"}")
|
30
|
+
|
31
|
+
if !return_string.include?('Proc.new')
|
32
|
+
return_string.sub!(/^[^{]*(?!={)/,'Proc.new')
|
33
|
+
end
|
34
|
+
|
35
|
+
if !self.source_location.nil?
|
36
|
+
Sourcerer::ProcSource.source_cache[self.inspect]= return_string
|
37
|
+
end
|
38
|
+
|
39
|
+
return return_string
|
40
|
+
end
|
41
|
+
end
|
42
|
+
alias :source_string :source
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Sourcerer
|
2
|
+
class ProcSource < String
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :source_cache
|
6
|
+
attr_accessor :eval_keys
|
7
|
+
end
|
8
|
+
self.source_cache= Hash.new
|
9
|
+
self.eval_keys= Array.new
|
10
|
+
|
11
|
+
|
12
|
+
def self.build(source_code_to_be_wrappered,*params_obj_array)
|
13
|
+
self.new(source_code_to_be_wrappered).wrapper_around!(*params_obj_array)
|
14
|
+
end
|
15
|
+
|
16
|
+
def wrapper_around!(*params)
|
17
|
+
if !params.nil?
|
18
|
+
params= params.join(',')
|
19
|
+
params.prepend(' |')
|
20
|
+
params.concat('|')
|
21
|
+
end
|
22
|
+
self.prepend("Proc.new{#{params}\n")
|
23
|
+
self.concat("\n}")
|
24
|
+
end
|
25
|
+
|
26
|
+
# create process object from valid process string
|
27
|
+
def to_proc(binding=nil)
|
28
|
+
begin
|
29
|
+
|
30
|
+
unless self.split("\n")[0].include?('Proc.new')
|
31
|
+
raise ArgumentError, "string obj is not a valid process source"
|
32
|
+
end
|
33
|
+
|
34
|
+
return_proc= nil
|
35
|
+
if binding.nil?
|
36
|
+
return_proc= eval(self)
|
37
|
+
else
|
38
|
+
return_proc= eval(self,binding)
|
39
|
+
end
|
40
|
+
|
41
|
+
if ProcSource.eval_keys.count > 1000
|
42
|
+
ProcSource.eval_keys.each {|e| ProcSource.source_cache.delete(e) }
|
43
|
+
ProcSource.eval_keys.clear
|
44
|
+
end
|
45
|
+
ProcSource.source_cache[return_proc.inspect]= self
|
46
|
+
ProcSource.eval_keys.push return_proc.inspect
|
47
|
+
|
48
|
+
return return_proc
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def body
|
53
|
+
|
54
|
+
body= ProcSourceBody.new(self.dup.to_s)
|
55
|
+
body.sub!(/.*Proc\.new *{ *(\|.*\|)?/,String.new)
|
56
|
+
body.gsub!(/^$\n/, String.new)
|
57
|
+
body.sub!(/\s*}\s*$/,String.new)
|
58
|
+
|
59
|
+
return body
|
60
|
+
end
|
61
|
+
|
62
|
+
def params
|
63
|
+
#SystemStackError
|
64
|
+
params= self.dup
|
65
|
+
params.sub!(params.split("\n")[0].scan(/\s*Proc.new\s*{/)[0],String.new)
|
66
|
+
params.sub!(' ','')
|
67
|
+
params= params.split("\n")[0].scan(/^\s*{?\s*(.*)/)[0][0].gsub!('|','')
|
68
|
+
if params.nil?
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
return ProcSourceParams[*params.split(',')]
|
72
|
+
end
|
73
|
+
|
74
|
+
def parameters
|
75
|
+
|
76
|
+
return_array= Array.new
|
77
|
+
params= self.params
|
78
|
+
params.each do |one_raw_parameter|
|
79
|
+
case true
|
80
|
+
when one_raw_parameter.include?('=')
|
81
|
+
begin
|
82
|
+
return_array.push Array.new.push(:opt).push(
|
83
|
+
one_raw_parameter.split('=')[0].to_sym)
|
84
|
+
end
|
85
|
+
when one_raw_parameter[0] == '*'
|
86
|
+
begin
|
87
|
+
one_raw_parameter[0]= ''
|
88
|
+
return_array.push Array.new.push(:rest).push(
|
89
|
+
one_raw_parameter.to_sym)
|
90
|
+
end
|
91
|
+
else
|
92
|
+
begin
|
93
|
+
return_array.push Array.new.push(:req).push(
|
94
|
+
one_raw_parameter.to_sym)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
return return_array
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Sourcerer
|
2
|
+
class ProcSourceParams < Array
|
3
|
+
|
4
|
+
# merge two proc params obj
|
5
|
+
# if multiple rest obj found
|
6
|
+
# it will remove and make an *args obj as last element
|
7
|
+
# if they are not equal ,
|
8
|
+
# else it makes it the last element only
|
9
|
+
def +(oth_ary)
|
10
|
+
|
11
|
+
merged_array= (Array[*self]+Array[*oth_ary])
|
12
|
+
|
13
|
+
rest_state= nil
|
14
|
+
rest_elements= Array.new
|
15
|
+
merged_array.dup.each do |element|
|
16
|
+
if element.include? '*'
|
17
|
+
merged_array.delete(element)
|
18
|
+
rest_state ||= true
|
19
|
+
rest_elements.push(element)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
rest_elements.uniq!
|
24
|
+
if rest_elements.count == 1 && !rest_elements.empty?
|
25
|
+
merged_array.push(rest_elements[0])
|
26
|
+
rest_state= nil
|
27
|
+
end
|
28
|
+
|
29
|
+
unless rest_state.nil?
|
30
|
+
merged_array.push('*args')
|
31
|
+
end
|
32
|
+
|
33
|
+
return ProcSourceParams[*merged_array]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
# return the number how often the str is with in the self
|
4
|
+
# by default with \b regex border
|
5
|
+
def frequency(str)
|
6
|
+
begin
|
7
|
+
if str.class == String
|
8
|
+
str= '\b'+str+'\b'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
self.scan(/#{str}/).count
|
12
|
+
end
|
13
|
+
|
14
|
+
# this is a helper to create source strings from procs
|
15
|
+
def source_formater_for_line_sub
|
16
|
+
self.gsub!(';',"\n")
|
17
|
+
self.gsub!(/\bdo\b/,'{')
|
18
|
+
self.gsub!(/\bend\b/,'}')
|
19
|
+
|
20
|
+
self.frequency(/{/)+
|
21
|
+
self.frequency(/def/)-
|
22
|
+
self.frequency(/}/)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/sourcerer.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__),"files.rb"))
|
4
|
+
|
5
|
+
### Specification for the new Gem
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
spec.name = "sourcerer"
|
9
|
+
spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
|
10
|
+
spec.authors = ["Adam Luzsi"]
|
11
|
+
spec.email = ["adamluzsi@gmail.com"]
|
12
|
+
spec.description = %q{ DSL for for simple to use proc source generating from methods, unbound methods and of course Proc/lambda. It will allow you to play with the source or even fuse two source code to make a new one and generate a proc from that. }
|
13
|
+
spec.summary = %q{Simple source extractor Based on standard CRuby}
|
14
|
+
spec.homepage = "https://github.com/adamluzsi/sourcerer"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = SpecFiles
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
##=======Runtime-ENV================##
|
23
|
+
#spec.add_runtime_dependency "asdf", ['~>4.1.3']
|
24
|
+
|
25
|
+
##=======Development-ENV============##
|
26
|
+
#spec.add_development_dependency "asdf",['~>4.1.3']
|
27
|
+
|
28
|
+
end
|
data/test/test.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sourcerer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0.pre.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Luzsi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ! ' DSL for for simple to use proc source generating from methods, unbound
|
14
|
+
methods and of course Proc/lambda. It will allow you to play with the source or
|
15
|
+
even fuse two source code to make a new one and generate a proc from that. '
|
16
|
+
email:
|
17
|
+
- adamluzsi@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- VERSION
|
28
|
+
- examples/fun_with_procs_and_methods.rb
|
29
|
+
- files.rb
|
30
|
+
- lib/source.rb
|
31
|
+
- lib/sourcerer.rb
|
32
|
+
- lib/sourcerer/file.rb
|
33
|
+
- lib/sourcerer/method.rb
|
34
|
+
- lib/sourcerer/proc.rb
|
35
|
+
- lib/sourcerer/proc_source.rb
|
36
|
+
- lib/sourcerer/proc_source_body.rb
|
37
|
+
- lib/sourcerer/proc_source_params.rb
|
38
|
+
- lib/sourcerer/string.rb
|
39
|
+
- sourcerer.gemspec
|
40
|
+
- test/test.rb
|
41
|
+
homepage: https://github.com/adamluzsi/sourcerer
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ! '>'
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.3.1
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.2.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Simple source extractor Based on standard CRuby
|
65
|
+
test_files:
|
66
|
+
- test/test.rb
|
67
|
+
has_rdoc:
|