hello_server_client 0.0.0 → 0.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/hello_server_client/service.rb +28 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3bfa9e9e596b477562f7397809efc2f7929d45a
|
4
|
+
data.tar.gz: 1a11e603d3d30e94b44707a6f9c1ca131e6d5e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5472247761b9d22aacb8bbdb30c7c8e949ff9c47abddc32c7e3e47ecadc841596600b8ef4d419372ba76b7e228e3b2aac605a8858b047f604c2c0736428719ab
|
7
|
+
data.tar.gz: 56f371c9586b7ed3b3366cae9fcdd137768accfabc093acb811662100647af4fba2d4c27363a7f6cadf91bc2979df6b818c5d4a8ab6461bed76a17375e587c5f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
@@ -9,13 +9,16 @@ module HelloServerClient
|
|
9
9
|
|
10
10
|
attribute :name
|
11
11
|
unique :name
|
12
|
+
# can be slower that commented piece of code below
|
12
13
|
attribute :value, Type::Hash
|
13
14
|
|
14
15
|
index :name
|
15
16
|
|
16
17
|
def self.find_or_initialize_by_name(name)
|
17
18
|
# find doesn't work
|
18
|
-
s = self.
|
19
|
+
#s = self.find(name: name)
|
20
|
+
#s = self.all.select { |o| o.name == name }.first
|
21
|
+
s = find_by_name(name)
|
19
22
|
if s.nil?
|
20
23
|
s = self.new
|
21
24
|
s.name = name
|
@@ -23,6 +26,30 @@ module HelloServerClient
|
|
23
26
|
return s
|
24
27
|
end
|
25
28
|
|
29
|
+
def self.find_by_name(name)
|
30
|
+
@@index = Hash.new unless defined? @@index
|
31
|
+
id = @@index[name]
|
32
|
+
if id
|
33
|
+
# something is indexed
|
34
|
+
obj = self[id]
|
35
|
+
if obj and obj.name == name
|
36
|
+
# good index
|
37
|
+
return obj
|
38
|
+
else
|
39
|
+
@@index.delete(name)
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
else
|
43
|
+
# get object
|
44
|
+
obj = self.all.select { |o| o.name == name }.first
|
45
|
+
if obj
|
46
|
+
@@index[name] = obj.id
|
47
|
+
return obj
|
48
|
+
else
|
49
|
+
return nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
26
53
|
|
27
54
|
#attribute :value_json
|
28
55
|
#def value
|