husky 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/lib/husky/repo.rb +85 -31
- data/lib/husky/version.rb +1 -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: 38617c348471e3451f02be3b42be8c1f22b20ed5
|
4
|
+
data.tar.gz: 1997480f17df4f4b6a37d841678ec0cc969fe599
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed6658e6fc0c8b844f271ca86d3e4bb2ef517b90a18bda8176724079fd76f50d59f68904a2d10c5918b7e9897696f45d2a3ced400ef6a17ff88cb9b47ef2226
|
7
|
+
data.tar.gz: 6e0b859e4f7b38e072baf3079ee3c255a00f3ef8d9a52cdce24a5152fdd4f94370239f4549e22cded589dcf27d4cd1f6956b56ce6939aac4ca674f4da4b7e529
|
data/lib/husky/repo.rb
CHANGED
@@ -1,48 +1,102 @@
|
|
1
1
|
module Husky
|
2
2
|
|
3
|
-
|
3
|
+
module Repo
|
4
4
|
|
5
|
-
|
6
|
-
entity.new(data_source.new(attributes))
|
7
|
-
end
|
5
|
+
class ActiveRecord
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def all
|
8
|
+
entity.wrap(data_source.all)
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def find(id)
|
12
|
+
entity.new(data_source.find(id))
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
15
|
+
def new(attributes = {})
|
16
|
+
entity.new(data_source.new(attributes))
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
# DEPRECATE
|
20
|
+
def build(attributes)
|
21
|
+
entity.new(data_source.build(attributes))
|
22
|
+
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def save(item)
|
25
|
+
item.save
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def create(attributes)
|
29
|
+
entity.new(data_source.create(attributes))
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def update(item, attributes)
|
33
|
+
entity.new(item.update_attributes(attributes))
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy(item)
|
37
|
+
item.destroy
|
38
|
+
end
|
37
39
|
|
38
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def data_source
|
43
|
+
raise NotImplementedError
|
44
|
+
end
|
45
|
+
|
46
|
+
def entity
|
47
|
+
raise NotImplementedError
|
48
|
+
end
|
39
49
|
|
40
|
-
def data_source
|
41
|
-
raise NotImplementedError
|
42
50
|
end
|
43
51
|
|
44
|
-
|
45
|
-
|
52
|
+
class InMemory
|
53
|
+
|
54
|
+
def initialize
|
55
|
+
@records = {}
|
56
|
+
@id = 1
|
57
|
+
end
|
58
|
+
|
59
|
+
def all
|
60
|
+
@records
|
61
|
+
end
|
62
|
+
|
63
|
+
def new(attributes = {})
|
64
|
+
entity.new(data_source.new(attributes))
|
65
|
+
end
|
66
|
+
|
67
|
+
def find(id)
|
68
|
+
entity.new(@records[id.to_i])
|
69
|
+
end
|
70
|
+
|
71
|
+
def save(object)
|
72
|
+
object.id = @id
|
73
|
+
@records[@id] = object
|
74
|
+
@id += 1
|
75
|
+
entity.new(object)
|
76
|
+
end
|
77
|
+
|
78
|
+
def create(attributes = {})
|
79
|
+
save(new(attributes))
|
80
|
+
end
|
81
|
+
|
82
|
+
def update(item, attributes)
|
83
|
+
entity.new(item.update_attributes(attributes))
|
84
|
+
end
|
85
|
+
|
86
|
+
def destroy(object)
|
87
|
+
@records.delete(object.id)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def data_source
|
93
|
+
raise NotImplementedError
|
94
|
+
end
|
95
|
+
|
96
|
+
def entity
|
97
|
+
raise NotImplementedError
|
98
|
+
end
|
99
|
+
|
46
100
|
end
|
47
101
|
|
48
102
|
end
|
data/lib/husky/version.rb
CHANGED