sdbcli 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sdbcli +1 -1
- data/lib/sdbcli/sdb-runner.rb +91 -35
- metadata +3 -3
data/bin/sdbcli
CHANGED
data/lib/sdbcli/sdb-runner.rb
CHANGED
@@ -22,6 +22,92 @@ class Array
|
|
22
22
|
def avg
|
23
23
|
self.sum / self.length
|
24
24
|
end
|
25
|
+
|
26
|
+
def as_row
|
27
|
+
row = self.dup
|
28
|
+
|
29
|
+
def row.method_missing(method_name)
|
30
|
+
case method_name.to_s
|
31
|
+
when /itemName/i
|
32
|
+
self[0]
|
33
|
+
else
|
34
|
+
self[1][method_name.to_s]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
return row
|
39
|
+
end
|
40
|
+
|
41
|
+
def as_row!
|
42
|
+
row = self
|
43
|
+
|
44
|
+
def row.method_missing(method_name)
|
45
|
+
case method_name.to_s
|
46
|
+
when /itemName/i
|
47
|
+
self[0]
|
48
|
+
else
|
49
|
+
self[1][method_name.to_s]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
return row
|
54
|
+
end
|
55
|
+
|
56
|
+
def as_rows
|
57
|
+
rows = self.dup
|
58
|
+
|
59
|
+
def rows.method_missing(method_name)
|
60
|
+
case method_name.to_s
|
61
|
+
when /itemName/i
|
62
|
+
self.map {|i| i[0] }
|
63
|
+
else
|
64
|
+
self.map {|i| i[1][method_name.to_s] }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
return rows
|
69
|
+
end
|
70
|
+
|
71
|
+
def as_rows!
|
72
|
+
rows = self
|
73
|
+
|
74
|
+
def rows.method_missing(method_name)
|
75
|
+
case method_name.to_s
|
76
|
+
when /itemName/i
|
77
|
+
self.map {|i| i[0] }
|
78
|
+
else
|
79
|
+
self.map {|i| i[1][method_name.to_s] }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
return rows
|
84
|
+
end
|
85
|
+
|
86
|
+
def inline
|
87
|
+
obj = self.dup
|
88
|
+
def obj.to_yaml_style; :inline; end
|
89
|
+
return obj
|
90
|
+
end
|
91
|
+
|
92
|
+
def inline!
|
93
|
+
obj = self
|
94
|
+
def obj.to_yaml_style; :inline; end
|
95
|
+
return obj
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Hash
|
100
|
+
def inline
|
101
|
+
obj = self.dup
|
102
|
+
def obj.to_yaml_style; :inline; end
|
103
|
+
return obj
|
104
|
+
end
|
105
|
+
|
106
|
+
def inline!
|
107
|
+
obj = self
|
108
|
+
def obj.to_yaml_style; :inline; end
|
109
|
+
return obj
|
110
|
+
end
|
25
111
|
end
|
26
112
|
|
27
113
|
module SimpleDB
|
@@ -92,11 +178,7 @@ module SimpleDB
|
|
92
178
|
case command
|
93
179
|
when :GET
|
94
180
|
item = @driver.get(parsed.domain, parsed.item_name, parsed.attr_names, consistent)
|
95
|
-
|
96
|
-
if inline
|
97
|
-
def item.to_yaml_style; :inline; end
|
98
|
-
end
|
99
|
-
|
181
|
+
item.inline! if inline
|
100
182
|
item
|
101
183
|
when :INSERT
|
102
184
|
rownum = parsed.items.length
|
@@ -149,24 +231,10 @@ module SimpleDB
|
|
149
231
|
end
|
150
232
|
|
151
233
|
unless items.kind_of?(Integer)
|
152
|
-
|
153
|
-
case method_name.to_s
|
154
|
-
when /itemName/i
|
155
|
-
self.map {|i| i[0] }
|
156
|
-
else
|
157
|
-
self.map {|i| i[1][method_name.to_s] }
|
158
|
-
end
|
159
|
-
end
|
234
|
+
items.as_rows!
|
160
235
|
|
161
236
|
items.each do |item|
|
162
|
-
|
163
|
-
case method_name.to_s
|
164
|
-
when /itemName/i
|
165
|
-
self[0]
|
166
|
-
else
|
167
|
-
self[1][method_name.to_s]
|
168
|
-
end
|
169
|
-
end
|
237
|
+
item.as_row!
|
170
238
|
end
|
171
239
|
|
172
240
|
def items.group_by(name, &block)
|
@@ -176,17 +244,7 @@ module SimpleDB
|
|
176
244
|
key = item[1][name.to_s]
|
177
245
|
|
178
246
|
unless item_h[key]
|
179
|
-
item_list = []
|
180
|
-
|
181
|
-
def item_list.method_missing(method_name)
|
182
|
-
case method_name.to_s
|
183
|
-
when /itemName/i
|
184
|
-
self.map {|i| i[0] }
|
185
|
-
else
|
186
|
-
self.map {|i| i[1][method_name.to_s] }
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
247
|
+
item_list = [].as_rows
|
190
248
|
item_h[key] = item_list
|
191
249
|
end
|
192
250
|
|
@@ -222,9 +280,7 @@ module SimpleDB
|
|
222
280
|
|
223
281
|
if inline and items.kind_of?(Array)
|
224
282
|
items.each do |item|
|
225
|
-
if item.kind_of?(Array)
|
226
|
-
def item.to_yaml_style; :inline; end
|
227
|
-
end
|
283
|
+
item.inline! if item.kind_of?(Array)
|
228
284
|
end
|
229
285
|
end
|
230
286
|
|
metadata
CHANGED