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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bca77cc0496ae923043c7d6365e634f0162ab913
4
- data.tar.gz: e6dd3b51d6918b2960cacd1d8b15eb9552af9941
3
+ metadata.gz: 38617c348471e3451f02be3b42be8c1f22b20ed5
4
+ data.tar.gz: 1997480f17df4f4b6a37d841678ec0cc969fe599
5
5
  SHA512:
6
- metadata.gz: aacce87652f53d3722687e07c8a1fc898197a484f6011fecf3bbab56a85413e801e9993a72b8a2532f5b5df12ab0e0b43648b273e7ebf573687ad27f6fe4952f
7
- data.tar.gz: d7e37f0393434b9895f28519b56689311dd9a89440b6818bbf0e58cd75037eab80ec231af55d2ac73fd6480b35ac4a23d2fe423ca0a3dd1fa1a37f9f9e397974
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
- class Repo
3
+ module Repo
4
4
 
5
- def new(attributes = {})
6
- entity.new(data_source.new(attributes))
7
- end
5
+ class ActiveRecord
8
6
 
9
- def find(id)
10
- entity.new(data_source.find(id))
11
- end
7
+ def all
8
+ entity.wrap(data_source.all)
9
+ end
12
10
 
13
- def all
14
- entity.wrap(data_source.all)
15
- end
11
+ def find(id)
12
+ entity.new(data_source.find(id))
13
+ end
16
14
 
17
- # DEPRECATE
18
- def build(attributes)
19
- entity.new(data_source.build(attributes))
20
- end
15
+ def new(attributes = {})
16
+ entity.new(data_source.new(attributes))
17
+ end
21
18
 
22
- def create(attributes)
23
- entity.new(data_source.create(attributes))
24
- end
19
+ # DEPRECATE
20
+ def build(attributes)
21
+ entity.new(data_source.build(attributes))
22
+ end
25
23
 
26
- def update(item, attributes)
27
- entity.new(item.update_attributes(attributes))
28
- end
24
+ def save(item)
25
+ item.save
26
+ end
29
27
 
30
- def save(item)
31
- item.save
32
- end
28
+ def create(attributes)
29
+ entity.new(data_source.create(attributes))
30
+ end
33
31
 
34
- def destroy(item)
35
- item.destroy
36
- end
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
- private
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
- def entity
45
- raise NotImplementedError
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
@@ -1,3 +1,3 @@
1
1
  module Husky
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: husky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Fiser