procemon 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +4 -2
- data/VERSION +1 -1
- data/lib/procemon/extra/str2duck.rb +1 -89
- data/lib/procemon.rb +1 -1
- data/procemon.gemspec +1 -0
- metadata +16 -19
- data/lib/procemon/function/binding/binding.rb +0 -17
- data/lib/procemon/function/validation.rb +0 -21
- data/lib/procemon/mpatch/array.rb +0 -149
- data/lib/procemon/mpatch/boolean.rb +0 -15
- data/lib/procemon/mpatch/class.rb +0 -92
- data/lib/procemon/mpatch/exception.rb +0 -0
- data/lib/procemon/mpatch/file.rb +0 -71
- data/lib/procemon/mpatch/hash.rb +0 -101
- data/lib/procemon/mpatch/integer.rb +0 -12
- data/lib/procemon/mpatch/kernel.rb +0 -9
- data/lib/procemon/mpatch/module.rb +0 -16
- data/lib/procemon/mpatch/object.rb +0 -250
- data/lib/procemon/mpatch/proc.rb +0 -27
- data/lib/procemon/mpatch/process.rb +0 -14
- data/lib/procemon/mpatch/random.rb +0 -39
- data/lib/procemon/mpatch/string.rb +0 -78
- data/lib/procemon/mpatch/yml.rb +0 -11
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTc0ZjMxOGUyM2YwZjI0ZTBmMTBlMGFiMzY2MDk1M2JmMDUwZjAxMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWU2NzZjZGRhYzM5ZGVkNmMzYmM4Yjc0NWUyMDkzYWU3NzkzMDFkZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzA2MmE3NTQ0NjM1YjRhZDcxYjdhMzkyOTUzYThmNGI3OTI5NGY2YmYxZjk1
|
10
|
+
MzFiYWQxYzNkYzVjYTUzZTAwY2E0ZDY2YmYyOGNjN2U0OWY3NmMyMzBlOWMy
|
11
|
+
OWNiYTE2ZGMxYjNkY2ZlYzU1ZmU0ZGJmOTMzODAxNjYwNTVlZmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTViNmJhYTAwYjZjYTMwMDZjMzU5MTUxZGE5ODc5NmIxYzEyMmJlNjFlYWM4
|
14
|
+
ZTU1ZDdlNGJhYWJhODgzODVmODNjY2E0M2U0N2U2Yjc1OTNiZGQ3YTg3YzUz
|
15
|
+
Nzc0MGNkODBhNzAyZTYxZTc5YTQzYzU2NDk0NTE1ZTY4YjE0MWE=
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
procemon (0.
|
4
|
+
procemon (0.8.1)
|
5
5
|
asynchronous
|
6
6
|
loader
|
7
|
+
mpatch
|
7
8
|
sourcerer
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: http://rubygems.org/
|
11
12
|
specs:
|
12
|
-
asynchronous (1.0.
|
13
|
+
asynchronous (1.0.4)
|
13
14
|
loader (1.0.2)
|
15
|
+
mpatch (1.0.0)
|
14
16
|
sourcerer (0.5.2)
|
15
17
|
|
16
18
|
PLATFORMS
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
@@ -1,90 +1,2 @@
|
|
1
1
|
require File.join 'active_support','time'
|
2
|
-
|
3
|
-
class String
|
4
|
-
|
5
|
-
def duck
|
6
|
-
|
7
|
-
begin
|
8
|
-
if self == self.to_f.to_s
|
9
|
-
return self.to_f
|
10
|
-
end
|
11
|
-
rescue NoMethodError
|
12
|
-
end
|
13
|
-
|
14
|
-
begin
|
15
|
-
if self == self.to_i.to_s
|
16
|
-
return self.to_i
|
17
|
-
end
|
18
|
-
rescue NoMethodError
|
19
|
-
end
|
20
|
-
|
21
|
-
begin
|
22
|
-
if self.gsub(":","") == self.to_datetime.to_s.gsub(
|
23
|
-
"T"," ").gsub("+"," +").gsub(":","")
|
24
|
-
return self.to_datetime
|
25
|
-
end
|
26
|
-
rescue Exception
|
27
|
-
end
|
28
|
-
|
29
|
-
begin
|
30
|
-
if self == self.to_datetime.to_s
|
31
|
-
return self.to_datetime
|
32
|
-
end
|
33
|
-
rescue Exception
|
34
|
-
end
|
35
|
-
|
36
|
-
begin
|
37
|
-
if self == self.to_date.to_s
|
38
|
-
return self.to_date
|
39
|
-
end
|
40
|
-
rescue Exception
|
41
|
-
end
|
42
|
-
|
43
|
-
begin
|
44
|
-
if self == "true"
|
45
|
-
return true
|
46
|
-
end
|
47
|
-
rescue NoMethodError
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
begin
|
52
|
-
if self == "false"
|
53
|
-
return false
|
54
|
-
end
|
55
|
-
rescue NoMethodError
|
56
|
-
end
|
57
|
-
|
58
|
-
begin
|
59
|
-
string_input= self
|
60
|
-
contain= nil
|
61
|
-
["[", "]","^","$","*","/"].each do |one_sym|
|
62
|
-
if string_input.include? one_sym
|
63
|
-
contain ||= true
|
64
|
-
end
|
65
|
-
end
|
66
|
-
if contain == true
|
67
|
-
string_regexp= Regexp.new(string_input).inspect#.gsub('\\','')
|
68
|
-
string_regexp= string_regexp[1..(string_regexp.length-2)]
|
69
|
-
if string_input == string_regexp
|
70
|
-
return Regexp.new(string_input)
|
71
|
-
else
|
72
|
-
raise ArgumentError,"invalid input string"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
rescue ArgumentError
|
76
|
-
end
|
77
|
-
|
78
|
-
begin
|
79
|
-
if self == self.to_s.to_s
|
80
|
-
return self.to_s
|
81
|
-
end
|
82
|
-
rescue NoMethodError
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
alias :to_duck :duck
|
88
|
-
alias :to_d :duck
|
89
|
-
|
90
|
-
end
|
2
|
+
require File.join 'mpatch','active_support','str2duck'
|
data/lib/procemon.rb
CHANGED
data/procemon.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.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-02-
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asynchronous
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mpatch
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: ! 'This is a collection of my Ruby Procs in the adventure of becoming
|
56
70
|
the best! In short this provides extra tools in Application configs, argumens processing,daemonise,eval,
|
57
71
|
getting source of a block,method,process and work with it, or even fuse them into
|
@@ -81,7 +95,6 @@ files:
|
|
81
95
|
- lib/procemon/extra/str2duck.rb
|
82
96
|
- lib/procemon/function/application.rb
|
83
97
|
- lib/procemon/function/argv.rb
|
84
|
-
- lib/procemon/function/binding/binding.rb
|
85
98
|
- lib/procemon/function/binding/bindless.rb
|
86
99
|
- lib/procemon/function/daemon.rb
|
87
100
|
- lib/procemon/function/documentation.rb
|
@@ -92,22 +105,6 @@ files:
|
|
92
105
|
- lib/procemon/function/name.rb
|
93
106
|
- lib/procemon/function/port.rb
|
94
107
|
- lib/procemon/function/tmp_dir.rb
|
95
|
-
- lib/procemon/function/validation.rb
|
96
|
-
- lib/procemon/mpatch/array.rb
|
97
|
-
- lib/procemon/mpatch/boolean.rb
|
98
|
-
- lib/procemon/mpatch/class.rb
|
99
|
-
- lib/procemon/mpatch/exception.rb
|
100
|
-
- lib/procemon/mpatch/file.rb
|
101
|
-
- lib/procemon/mpatch/hash.rb
|
102
|
-
- lib/procemon/mpatch/integer.rb
|
103
|
-
- lib/procemon/mpatch/kernel.rb
|
104
|
-
- lib/procemon/mpatch/module.rb
|
105
|
-
- lib/procemon/mpatch/object.rb
|
106
|
-
- lib/procemon/mpatch/proc.rb
|
107
|
-
- lib/procemon/mpatch/process.rb
|
108
|
-
- lib/procemon/mpatch/random.rb
|
109
|
-
- lib/procemon/mpatch/string.rb
|
110
|
-
- lib/procemon/mpatch/yml.rb
|
111
108
|
- procemon.gemspec
|
112
109
|
- scripts/doc_gen.rb
|
113
110
|
- scripts/test.txt
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
|
3
|
-
# basic validations for those who fear the DUCK!
|
4
|
-
def must_be class_name
|
5
|
-
if class_name.class == Class
|
6
|
-
begin
|
7
|
-
if self.class != class_name
|
8
|
-
raise ArgumentError, "invalid parameter given: #{self}"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
else
|
12
|
-
begin
|
13
|
-
if self != class_name
|
14
|
-
raise ArgumentError, "invalid parameter given: #{self}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
return self
|
19
|
-
end unless method_defined? :must_be
|
20
|
-
|
21
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
|
3
|
-
# remove arguments or array of
|
4
|
-
# parameters from the main array
|
5
|
-
def trim(*args)
|
6
|
-
|
7
|
-
args.dup.each do |one_element|
|
8
|
-
if one_element.class == Array
|
9
|
-
args.delete_at(args.index(one_element))
|
10
|
-
args= args+one_element
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
delete_array= Array.new
|
15
|
-
args.each do |one_element|
|
16
|
-
index= self.index(one_element)
|
17
|
-
unless index.nil?
|
18
|
-
delete_array.push index
|
19
|
-
self.delete_at(index)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
return self
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
# return index of the target element
|
28
|
-
def index_of(target_element)
|
29
|
-
array = self
|
30
|
-
hash = Hash[array.map.with_index.to_a]
|
31
|
-
return hash[target_element]
|
32
|
-
end
|
33
|
-
|
34
|
-
# remove n. element from the end
|
35
|
-
# and return a new object
|
36
|
-
def pinch n=1
|
37
|
-
return self[0..(self.count-(n+1))]
|
38
|
-
end
|
39
|
-
|
40
|
-
# remove n. element from the end
|
41
|
-
# and return the original object
|
42
|
-
def pinch! n=1
|
43
|
-
n.times do
|
44
|
-
self.pop
|
45
|
-
end
|
46
|
-
return self
|
47
|
-
end
|
48
|
-
|
49
|
-
# return boolean by other array
|
50
|
-
# all element included or
|
51
|
-
# not in the target array
|
52
|
-
def contain?(oth_array)#anothere array
|
53
|
-
(oth_array & self) == oth_array
|
54
|
-
end
|
55
|
-
|
56
|
-
# return boolean by other array
|
57
|
-
# if any element included from
|
58
|
-
# the oth_array, return a true
|
59
|
-
def contain_any_of?(oth_array)
|
60
|
-
oth_array.each do |element|
|
61
|
-
if self.include? element
|
62
|
-
return true
|
63
|
-
end
|
64
|
-
end
|
65
|
-
return false
|
66
|
-
end
|
67
|
-
|
68
|
-
alias :contains_any_of? :contain_any_of?
|
69
|
-
alias :has_any_of? :contain_any_of?
|
70
|
-
|
71
|
-
# do safe transpose
|
72
|
-
def safe_transpose
|
73
|
-
result = []
|
74
|
-
max_size = self.max { |a,b| a.size <=> b.size }.size
|
75
|
-
max_size.times do |i|
|
76
|
-
result[i] = Array.new(self.first.size)
|
77
|
-
self.each_with_index { |r,j| result[i][j] = r[i] }
|
78
|
-
end
|
79
|
-
result
|
80
|
-
end
|
81
|
-
|
82
|
-
alias :contains? :contain?
|
83
|
-
|
84
|
-
# return boolean
|
85
|
-
# if any element class is equal to th given class
|
86
|
-
# return a true , else false
|
87
|
-
def contain_element_of_class?(class_name)
|
88
|
-
target_array= self.map{|e| e.class }.uniq
|
89
|
-
if class_name.class != Class
|
90
|
-
raise ArgumentError, "Argument must be a Class!"
|
91
|
-
end
|
92
|
-
if target_array.include? class_name
|
93
|
-
return true
|
94
|
-
end
|
95
|
-
return false
|
96
|
-
end
|
97
|
-
|
98
|
-
alias :contains_element_of_class? :contain_element_of_class?
|
99
|
-
alias :has_element_of_class? :contain_element_of_class?
|
100
|
-
|
101
|
-
# generate params structure from array
|
102
|
-
# *args => [:opts,:args]
|
103
|
-
def params_separation
|
104
|
-
|
105
|
-
options= self.map { |element|
|
106
|
-
if element.class == Hash
|
107
|
-
element
|
108
|
-
end
|
109
|
-
}.uniq - [ nil ]
|
110
|
-
#options.each{|e| self.delete(e) }
|
111
|
-
arguments= self.dup - options
|
112
|
-
options= Hash[*options]
|
113
|
-
|
114
|
-
return [options,arguments]
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
alias :separate_params :params_separation
|
119
|
-
alias :process_params :params_separation
|
120
|
-
|
121
|
-
# generate params structure from array
|
122
|
-
# return_array
|
123
|
-
def extract_class! class_name
|
124
|
-
|
125
|
-
if class_name.class != Class
|
126
|
-
raise ArgumentError, "parameter must be a class name"
|
127
|
-
end
|
128
|
-
|
129
|
-
return_value= self.map { |element|
|
130
|
-
if element.class == class_name
|
131
|
-
element
|
132
|
-
end
|
133
|
-
}.uniq - [ nil ]
|
134
|
-
return_value.each{|e| self.delete(e) }
|
135
|
-
|
136
|
-
return return_value
|
137
|
-
|
138
|
-
end
|
139
|
-
alias :cut_class! :extract_class!
|
140
|
-
|
141
|
-
# generate params structure from array
|
142
|
-
# *args - options {}
|
143
|
-
def extract_options!
|
144
|
-
options= self.extract_class! Hash
|
145
|
-
return Hash[*options]
|
146
|
-
end
|
147
|
-
alias :extract_hash! :extract_options!
|
148
|
-
|
149
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
class Class
|
2
|
-
|
3
|
-
# get singleton methods to target class without super class methods
|
4
|
-
def class_methods
|
5
|
-
self.methods - Object.methods
|
6
|
-
end
|
7
|
-
|
8
|
-
# bind a singleton method to a class object
|
9
|
-
def create_class_method(method,&block)
|
10
|
-
self.class_eval do
|
11
|
-
define_singleton_method method do |*args|
|
12
|
-
block.call *args
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# create an instance method
|
18
|
-
def create_instance_method(method,&block)
|
19
|
-
self.class_eval do
|
20
|
-
define_method method do |*args|
|
21
|
-
block.call *args
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Iterates over all subclasses (direct and indirect)
|
27
|
-
def each_subclass
|
28
|
-
ObjectSpace.each_object(Class) { | candidate |
|
29
|
-
begin
|
30
|
-
yield candidate if candidate < self
|
31
|
-
rescue ArgumentError
|
32
|
-
# comparison of Class with Class failed (ArgumentError)
|
33
|
-
end
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns an Array of subclasses (direct and indirect)
|
38
|
-
def subclasses_all
|
39
|
-
ret = []
|
40
|
-
each_subclass {|c| ret.push c}
|
41
|
-
ret
|
42
|
-
end
|
43
|
-
|
44
|
-
alias :all_subclasses :subclasses_all
|
45
|
-
|
46
|
-
# Returns an Array of direct subclasses
|
47
|
-
def subclasses
|
48
|
-
ret = []
|
49
|
-
each_subclass {|c| ret.push(c) if c.superclass == self }
|
50
|
-
ret
|
51
|
-
end
|
52
|
-
alias :subclass :subclasses
|
53
|
-
|
54
|
-
# create singleton attribute
|
55
|
-
def class_attr_accessor(name)
|
56
|
-
|
57
|
-
### GET
|
58
|
-
begin
|
59
|
-
define_method name do
|
60
|
-
class_variable_get "@@#{name}"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
### SET
|
65
|
-
begin
|
66
|
-
define_method "#{name}=" do |new_val|
|
67
|
-
class_variable_set "@@#{name}", new_val
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
# create class instance attribute
|
74
|
-
def instance_attr_accessor(name)
|
75
|
-
|
76
|
-
### GET
|
77
|
-
begin
|
78
|
-
define_method name do
|
79
|
-
instance_variable_get "@#{name}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
### SET
|
84
|
-
begin
|
85
|
-
define_method "#{name}=" do |new_val|
|
86
|
-
instance_variable_set "@#{name}", new_val
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
File without changes
|
data/lib/procemon/mpatch/file.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
class File
|
2
|
-
|
3
|
-
# create a file, if not exsist create file, and dir if needed
|
4
|
-
def self.create(route_name ,filemod="w",string_data=String.new)
|
5
|
-
begin
|
6
|
-
|
7
|
-
#file_name generate
|
8
|
-
if !route_name.to_s.split(File::SEPARATOR).last.nil? || route_name.to_s.split(File::SEPARATOR).last != ''
|
9
|
-
file_name = route_name.to_s.split(File::SEPARATOR).last
|
10
|
-
else
|
11
|
-
file_name = nil?
|
12
|
-
end
|
13
|
-
|
14
|
-
#path_way
|
15
|
-
begin
|
16
|
-
raise ArgumentError, "missing route_name: #{route_name}" if route_name.nil?
|
17
|
-
path = File.expand_path(route_name).to_s.split(File::SEPARATOR)
|
18
|
-
path = path - [File.expand_path(route_name).to_s.split(File::SEPARATOR).last]
|
19
|
-
path.shift
|
20
|
-
end
|
21
|
-
|
22
|
-
#job
|
23
|
-
begin
|
24
|
-
if !Dir.exists?(File::SEPARATOR+path.join(File::SEPARATOR))
|
25
|
-
|
26
|
-
at_now = File::SEPARATOR
|
27
|
-
path.each do |dir_to_be_checked|
|
28
|
-
|
29
|
-
at_now += "#{dir_to_be_checked+File::SEPARATOR}"
|
30
|
-
Dir.mkdir(at_now) if !Dir.exists?(at_now)
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# write data
|
37
|
-
begin
|
38
|
-
full_path = "#{File::SEPARATOR+path.join(File::SEPARATOR)+File::SEPARATOR}#{file_name}"
|
39
|
-
if File.exist? full_path
|
40
|
-
File.open(full_path,filemod).write string_data
|
41
|
-
else
|
42
|
-
File.new(full_path,filemod).write string_data
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
rescue Exception => ex
|
47
|
-
puts ex
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# start read the file object on each line
|
52
|
-
# optionable an integer value to start read line at
|
53
|
-
# compatible with mac (i am linux user, so not tested)
|
54
|
-
def each_line_from(start_at=1,&block)
|
55
|
-
unless [Integer,Fixnum,Bignum].include?(start_at.class)
|
56
|
-
raise ArgumentError, "invalid line index"
|
57
|
-
end
|
58
|
-
begin
|
59
|
-
line_num= 1
|
60
|
-
text= self.read
|
61
|
-
text.gsub!(/\r\n?/, "\n")
|
62
|
-
text.each_line do |*line|
|
63
|
-
if line_num >= start_at
|
64
|
-
block.call #*line
|
65
|
-
end
|
66
|
-
line_num += 1
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
data/lib/procemon/mpatch/hash.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
|
3
|
-
# remove elements by keys,
|
4
|
-
# array of keys,
|
5
|
-
# hashTags,
|
6
|
-
# strings
|
7
|
-
def trim(*args)
|
8
|
-
|
9
|
-
args.each do |one_element|
|
10
|
-
case true
|
11
|
-
|
12
|
-
when one_element.class == Hash
|
13
|
-
begin
|
14
|
-
one_element.each do |key,value|
|
15
|
-
if self[key] == value
|
16
|
-
self.delete(key)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
when one_element.class == Array
|
22
|
-
begin
|
23
|
-
one_element.each do |one_key|
|
24
|
-
self.delete(one_key)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
when one_element.class == Symbol,
|
29
|
-
one_element.class == String
|
30
|
-
begin
|
31
|
-
self.delete(one_element)
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
return self
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
#pass single or array of keys, which will be removed, returning the remaining hash
|
41
|
-
def remove!(*keys)
|
42
|
-
keys.each{|key| self.delete(key) }
|
43
|
-
self
|
44
|
-
end
|
45
|
-
|
46
|
-
#non-destructive version
|
47
|
-
def remove(*keys)
|
48
|
-
self.dup.remove!(*keys)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
52
|
-
#
|
53
|
-
# h1 = {:x => {:y => [4,5,6]}, :z => [7,8,9]}
|
54
|
-
# h2 = {:x => {:y => [7,8,9]}, :z => "xyz"}
|
55
|
-
#
|
56
|
-
# h1.deep_merge(h2) #=> { :x => {:y => [7, 8, 9]}, :z => "xyz" }
|
57
|
-
# h2.deep_merge(h1) #=> { :x => {:y => [4, 5, 6]}, :z => [7, 8, 9] }
|
58
|
-
def deep_merge(other_hash)
|
59
|
-
dup.deep_merge!(other_hash)
|
60
|
-
end unless method_defined? :deep_merge
|
61
|
-
|
62
|
-
alias :+ :deep_merge
|
63
|
-
|
64
|
-
# Same as +deep_merge+, but modifies +self+.
|
65
|
-
def deep_merge!(other_hash)
|
66
|
-
other_hash.each_pair do |k,v|
|
67
|
-
tv = self[k]
|
68
|
-
self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
|
69
|
-
end
|
70
|
-
self
|
71
|
-
end unless method_defined? :deep_merge!
|
72
|
-
|
73
|
-
# return bool that does the sub hash all element include the hash who call this or not
|
74
|
-
def deep_include?(sub_hash)
|
75
|
-
sub_hash.keys.all? do |key|
|
76
|
-
self.has_key?(key) && if sub_hash[key].is_a?(Hash)
|
77
|
-
self[key].is_a?(Hash) && self[key].deep_include?(sub_hash[key])
|
78
|
-
else
|
79
|
-
self[key] == sub_hash[key]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end unless method_defined? :deep_include?
|
83
|
-
|
84
|
-
def map_hash &block
|
85
|
-
|
86
|
-
tmp_hash= Hash.new
|
87
|
-
map_hash_obj= self.map &block
|
88
|
-
map_hash_obj.each do |hash|
|
89
|
-
|
90
|
-
if hash.class <= Array
|
91
|
-
hash= Hash[*hash]
|
92
|
-
end
|
93
|
-
|
94
|
-
tmp_hash.deep_merge!(hash)
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
return tmp_hash
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class Module
|
2
|
-
|
3
|
-
# return the module objects direct sub modules
|
4
|
-
def modules
|
5
|
-
constants.collect {|const_name| const_get(const_name)}.select {|const| const.class == Module}
|
6
|
-
end
|
7
|
-
|
8
|
-
# return the module objects direct sub modules
|
9
|
-
def classes
|
10
|
-
constants.collect {|const_name| const_get(const_name)}.select {|const| const.class == Class}
|
11
|
-
end
|
12
|
-
|
13
|
-
alias :submodules :modules
|
14
|
-
alias :subclasses :classes
|
15
|
-
|
16
|
-
end
|
@@ -1,250 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
|
3
|
-
# The hidden singleton lurks behind everyone
|
4
|
-
def metaclass; class << self; self; end; end
|
5
|
-
|
6
|
-
# extend the metaclass with an instance eval
|
7
|
-
def meta_eval &blk; metaclass.instance_eval &blk; end
|
8
|
-
|
9
|
-
# Adds methods to a metaclass
|
10
|
-
def meta_def name, &blk
|
11
|
-
meta_eval { define_method name, &blk }
|
12
|
-
end
|
13
|
-
|
14
|
-
# Defines an instance method within a class
|
15
|
-
def class_def name, &blk
|
16
|
-
class_eval { define_method name, &blk }
|
17
|
-
end
|
18
|
-
|
19
|
-
# constantize object
|
20
|
-
def constantize
|
21
|
-
camel_cased_word= self.to_s
|
22
|
-
names = camel_cased_word.split('::')
|
23
|
-
names.shift if names.empty? || names.first.empty?
|
24
|
-
|
25
|
-
constant = Object
|
26
|
-
names.each do |name|
|
27
|
-
constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
|
28
|
-
end
|
29
|
-
constant
|
30
|
-
end unless method_defined? :constantize
|
31
|
-
|
32
|
-
# find and replace object in object
|
33
|
-
def find_and_replace(input,*params)
|
34
|
-
params=Hash[*params]
|
35
|
-
# some default values
|
36
|
-
begin
|
37
|
-
#None!
|
38
|
-
end
|
39
|
-
# Do the find and replace
|
40
|
-
begin
|
41
|
-
|
42
|
-
if input.class == Array
|
43
|
-
input.count.times do |counter|
|
44
|
-
params.each do |key,value|
|
45
|
-
input[counter]= input[counter].gsub(key,value)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
elsif input.class == String
|
49
|
-
params.each do |key,value|
|
50
|
-
input= input.gsub(key,value)
|
51
|
-
end
|
52
|
-
elsif input.class == Integer
|
53
|
-
params.each do |key,value|
|
54
|
-
input= input.to_s.gsub(key,value).to_i
|
55
|
-
end
|
56
|
-
elsif input.class == Float
|
57
|
-
params.each do |key,value|
|
58
|
-
input= input.to_s.gsub(key,value).to_f
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# return value
|
63
|
-
return input
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# each for any object
|
68
|
-
def each_universal(&block)
|
69
|
-
case self.class.to_s.downcase
|
70
|
-
when "hash"
|
71
|
-
self.each do |key,value|
|
72
|
-
block.call(key,value)
|
73
|
-
end
|
74
|
-
when "array"
|
75
|
-
self.each do |one_element|
|
76
|
-
block.call(self.index(one_element),one_element)
|
77
|
-
end
|
78
|
-
else
|
79
|
-
block.call nil,self
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# map an object => experiment
|
84
|
-
def map_object(symbol_key="$type")
|
85
|
-
|
86
|
-
stage = self
|
87
|
-
do_later = Hash.new
|
88
|
-
samples = Hash.new
|
89
|
-
relations = Hash.new
|
90
|
-
main_object = nil
|
91
|
-
|
92
|
-
loop do
|
93
|
-
|
94
|
-
# processing
|
95
|
-
begin
|
96
|
-
|
97
|
-
tmp_key = String.new
|
98
|
-
tmp_hash= Hash.new
|
99
|
-
stage.each_universal do |key,value|
|
100
|
-
|
101
|
-
if value.class.to_s.downcase == "string"
|
102
|
-
|
103
|
-
if key== symbol_key
|
104
|
-
tmp_key= value
|
105
|
-
main_object ||= value
|
106
|
-
else
|
107
|
-
tmp_hash[key]= value
|
108
|
-
end
|
109
|
-
|
110
|
-
else
|
111
|
-
|
112
|
-
value.each_universal do |key_sub,value_sub|
|
113
|
-
if key_sub == symbol_key && tmp_key != String.new
|
114
|
-
child_property = Hash.new
|
115
|
-
child_property['type']= value_sub
|
116
|
-
child_property['class']= value.class.to_s
|
117
|
-
relations[tmp_key]= child_property
|
118
|
-
end
|
119
|
-
do_later[key_sub]= value_sub
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
if tmp_key != String.new && tmp_hash != Hash.new
|
126
|
-
samples[tmp_key]=tmp_hash
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
# finish
|
132
|
-
begin
|
133
|
-
break if do_later == Hash.new
|
134
|
-
stage= do_later
|
135
|
-
do_later = Hash.new
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
return {:samples => samples,
|
141
|
-
:relations => relations,
|
142
|
-
:main => main_object
|
143
|
-
}
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
# is class?
|
148
|
-
def class?
|
149
|
-
self.class == Class
|
150
|
-
end
|
151
|
-
|
152
|
-
# convert class instance instance variables into a hash object
|
153
|
-
def convert_to_hash
|
154
|
-
|
155
|
-
unless self.class.class == Class
|
156
|
-
raise NoMethodError, "undefined method `to_hash' for #{self.inspect}"
|
157
|
-
end
|
158
|
-
|
159
|
-
tmp_hash= Hash.new()
|
160
|
-
self.instance_variables.each do|var|
|
161
|
-
tmp_hash[var.to_s.delete("@")] = self.instance_variable_get(var)
|
162
|
-
end
|
163
|
-
|
164
|
-
return tmp_hash
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
# this will check that the class is
|
169
|
-
# defined or not in the runtime memory
|
170
|
-
def class_exists?
|
171
|
-
klass = Module.const_get(self)
|
172
|
-
return klass.is_a?(Class)
|
173
|
-
rescue NameError
|
174
|
-
return false
|
175
|
-
end
|
176
|
-
|
177
|
-
# This will convert a symbol or string and format to be a valid
|
178
|
-
# constant name and create from it a class with instance attribute accessors
|
179
|
-
# Best use is when you get raw data in string from external source
|
180
|
-
# and you want make them class objects
|
181
|
-
#
|
182
|
-
# :hello_world.to_class(:test)
|
183
|
-
# HelloWorld.to_class(:sup)
|
184
|
-
# hw_var = HelloWorld.new
|
185
|
-
# hw_var.sup = "Fine thanks!"
|
186
|
-
# hw_var.test = 5
|
187
|
-
#
|
188
|
-
# puts hw_var.test
|
189
|
-
#
|
190
|
-
# #> produce 5 :Integer
|
191
|
-
#
|
192
|
-
# you can also use this formats
|
193
|
-
# :HelloWorld , "hello.world",
|
194
|
-
# "hello/world", "Hello::World",
|
195
|
-
# "hello:world"...
|
196
|
-
def to_class(*attributes)
|
197
|
-
|
198
|
-
unless self.class == Symbol || self.class == String || self.class == Class
|
199
|
-
raise ArgumentError, "object must be symbol or string to make able build class to it"
|
200
|
-
end
|
201
|
-
|
202
|
-
class_name= self.to_s
|
203
|
-
|
204
|
-
unless self.class == Class
|
205
|
-
|
206
|
-
class_name= class_name[0].upcase+class_name[1..class_name.length]
|
207
|
-
%w[ _ . : / ].each do |one_sym|
|
208
|
-
|
209
|
-
loop do
|
210
|
-
index_nmb= class_name.index(one_sym)
|
211
|
-
break if index_nmb.nil?
|
212
|
-
class_name[index_nmb..index_nmb+1]= class_name[index_nmb+1].upcase
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|
216
|
-
|
217
|
-
end
|
218
|
-
|
219
|
-
create_attribute = Proc.new do |*args|
|
220
|
-
|
221
|
-
end
|
222
|
-
|
223
|
-
unless class_name.class_exists?
|
224
|
-
|
225
|
-
Object.const_set(
|
226
|
-
class_name,
|
227
|
-
Class.new
|
228
|
-
)
|
229
|
-
|
230
|
-
end
|
231
|
-
|
232
|
-
|
233
|
-
class_name.constantize.class_eval do
|
234
|
-
attributes.each do |one_attribute|
|
235
|
-
attr_accessor one_attribute.to_s.to_sym
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
return true
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
alias :create_attributes :to_class
|
246
|
-
alias :map_sample :map_object
|
247
|
-
alias :each_univ :each_universal
|
248
|
-
alias :fnr :find_and_replace
|
249
|
-
|
250
|
-
end
|
data/lib/procemon/mpatch/proc.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
class Proc
|
2
|
-
|
3
|
-
# sugar syntax for proc * operator
|
4
|
-
# a = ->(x){x+1}
|
5
|
-
# b = ->(x){x*10}
|
6
|
-
# c = b*a
|
7
|
-
# c.call(1) #=> 20
|
8
|
-
def *(other)
|
9
|
-
Proc.new { |*args| self[*other[*args]] }
|
10
|
-
end unless method_defined? :*
|
11
|
-
|
12
|
-
def call_with_binding(bind, *args)
|
13
|
-
Bindless.new([bind]).run_proc(self, *args)
|
14
|
-
end
|
15
|
-
|
16
|
-
def call_with_obj(obj, *args)
|
17
|
-
m = nil
|
18
|
-
p = self
|
19
|
-
Object.class_eval do
|
20
|
-
define_method :a_temp_method_name, &p
|
21
|
-
m = instance_method :a_temp_method_name
|
22
|
-
remove_method :a_temp_method_name
|
23
|
-
end
|
24
|
-
m.bind(obj).call(*args)
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Process
|
2
|
-
def self.daemonize
|
3
|
-
File.create Application.pid,'a+'
|
4
|
-
File.create Application.log,'a+'
|
5
|
-
File.create Application.daemon_stderr,'a+'
|
6
|
-
Daemon.start fork,
|
7
|
-
Application.pid,
|
8
|
-
Application.log,
|
9
|
-
Application.daemon_stderr
|
10
|
-
end
|
11
|
-
def self.stop
|
12
|
-
Daemon.stop
|
13
|
-
end
|
14
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
class RND
|
2
|
-
class << self
|
3
|
-
def string(length= 7,amount=1,hyphen= " ")
|
4
|
-
amount_container= Array.new
|
5
|
-
amount.times do
|
6
|
-
mrg= String.new
|
7
|
-
mrg= (0...length).map{ ('a'..'z').to_a[rand(26)] }.join
|
8
|
-
amount_container.push mrg
|
9
|
-
end
|
10
|
-
return amount_container.join(hyphen)
|
11
|
-
end
|
12
|
-
def integer(length= 3)
|
13
|
-
Random.rand(length)
|
14
|
-
end
|
15
|
-
def boolean
|
16
|
-
rand(2) == 1
|
17
|
-
end
|
18
|
-
def time from = Time.at(1114924812), to = Time.now
|
19
|
-
rand(from..to)
|
20
|
-
end
|
21
|
-
def date from = Time.at(1114924812), to = Time.now
|
22
|
-
rand(from..to).to_date
|
23
|
-
end
|
24
|
-
def datetime from = Time.at(1114924812), to = Time.now
|
25
|
-
rand(from..to).to_datetime
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# alias in Random from RND
|
31
|
-
begin
|
32
|
-
(RND.singleton_methods-Object.singleton_methods).each do |one_method_sym|
|
33
|
-
Random.class_eval do
|
34
|
-
define_singleton_method one_method_sym do |*args|
|
35
|
-
RND.__send__(one_method_sym,*args)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
# Find string in othere string
|
4
|
-
def positions(oth_string)
|
5
|
-
|
6
|
-
special_chrs=%w[# _ & < > @ $ . , -]+[*(0..9)]+[*("A".."Z")]+[*("a".."z")]
|
7
|
-
loop do
|
8
|
-
if oth_string.include? special_chrs[0]
|
9
|
-
special_chrs.shift
|
10
|
-
else
|
11
|
-
break
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
string=self
|
16
|
-
return_array = Array.new
|
17
|
-
loop do
|
18
|
-
break if string.index(oth_string).nil?
|
19
|
-
range_value= ((string.index(oth_string))..(string.index(oth_string)+oth_string.length-1))
|
20
|
-
return_array.push range_value
|
21
|
-
[*range_value].each do |one_index|
|
22
|
-
string[one_index]= special_chrs[0]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# return value
|
27
|
-
return return_array
|
28
|
-
end
|
29
|
-
|
30
|
-
# Standard in rails. See official documentation
|
31
|
-
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
32
|
-
def camelize(first_letter = :upper)
|
33
|
-
if first_letter == :upper
|
34
|
-
gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
35
|
-
else
|
36
|
-
self[0..0].downcase + camelize[1..-1]
|
37
|
-
end
|
38
|
-
end unless method_defined? :camelize
|
39
|
-
|
40
|
-
# Standard in rails. See official documentation
|
41
|
-
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
42
|
-
def dasherize
|
43
|
-
gsub(/_/, '-')
|
44
|
-
end unless method_defined? :dasherize
|
45
|
-
|
46
|
-
# Standard in rails. See official documentation
|
47
|
-
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
48
|
-
def demodulize
|
49
|
-
gsub(/^.*::/, '')
|
50
|
-
end unless method_defined? :demodulize
|
51
|
-
|
52
|
-
# Standard in rails. See official documentation
|
53
|
-
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
54
|
-
def underscore
|
55
|
-
gsub(/::/, '/').
|
56
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
57
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
58
|
-
tr("-", "_").
|
59
|
-
downcase
|
60
|
-
end unless method_defined? :underscore
|
61
|
-
|
62
|
-
# Check that instance of String is start with an upper case or not
|
63
|
-
def capitalized?
|
64
|
-
self.match(/^[[:upper:]]/) ? true : false
|
65
|
-
end
|
66
|
-
|
67
|
-
# return the number how often the str is with in the self
|
68
|
-
# by default with \b regex border
|
69
|
-
def frequency(str)
|
70
|
-
begin
|
71
|
-
if str.class == String
|
72
|
-
str= '\b'+str+'\b'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
self.scan(/#{str}/).count
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
data/lib/procemon/mpatch/yml.rb
DELETED