procemon 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,362 +11,13 @@ tmp folder helpers, Application centralized datas, folder structure logic ,
11
11
  meta data control, dynamic lib read etc
12
12
 
13
13
 
14
- short lazy doc
15
-
16
-
17
-
18
- in Str2duck
19
-
20
- convert string object to something what is it looks to be as duck type mean to do
21
- useful for RESTfull aps when data sent as string
22
- duck
23
-
24
-
25
- in Tmp_dir
26
-
27
- init a tmpdir in the OS tmp folder with the application name
28
- (by default this is the root folder name)
29
- tmpdir_init
30
-
31
-
32
- in Name
33
-
34
- what it looks to be
35
- set_app_name_by_root_folder
36
-
37
-
38
- in Argv
39
-
40
- what it looks to be
41
- process_parameters
42
-
43
-
44
- in Daemon
45
-
46
- Checks to see if the current process is the child process and if not
47
- will update the pid file with the child pid.
48
- self.start pid, pidfile, outfile, errfile
49
-
50
- Attempts to write the pid of the forked process to the pid file.
51
- self.write pid, pidfile
52
-
53
- Try and read the existing pid from the pid file and signal the
54
- process. Returns true for a non blocking status.
55
- self.kill(pidfile)
56
-
57
- Send stdout and stderr to log files for the child process
58
- self.redirect outfile, errfile
59
- self.daemonize
60
- self.kill_with_pid
61
- self.terminate
62
- self.kill_by_name(*args)
63
- self.stop
64
- self.init
65
-
66
-
67
- in Inject_methods
68
-
69
- this will inject a code block to a target instance method
70
- by default the before or after sym is not required
71
- default => before
72
-
73
- Test.inject_singleton_method :hello do |*args|
74
- puts "singleton extra, so{args[0]}"
75
- end
76
-
77
- inject_singleton_method(method,options=:before,&block)
78
-
79
- Singleton.methods[self.object_id]= self.method(method)
80
- this will inject a code block to a target singleton method
81
- by default the before or after sym is not required
82
- default => before
83
-
84
- Test.inject_instance_method :hello, :before do |*args|
85
- puts "singleton on a instance method and "+args[0]
86
- end
87
-
88
- inject_instance_method(method,options=:before,&block)
89
-
90
-
91
- in Require
92
-
93
- load meta-s
94
- meta_load(app_folder= Dir.pwd)
95
-
96
- find elements
97
- get_meta_config(app_folder= Dir.pwd)
98
-
99
- defaults
100
- find elements
101
- defaults
102
- processing
103
- return data
104
- mount libs
105
- mount_libs(app_folder= Dir.pwd)
106
-
107
- load lib files
108
- Offline repo activate
109
- mount_modules(app_folder= Dir.pwd)
110
-
111
- Return File_name => File_path
112
- get_files(folder)
113
-
114
- Validation
115
- Check that does the folder is absolute or not
116
- Get Files list
117
- Return file_name:folder
118
- require by absolute path directory's files
119
- require_directory(folder)
120
-
121
- require sender relative directory's files
122
- require_relative_directory(folder)
123
-
124
- generate config from yaml (default is app_root/config folder)
125
- generate_config(target_config_hash= Application.config,app_folder= Dir.pwd)
126
-
127
- try load all the ruby files marked with "generate" in they name from app_root/docs
128
- generate_documentation(boolean= false,keyword= "generate",app_folder= Dir.pwd)
129
-
130
-
131
- in Port
132
-
133
- get_port(mint_port,max_port,host="0.0.0.0")
134
- port_open?(port,host="0.0.0.0")
135
-
136
-
137
- in Eval
138
-
139
- NOT working yet, need to rework the exclude method
140
- safe_eval(string [, binding [, filename [,lineno]]] *allowed_class/module_names ) -> obj
141
-
142
- Evaluates the Ruby expression(s) in <em>string</em>. If
143
- <em>binding</em> is given, which must be a <code>Binding</code>
144
- object, the evaluation is performed in its context. If the
145
- optional <em>filename</em> and <em>lineno</em> parameters are
146
- present, they will be used when reporting syntax errors.
147
-
148
- def get_binding(str)
149
- return binding
150
- end
151
- str = "hello"
152
- safe_eval "str + ' Fred'" ,Kernel#=> "hello Fred"
153
- safe_eval "str + ' Fred'", get_binding("bye") ,Kernel#=> "bye Fred"
154
- safe_eval(*args)
155
-
156
-
157
- in Process
158
-
159
- self.daemonize
160
- self.stop
161
-
162
-
163
- in String
164
-
165
- Find string in othere string
166
- positions(oth_string)
167
-
168
- return value
169
- Standard in rails. See official documentation
170
- [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
171
- camelize(first_letter = :upper)
172
-
173
- Standard in rails. See official documentation
174
- [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
175
- dasherize
176
-
177
- Standard in rails. See official documentation
178
- [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
179
- demodulize
180
-
181
- Standard in rails. See official documentation
182
- [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
183
- underscore
184
-
185
- Check that instance of String is start with an upper case or not
186
- capitalized?
187
-
188
-
189
- in Yml
190
-
191
- self.save_file(file_path,config_hash)
192
-
193
- self.load_file(file_path)
194
-
195
-
196
- in Object
197
-
198
- The hidden singleton lurks behind everyone
199
- metaclass; class << self; self; end; end
200
-
201
- extend the metaclass with an instance eval
202
- meta_eval &blk; metaclass.instance_eval &blk; end
203
-
204
- Adds methods to a metaclass
205
- meta_name, &blk
206
-
207
- Defines an instance method within a class
208
- class_name, &blk
209
-
210
- constantize object
211
- constantize
212
-
213
- find and replace object in object
214
- find_and_replace(input,*params)
215
-
216
- it was made only for fun to make same each to array and hash and everything
217
- each_universal(&block)
218
-
219
- map an object => experiment
220
- map_object(symbol_key="$type")
221
-
222
- is class?
223
- class?
224
-
225
- convert class instance instance variables into a hash object
226
- convert_to_hash
227
-
228
- this will check that the class is
229
- defined or not in the runtime memory
230
- class_exists?
231
-
232
- This will convert a symbol or string and format to be a valid
233
- constant name and create from it a class with instance attribute accessors
234
- Best use is when you get raw data in string from external source
235
- and you want make them class objects
236
-
237
- :hello_world.to_class(:test)
238
- HelloWorld.to_class(:sup)
239
- hw_var = HelloWorld.new
240
- hw_var.sup = "Fine thanks!"
241
- hw_var.test = 5
242
-
243
- puts hw_var.test
244
-
245
- > produce 5 :Integer
246
-
247
- you can also use this formats
248
- :HelloWorld , "hello.world",
249
- "hello/world", "Hello::World",
250
- "hello:world"...
251
- to_class(*attributes)
252
- or
253
- create_attributes(*attributes)
254
-
255
- in File
256
-
257
- self.create(route_name ,filemod="w",string_data=String.new)
258
-
259
-
260
- in Array
261
-
262
- remove arguments or array of
263
- parameters from the main array
264
- trim(*args)
265
-
266
- return index of the target element
267
- index_of(target_element)
268
-
269
- remove n. element from the end
270
- and return a new object
271
- pinch n=1
272
-
273
- remove n. element from the end
274
- and return the original object
275
- pinch! n=1
276
-
277
- return boolean by other array
278
- all element included or
279
- not in the target array
280
- contain?(oth_array)#anothere array
281
-
282
- do safe transpose
283
- safe_transpose
284
-
285
-
286
- in Class
287
-
288
- get singleton methods to target class without super class methods
289
- class_methods
290
-
291
- bind a singleton method to a class object
292
- create_class_method(method,&block)
293
-
294
- create an instance method
295
- create_instance_method(method,&block)
296
-
297
- Iterates over all subclasses (direct and indirect)
298
- each_subclass
299
-
300
- Returns an Array of subclasses (direct and indirect)
301
- subclasses
302
-
303
- Returns an Array of direct subclasses
304
- direct_subclasses
305
-
306
- create singleton attribute
307
- class_attr_accessor(name)
308
-
309
- GET
310
- SET
311
- create class instance attribute
312
- instance_attr_accessor(name)
313
-
314
-
315
- in Integer
316
-
317
- because for i in integer/fixnum not working,
318
- here is a little patch
319
- each &block
320
-
321
-
322
- in Random
323
-
324
- string(length= 7,amount=1)
325
-
326
- integer(length= 3)
327
-
328
- boolean
329
-
330
- time from = Time.at(1114924812), to = Time.now
331
-
332
- date from = Time.at(1114924812), to = Time.now
333
-
334
- datetime from = Time.at(1114924812), to = Time.now
335
-
336
-
337
- in Hash
338
-
339
- remove elements by keys,
340
- array of keys,
341
- hashTags,
342
- strings
343
- trim(*args)
344
-
345
- pass single or array of keys, which will be removed, returning the remaining hash
346
- remove!(*keys)
347
-
348
- non-destructive version
349
- remove(*keys)
350
-
351
- Returns a new hash with +self+ and +other_hash+ merged recursively.
352
-
353
- h1 = {:x => {:y => [4,5,6]}, :z => [7,8,9]}
354
- h2 = {:x => {:y => [7,8,9]}, :z => "xyz"}
355
- #
356
- h1.deep_merge(h2#=> { :x => {:y => [7, 8, 9]}, :z => "xyz" }
357
- h2.deep_merge(h1#=> { :x => {:y => [4, 5, 6]}, :z => [7, 8, 9] }
358
- deep_merge(other_hash)
359
-
360
- Same as +deep_merge+, but modifies +self+.
361
- deep_merge!(other_hash)
362
-
363
- return bool that does the sub hash all element include the hash who call this or not
364
- deep_include?(sub_hash)
365
-
366
-
367
- in Kernel
368
-
369
- eats puts like formated printf method
370
- just use an integer what will be the distance
371
- between elements and the elements next to it
372
- putsf(integer,*args)
14
+ There is really lot of helper method, i mean i even lose my life love if i want to start describe all of them
15
+ you can generate rdoc if you want, i more like examples, so from now on,
16
+ i will make examples!
17
+
18
+ The first one tells you how to NOT monkey patch methods in modules.
19
+ You want use a module? sure awsome !
20
+ You need to add plus functionality but dont want to follow the module updates
21
+ (in case of conflight with the monkey patch)
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!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -0,0 +1,33 @@
1
+ require 'procemon'
2
+
3
+ class TestT
4
+
5
+ def self.test
6
+ puts self
7
+ end
8
+
9
+ def test
10
+ puts self
11
+ end
12
+
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>
@@ -17,21 +17,17 @@ class Class
17
17
  self.singleton_class.__send__ :undef_method, method
18
18
  self.class_eval do
19
19
  define_singleton_method method do |*arguments|
20
- case true
21
20
 
22
- when options == :before
23
- begin
24
- block.call_with_binding self.get_binding, *arguments
25
- original_method.call *arguments
26
- end
21
+ if options == :before
22
+ block.source.to_proc(self.binding?).call *arguments
23
+ end
27
24
 
28
- when options == :after
29
- begin
30
- original_method.call *arguments
31
- block.call_with_binding self.get_binding, *arguments
32
- end
25
+ original_method.call *arguments
33
26
 
27
+ if options == :after
28
+ block.source.to_proc(self.binding?).call *arguments
34
29
  end
30
+
35
31
  end
36
32
  end
37
33
 
@@ -46,25 +42,20 @@ class Class
46
42
  # end
47
43
  #
48
44
  def inject_instance_method(method,options=:before,&block)
45
+
49
46
  self.class_eval do
50
47
  alias_method :"old_#{method.to_s}", method
51
48
  end
52
49
  extended_process = Proc.new do |*args|
53
50
 
54
- case true
55
-
56
- when options == :before
57
- begin
58
- block.call_with_binding self.get_binding, *args
59
- self.__send__ :"old_#{method.to_s}", *args
60
- end
51
+ if options == :before
52
+ block.source.to_proc(self.binding?).call *args
53
+ end
61
54
 
62
- when options == :after
63
- begin
64
- self.__send__ :"old_#{method.to_s}", *args
65
- block.call_with_binding self.get_binding, *args
66
- end
55
+ self.__send__ :"old_#{method.to_s}", *args
67
56
 
57
+ if options == :after
58
+ block.source.to_proc(self.binding?).call *args
68
59
  end
69
60
 
70
61
  end
@@ -20,7 +20,6 @@ class Proc
20
20
  return_string= String.new
21
21
  block= 0
22
22
  end
23
-
24
23
  if @@source_cache.keys.include? self.object_id
25
24
  return @@source_cache[self.object_id]
26
25
  else
@@ -39,10 +38,17 @@ class Proc
39
38
 
40
39
  return_string.sub!(/^[\w\W]*Proc.new\s*{/,'Proc.new{')
41
40
  return_string.sub!(/}[^}]*$/,"}")
41
+
42
+ if !return_string.include?('Proc.new')
43
+ return_string.sub!(/^[^{]*(?!={)/,'Proc.new')
44
+ end
45
+
42
46
  @@source_cache[self.object_id]= return_string
47
+
43
48
  return return_string
44
49
  end
45
50
 
46
51
  end
52
+ alias :source_string :source
47
53
 
48
54
  end
@@ -1,17 +1,33 @@
1
1
  require_relative "../lib/procemon.rb"
2
2
 
3
+ class TestT
4
+
5
+ def self.test
6
+ puts self
7
+ end
8
+
9
+ def test
10
+ puts self
11
+ end
3
12
 
4
- class Test1
5
13
  end
6
14
 
7
- class Test2 < Test1
15
+ TestT.inject_instance_method :test do
16
+
17
+ puts "hello world! instance"
8
18
 
9
19
  end
10
20
 
21
+ TestT.inject_singleton_method :test, :after do
11
22
 
12
- ret= Array.new
13
- Test1.each_subclass{|c| ret.push c}
14
- puts ret
23
+ puts "hello world! singleton"
15
24
 
25
+ end
16
26
 
27
+ TestT.test
28
+ TestT.new.test
17
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.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,7 @@ files:
27
27
  - README.md
28
28
  - Rakefile
29
29
  - VERSION
30
+ - examples/how_to_inject_with_extra_process_a_method.rb
30
31
  - files.rb
31
32
  - lib/procemon.rb
32
33
  - lib/procemon/function/application.rb