mpatch 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/mpatch/object.rb +12 -129
- data/lib/mpatch/yml.rb +1 -1
- data/lib/mpatch.rb +1 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fe665f1989da12d5a5080e7d5a03e77336f5a7a
|
4
|
+
data.tar.gz: 1752300d634322f35bd8f6fea7b6e574947d483b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cccdc74e6d599d7a57c35578d82d9b7ef023a7285de6e6dedce6c4fe283ddd67eefc5c903f7a29ac29655c6503fb2d3e64fcd705f3b85f160d4489de1c1a33b
|
7
|
+
data.tar.gz: cb6b6c372586bd890af287f9fb2297f372b956c84025a49fb876e627a43318af25f3010a791d0d89b043e6bbc00d58f31fbff31278a76a522c6d329ef57c3fda
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.1
|
data/lib/mpatch/object.rb
CHANGED
@@ -13,6 +13,10 @@ module MPatch
|
|
13
13
|
self == false
|
14
14
|
end
|
15
15
|
|
16
|
+
def class?
|
17
|
+
self.class == ::Class
|
18
|
+
end
|
19
|
+
|
16
20
|
# basic validations for those who fear the DUCK!
|
17
21
|
def must_be class_name
|
18
22
|
if class_name.class == ::Class
|
@@ -49,142 +53,24 @@ module MPatch
|
|
49
53
|
|
50
54
|
# constantize object
|
51
55
|
def constantize
|
56
|
+
|
52
57
|
camel_cased_word= self.to_s
|
53
58
|
names = camel_cased_word.split('::')
|
54
59
|
names.shift if names.empty? || names.first.empty?
|
55
60
|
|
56
|
-
constant =
|
61
|
+
constant = ::Object
|
57
62
|
names.each do |name|
|
58
63
|
constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
|
59
64
|
end
|
60
65
|
constant
|
61
|
-
end unless method_defined? :constantize
|
62
|
-
|
63
|
-
# find and replace object in object
|
64
|
-
def find_and_replace(input,*params)
|
65
|
-
params=Hash[*params]
|
66
|
-
# some default values
|
67
|
-
begin
|
68
|
-
#None!
|
69
|
-
end
|
70
|
-
# Do the find and replace
|
71
|
-
begin
|
72
|
-
|
73
|
-
if input.class <= ::Array
|
74
|
-
input.count.times do |counter|
|
75
|
-
params.each do |key,value|
|
76
|
-
input[counter]= input[counter].gsub(key,value)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
elsif input.class <= ::String
|
80
|
-
params.each do |key,value|
|
81
|
-
input= input.gsub(key,value)
|
82
|
-
end
|
83
|
-
elsif input.class <= ::Integer
|
84
|
-
params.each do |key,value|
|
85
|
-
input= input.to_s.gsub(key,value).to_i
|
86
|
-
end
|
87
|
-
elsif input.class <= ::Float
|
88
|
-
params.each do |key,value|
|
89
|
-
input= input.to_s.gsub(key,value).to_f
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# return value
|
94
|
-
return input
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# each for any object
|
99
|
-
def each_universal(&block)
|
100
|
-
case self.class.to_s.downcase
|
101
|
-
when "hash"
|
102
|
-
self.each do |key,value|
|
103
|
-
block.call(key,value)
|
104
|
-
end
|
105
|
-
when "array"
|
106
|
-
self.each do |one_element|
|
107
|
-
block.call(self.index(one_element),one_element)
|
108
|
-
end
|
109
|
-
else
|
110
|
-
block.call nil,self
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# map an object => experiment
|
115
|
-
def map_object(symbol_key="$type")
|
116
|
-
|
117
|
-
stage = self
|
118
|
-
do_later = ::Hash.new
|
119
|
-
samples = ::Hash.new
|
120
|
-
relations = ::Hash.new
|
121
|
-
main_object = nil
|
122
|
-
|
123
|
-
loop do
|
124
|
-
|
125
|
-
# processing
|
126
|
-
begin
|
127
|
-
|
128
|
-
tmp_key = ::String.new
|
129
|
-
tmp_hash= ::Hash.new
|
130
|
-
stage.each_universal do |key,value|
|
131
|
-
|
132
|
-
if value.class.to_s.downcase == "string"
|
133
|
-
|
134
|
-
if key== symbol_key
|
135
|
-
tmp_key= value
|
136
|
-
main_object ||= value
|
137
|
-
else
|
138
|
-
tmp_hash[key]= value
|
139
|
-
end
|
140
|
-
|
141
|
-
else
|
142
|
-
|
143
|
-
value.each_universal do |key_sub,value_sub|
|
144
|
-
if key_sub == symbol_key && tmp_key != ::String.new
|
145
|
-
child_property = ::Hash.new
|
146
|
-
child_property['type']= value_sub
|
147
|
-
child_property['class']= value.class.to_s
|
148
|
-
relations[tmp_key]= child_property
|
149
|
-
end
|
150
|
-
do_later[key_sub]= value_sub
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
if tmp_key != ::String.new && tmp_hash != ::Hash.new
|
157
|
-
samples[tmp_key]=tmp_hash
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
# finish
|
163
|
-
begin
|
164
|
-
break if do_later == ::Hash.new
|
165
|
-
stage= do_later
|
166
|
-
do_later = ::Hash.new
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
return {:samples => samples,
|
172
|
-
:relations => relations,
|
173
|
-
:main => main_object
|
174
|
-
}
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
# is class?
|
179
|
-
def class?
|
180
|
-
self.class == ::Class
|
181
66
|
end
|
182
67
|
|
183
|
-
#
|
184
|
-
def
|
68
|
+
#convert class instance instance variables into a hash object
|
69
|
+
def convert_to_hash
|
185
70
|
|
186
71
|
unless self.class.class <= ::Class
|
187
|
-
|
72
|
+
super
|
73
|
+
#raise ::NoMethodError, "undefined method `to_hash' for #{self.inspect}"
|
188
74
|
end
|
189
75
|
|
190
76
|
tmp_hash= ::Hash.new()
|
@@ -225,7 +111,7 @@ module MPatch
|
|
225
111
|
# :HelloWorld , "hello.world",
|
226
112
|
# "hello/world", "Hello::World",
|
227
113
|
# "hello:world"...
|
228
|
-
def
|
114
|
+
def convert_to_class(*attributes)
|
229
115
|
|
230
116
|
unless self.class <= ::Symbol || self.class <= ::String || self.class <= ::Class
|
231
117
|
raise ::ArgumentError, "object must be symbol or string to make able build class to it"
|
@@ -274,10 +160,7 @@ module MPatch
|
|
274
160
|
|
275
161
|
end
|
276
162
|
|
277
|
-
alias :create_attributes :
|
278
|
-
alias :map_sample :map_object
|
279
|
-
alias :each_univ :each_universal
|
280
|
-
alias :fnr :find_and_replace
|
163
|
+
alias :create_attributes :convert_to_class
|
281
164
|
|
282
165
|
end
|
283
166
|
end
|
data/lib/mpatch/yml.rb
CHANGED
data/lib/mpatch.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
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-03-
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This is a collection of my Ruby monkey patches for making easer to use
|
14
14
|
the basic classes
|