procemon 0.0.1

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.
@@ -0,0 +1,20 @@
1
+ module Procemon
2
+ class << self
3
+
4
+ require "tmpdir"
5
+ def tmpdir_init
6
+ begin
7
+ Dir.mkdir File.join(Dir.tmpdir,$0)
8
+ rescue Errno::EEXIST
9
+ end
10
+
11
+ Application.tmpdir= File.join(Dir.tmpdir,$0)
12
+
13
+ Application.pid= File.join(Application.tmpdir,"pid")
14
+ Application.log= File.join(Application.tmpdir,"log")
15
+ Application.daemon_stderr= File.join(Application.tmpdir,"daemon_stderr")
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,59 @@
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
35
+ def pinch n=1
36
+ return self[0..(self.count-2)]
37
+ end
38
+
39
+ # return boolean by other array
40
+ # all element included or
41
+ # not in the target array
42
+ def contain?(oth_array)#anothere array
43
+ (oth_array & self) == oth_array
44
+ #(oth_array - self).size == 0
45
+ end
46
+
47
+ # do safe transpose
48
+ def safe_transpose
49
+ result = []
50
+ max_size = self.max { |a,b| a.size <=> b.size }.size
51
+ max_size.times do |i|
52
+ result[i] = Array.new(self.first.size)
53
+ self.each_with_index { |r,j| result[i][j] = r[i] }
54
+ end
55
+ result
56
+ end
57
+
58
+ alias :contains? :contain?
59
+ end
@@ -0,0 +1,85 @@
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
+ yield candidate if candidate < self
30
+ }
31
+ end
32
+
33
+ # Returns an Array of subclasses (direct and indirect)
34
+ def subclasses
35
+ ret = []
36
+ each_subclass {|c| ret << c}
37
+ ret
38
+ end
39
+
40
+ # Returns an Array of direct subclasses
41
+ def direct_subclasses
42
+ ret = []
43
+ each_subclass {|c| ret << c if c.superclass == self }
44
+ ret
45
+ end
46
+
47
+ # create singleton attribute
48
+ def class_attr_accessor(name)
49
+
50
+ ### GET
51
+ begin
52
+ define_method name do
53
+ class_variable_get "@@#{name}"
54
+ end
55
+ end
56
+
57
+ ### SET
58
+ begin
59
+ define_method "#{name}=" do |new_val|
60
+ class_variable_set "@@#{name}", new_val
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ # create class instance attribute
67
+ def instance_attr_accessor(name)
68
+
69
+ ### GET
70
+ begin
71
+ define_method name do
72
+ instance_variable_get "@#{name}"
73
+ end
74
+ end
75
+
76
+ ### SET
77
+ begin
78
+ define_method "#{name}=" do |new_val|
79
+ instance_variable_set "@#{name}", new_val
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ end
File without changes
@@ -0,0 +1,48 @@
1
+ class File
2
+ def self.create(route_name ,filemod="w",string_data=String.new)
3
+ begin
4
+
5
+ #file_name generate
6
+ if !route_name.to_s.split(File::SEPARATOR).last.nil? || route_name.to_s.split(File::SEPARATOR).last != ''
7
+ file_name = route_name.to_s.split(File::SEPARATOR).last
8
+ else
9
+ file_name = nil?
10
+ end
11
+
12
+ #path_way
13
+ begin
14
+ raise ArgumentError, "missing route_name: #{route_name}" if route_name.nil?
15
+ path = File.expand_path(route_name).to_s.split(File::SEPARATOR)
16
+ path = path - [File.expand_path(route_name).to_s.split(File::SEPARATOR).last]
17
+ path.shift
18
+ end
19
+
20
+ #job
21
+ begin
22
+ if !Dir.exists?(File::SEPARATOR+path.join(File::SEPARATOR))
23
+
24
+ at_now = File::SEPARATOR
25
+ path.each do |dir_to_be_checked|
26
+
27
+ at_now += "#{dir_to_be_checked+File::SEPARATOR}"
28
+ Dir.mkdir(at_now) if !Dir.exists?(at_now)
29
+
30
+ end
31
+ end
32
+ end
33
+
34
+ # write data
35
+ begin
36
+ full_path = "#{File::SEPARATOR+path.join(File::SEPARATOR)+File::SEPARATOR}#{file_name}"
37
+ if File.exist? full_path
38
+ File.open(full_path,filemod).write string_data
39
+ else
40
+ File.new(full_path,filemod).write string_data
41
+ end
42
+ end
43
+
44
+ rescue Exception => ex
45
+ puts ex
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,82 @@
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
+ # Same as +deep_merge+, but modifies +self+.
63
+ def deep_merge!(other_hash)
64
+ other_hash.each_pair do |k,v|
65
+ tv = self[k]
66
+ self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
67
+ end
68
+ self
69
+ end unless method_defined? :deep_merge!
70
+
71
+ # return bool that does the sub hash all element include the hash who call this or not
72
+ def deep_include?(sub_hash)
73
+ sub_hash.keys.all? do |key|
74
+ self.has_key?(key) && if sub_hash[key].is_a?(Hash)
75
+ self[key].is_a?(Hash) && self[key].deep_include?(sub_hash[key])
76
+ else
77
+ self[key] == sub_hash[key]
78
+ end
79
+ end
80
+ end unless method_defined? :deep_include?
81
+
82
+ end
@@ -0,0 +1,9 @@
1
+ def putsf(integer,*args)
2
+ command_string=String.new
3
+ args.each do |one_element|
4
+ command_string+="%-#{integer}s"
5
+ end
6
+ command_string+="\n"
7
+ printf command_string,*args
8
+ end
9
+
@@ -0,0 +1,172 @@
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
+ alias :map_sample :map_object
169
+ alias :each_univ :each_universal
170
+ alias :fnr :find_and_replace
171
+
172
+ end