husky 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/husky/data_source.rb +23 -1
- 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: 03a7334afed3c27cb45e6e810a36658b5d43e2c8
|
4
|
+
data.tar.gz: c2650753e06b957e63fedbcc83d494af80b6e461
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d3a59ce42284484b60d87437225dd9e4ffe899b235a37e868c22f1fa7c6893f239af64f54b92b3ace8f7588a6e7c1f93f3674c3caf4ac542c409bea8bc1e187
|
7
|
+
data.tar.gz: be05328b02db665e09fe1f83b102b07eeac9589c0f855ef665a8072e7b23dfe64cdf0c548aeb6880e128c499b6fbf959bb3e4d335969fdf720da19483d17fcad
|
data/lib/husky/data_source.rb
CHANGED
@@ -10,7 +10,8 @@ module Husky
|
|
10
10
|
define_method association do
|
11
11
|
singular_association = association.to_s[0..-2].to_sym
|
12
12
|
klass_id = "#{self.class.name.split('::')[1].downcase}_id".to_sym
|
13
|
-
Husky::Repo::Registry.for(singular_association).all.select { |k,v| v.send(klass_id) == self.id }
|
13
|
+
set = Husky::Repo::Registry.for(singular_association).all.select { |k,v| v.send(klass_id) == self.id }
|
14
|
+
Husky::DataSource::MemoryRelation.new(set, self)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -33,6 +34,27 @@ module Husky
|
|
33
34
|
|
34
35
|
end
|
35
36
|
|
37
|
+
class MemoryRelation
|
38
|
+
include Enumerable
|
39
|
+
|
40
|
+
attr_reader :set, :caller, :receiver
|
41
|
+
|
42
|
+
def initialize(set, caller, receiver)
|
43
|
+
@set = set
|
44
|
+
@caller = caller
|
45
|
+
@receiver = receiver
|
46
|
+
end
|
47
|
+
|
48
|
+
def each
|
49
|
+
set.map { |item| yield item }
|
50
|
+
end
|
51
|
+
|
52
|
+
def create(attributes)
|
53
|
+
receiver.create({ "#{caller.class.downcase}_id".to_sym => caller.id })
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
36
58
|
end
|
37
59
|
|
38
60
|
end
|
data/lib/husky/version.rb
CHANGED