procemon 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,4 +20,32 @@ You want use a module? sure awsome !
20
20
  You need to add plus functionality but dont want to follow the module updates
21
21
  (in case of conflight with the monkey patch)
22
22
  Than this is your tool. Tell the method to inject what method and it will , but remember
23
- params are always have to obey to the original method!
23
+ params are always have to obey to the original method!
24
+
25
+
26
+
27
+
28
+ ## LICENSE
29
+
30
+ (The MIT License)
31
+
32
+ Copyright (c) 2009-2013 Adam Luzsi <adamluzsi@gmail.com>
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -1,7 +1,5 @@
1
1
  class Class
2
2
 
3
- #TODO refacotr to binding logic because this is useless now to me in hardcore use
4
-
5
3
  # this will inject a code block to a target instance method
6
4
  # by default the before or after sym is not required
7
5
  # default => before
@@ -0,0 +1,30 @@
1
+ module Kernel
2
+
3
+ def sender
4
+ sender_properties= Hash.new
5
+ # File system
6
+ begin
7
+ # folder create from caller
8
+ begin
9
+ folder= caller[0].split(".{rb,ru}:").first.split(File::SEPARATOR)
10
+ sender_properties[:file]= folder[(folder.count-1)].split(':')[0]
11
+ folder= folder[0..(folder.count-2)]
12
+ end
13
+ # after formatting
14
+ begin
15
+
16
+ if !File.directory?(folder.join(File::SEPARATOR))
17
+ folder.pop
18
+ end
19
+ folder= File.join(folder.join(File::SEPARATOR))
20
+ if folder != File.expand_path(folder)
21
+ folder= File.expand_path(folder)
22
+ end
23
+
24
+ end
25
+ sender_properties[:folder]= folder
26
+ end
27
+ return sender_properties
28
+ end
29
+
30
+ end
@@ -0,0 +1,44 @@
1
+ class Method
2
+
3
+ # creatue a raw eval-able process source, so you can set
4
+ # the right bindings using the .to_proc call from String methods
5
+ @@source_cache= Hash.new
6
+ def source
7
+
8
+ # defaults
9
+ begin
10
+ return_string= String.new
11
+ block= 0
12
+ end
13
+ unless @@source_cache[self.object_id].nil?
14
+ return @@source_cache[self.object_id]
15
+ else
16
+
17
+ File.open(File.expand_path(self.source_location[0])
18
+ ).each_line_from self.source_location[1] do |line|
19
+ block += line.source_formater_for_line_sub
20
+ return_string.concat(line)
21
+ break if block == 0
22
+ end
23
+
24
+ return_string.sub!(/\s*\bdef\s*[\w\S]*/,'Proc.new{')
25
+ return_string.sub!(/}[^}]*$/,"}")
26
+
27
+ return_string.sub!(
28
+ return_string.scan(/\w*\s*,\s*\w*/)[0],
29
+ '|'+return_string.scan(/\w*\s*,\s*\w*/)[0]+'|'
30
+ )
31
+
32
+ if !return_string.include?('Proc.new')
33
+ return_string.sub!(/^[^{]*(?!={)/,'Proc.new')
34
+ end
35
+
36
+ @@source_cache[self.object_id]= return_string
37
+
38
+ return return_string
39
+ end
40
+ end
41
+ alias :source_string :source
42
+ alias :proc_source :source
43
+
44
+ end
@@ -9,29 +9,22 @@ class Proc
9
9
  Proc.new { |*args| self[*other[*args]] }
10
10
  end unless method_defined? :*
11
11
 
12
-
13
12
  # create a raw eval-able process source, so you can set
14
13
  # the right bindings using the .to_proc call from String methods
15
14
  @@source_cache= Hash.new
16
15
  def source
17
-
18
16
  # defaults
19
17
  begin
20
18
  return_string= String.new
21
19
  block= 0
22
20
  end
23
- if @@source_cache.keys.include? self.object_id
21
+
22
+ unless @@source_cache[self.object_id].nil?
24
23
  return @@source_cache[self.object_id]
25
24
  else
26
- File.open(Dir.pwd.dup.concat(File::Separator).concat(self.source_location[0])
25
+ File.open(File.expand_path(self.source_location[0])
27
26
  ).each_line_from self.source_location[1] do |line|
28
-
29
- line.gsub!(/\bdo\b/,'{')
30
- line.gsub!(/\bend\b/,'}')
31
-
32
- block += line.frequency /{/
33
- block -= line.frequency /}/
34
-
27
+ block += line.source_formater_for_line_sub
35
28
  return_string.concat(line)
36
29
  break if block == 0
37
30
  end
@@ -47,8 +40,21 @@ class Proc
47
40
 
48
41
  return return_string
49
42
  end
50
-
51
43
  end
52
44
  alias :source_string :source
53
45
 
46
+ def call_with_binding(bind, *args)
47
+ Bindless.new([bind]).run_proc(self, *args)
48
+ end
49
+
50
+ def call_with_obj(obj, *args)
51
+ m = nil
52
+ p = self
53
+ Object.class_eval do
54
+ define_method :a_temp_method_name, &p
55
+ m = instance_method :a_temp_method_name; remove_method :a_temp_method_name
56
+ end
57
+ m.bind(obj).call(*args)
58
+ end
59
+
54
60
  end
@@ -92,4 +92,16 @@ class String
92
92
  end
93
93
  end
94
94
 
95
+ # this is a helper to create source strings from procs
96
+ def source_formater_for_line_sub
97
+ self.gsub!(';',"\n")
98
+ self.gsub!(/\bdo\b/,'{')
99
+ self.gsub!(/\bend\b/,'}')
100
+
101
+ self.frequency(/{/)+
102
+ self.frequency(/def/)-
103
+ self.frequency(/}/)
104
+ end
105
+
106
+
95
107
  end
@@ -1,83 +1,10 @@
1
- require "procemon"
1
+ #require "procemon"
2
2
 
3
3
 
4
- #class Hello
5
- #
6
- # def world arg
7
- # puts arg
8
- # end
9
- #
10
- # def hello
11
- # puts "this is hello, hy!"
12
- # end
13
- #
14
- #end
15
- #
16
- #class Proc
17
- #
18
- # def source_code
19
- # puts self.source_location.inspect
20
- #
21
- # end
22
- #
23
- #end
24
- #
25
- #
26
- #
27
- ##.to_proc.source_code
28
- #TestProc= Proc.new do
29
- # puts "hello world!"
30
- #end
31
- #
32
- #SecurityProc = Proc.new{ |*args|
33
- # puts "hello world!"
34
- #}
35
- #
36
- #class Test
37
- #
38
- #
39
- # attr_accessor :test1
40
- # Test= Proc.new do
41
- # puts "hello world"
42
- # end
43
- #
44
- # class << self
45
- # attr_accessor :test2
46
- # end
47
- #
48
- # def hello *args
49
- # puts self.test1.inspect
50
- # end
51
- #
52
- # def self.hello *args
53
- # puts self.test2.inspect
54
- # end
55
- #
56
- # def security_proc *args
57
- # self.class::Test.call *args
58
- # end
59
- #
60
- #
61
- #end
62
- #
63
- ##test= Test.new
64
- ##test.security_proc
65
- #
66
- ##require "sourcify"
67
- ##require "debugger"
68
- ##debugger
69
- #
70
- #puts SecurityProc.source_location.inspect
71
- #puts Test.method(:hello).to_proc.source_location.inspect
72
- #puts TestProc.source_location.inspect
4
+ def hello_world! hello,world
73
5
 
6
+ puts hello
7
+ # than hello,world
8
+ puts world ; puts sender
74
9
 
75
-
76
-
77
-
78
-
79
- #method(:world).get_binding
80
-
81
- #puts test.get_binding
82
- #puts test.get_binding2
83
- #puts test.get_binding
10
+ end
@@ -1,33 +1,11 @@
1
1
  require_relative "../lib/procemon.rb"
2
+ require_relative "lab"
2
3
 
3
- class TestT
4
+ #hello_world!
5
+ #puts Dir.pwd.concat(Proc.new{
6
+ # "hy"
7
+ #}.source_location[0])
4
8
 
5
- def self.test
6
- puts self
7
- end
9
+ puts method(:hello_world!).source
8
10
 
9
- def test
10
- puts self
11
- end
12
11
 
13
- end
14
-
15
- TestT.inject_instance_method :test do
16
-
17
- puts "hello world! instance"
18
-
19
- end
20
-
21
- TestT.inject_singleton_method :test, :after do
22
-
23
- puts "hello world! singleton"
24
-
25
- end
26
-
27
- TestT.test
28
- TestT.new.test
29
-
30
- #> TestT
31
- #> hello world! singleton
32
- #> hello world! instance
33
- #> #<TestT:0x0000000288b808>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -32,18 +32,17 @@ files:
32
32
  - lib/procemon.rb
33
33
  - lib/procemon/function/application.rb
34
34
  - lib/procemon/function/argv.rb
35
+ - lib/procemon/function/binding/binding.rb
36
+ - lib/procemon/function/binding/bindless.rb
35
37
  - lib/procemon/function/daemon.rb
36
38
  - lib/procemon/function/documentation.rb
37
- - lib/procemon/function/eval.rb
38
39
  - lib/procemon/function/macaddr.rb
39
- - lib/procemon/function/meta/binding/binding.rb
40
- - lib/procemon/function/meta/binding/bindless.rb
41
- - lib/procemon/function/meta/binding/proc.rb
40
+ - lib/procemon/function/meta/eval.rb
42
41
  - lib/procemon/function/meta/inject_methods.rb
43
- - lib/procemon/function/meta/source.rb
44
42
  - lib/procemon/function/name.rb
45
43
  - lib/procemon/function/port.rb
46
44
  - lib/procemon/function/require.rb
45
+ - lib/procemon/function/sender.rb
47
46
  - lib/procemon/function/str2duck.rb
48
47
  - lib/procemon/function/systemu.rb
49
48
  - lib/procemon/function/tmp_dir.rb
@@ -54,6 +53,7 @@ files:
54
53
  - lib/procemon/mpatch/hash.rb
55
54
  - lib/procemon/mpatch/integer.rb
56
55
  - lib/procemon/mpatch/kernel.rb
56
+ - lib/procemon/mpatch/method.rb
57
57
  - lib/procemon/mpatch/module.rb
58
58
  - lib/procemon/mpatch/object.rb
59
59
  - lib/procemon/mpatch/proc.rb
@@ -1,17 +0,0 @@
1
- class Proc
2
-
3
- def call_with_binding(bind, *args)
4
- Bindless.new([bind]).run_proc(self, *args)
5
- end
6
-
7
- def call_with_obj(obj, *args)
8
- m = nil
9
- p = self
10
- Object.class_eval do
11
- define_method :a_temp_method_name, &p
12
- m = instance_method :a_temp_method_name; remove_method :a_temp_method_name
13
- end
14
- m.bind(obj).call(*args)
15
- end
16
-
17
- end
File without changes