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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6fef1730b1863ac7aab7931b0ec3726f9e6b4a5
4
- data.tar.gz: 0bdc028622391edd72dc091e56f11015ea25c7bf
3
+ metadata.gz: 03a7334afed3c27cb45e6e810a36658b5d43e2c8
4
+ data.tar.gz: c2650753e06b957e63fedbcc83d494af80b6e461
5
5
  SHA512:
6
- metadata.gz: fcaf796fab39b50b23e531b2f2557cc75bb608c4ccc462c371c414b005624715d5361edbc1360816a1907239f9e7a48fbe390ff41c25bc80d2640062900dfb29
7
- data.tar.gz: 01106404bab685110f5aa5d83694eece1b6ed7c3fb0ea7de097affb939393202489a9774bf4187ecc2741cebdba7246d8efda500fae9a7cb431ca3aa9cffc7e7
6
+ metadata.gz: 6d3a59ce42284484b60d87437225dd9e4ffe899b235a37e868c22f1fa7c6893f239af64f54b92b3ace8f7588a6e7c1f93f3674c3caf4ac542c409bea8bc1e187
7
+ data.tar.gz: be05328b02db665e09fe1f83b102b07eeac9589c0f855ef665a8072e7b23dfe64cdf0c548aeb6880e128c499b6fbf959bb3e4d335969fdf720da19483d17fcad
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Husky
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Fiser