ocean-dynamo 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ module OceanDynamo #:nodoc:
2
+ module Associations #:nodoc:
3
+ #
4
+ # CollectionAssociation is an abstract class that provides common stuff to
5
+ # ease the implementation of association proxies that represent
6
+ # collections. See the class hierarchy in AssociationProxy.
7
+ #
8
+ # CollectionAssociation:
9
+ # HasAndBelongsToManyAssociation => has_and_belongs_to_many
10
+ # HasManyAssociation => has_many
11
+ # HasManyThroughAssociation + ThroughAssociation => has_many :through
12
+ #
13
+ # CollectionAssociation class provides common methods to the collections
14
+ # defined by +has_and_belongs_to_many+, +has_many+ or +has_many+ with
15
+ # +:through association+ option.
16
+ #
17
+ # You need to be careful with assumptions regarding the target: The proxy
18
+ # does not fetch records from the database until it needs them, but new
19
+ # ones created with +build+ are added to the target. So, the target may be
20
+ # non-empty and still lack children waiting to be read from the database.
21
+ # If you look directly to the database you cannot assume that's the entire
22
+ # collection because new records may have been added to the target, etc.
23
+ #
24
+ # If you need to work on all current children, new and existing records,
25
+ # +load_target+ and the +loaded+ flag are your friends.
26
+ #
27
+ class CollectionAssociation < Association #:nodoc:
28
+
29
+ #
30
+ # Resets the collection to the empty array.
31
+ #
32
+ def reset
33
+ super
34
+ @target = []
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ module OceanDynamo
2
+
3
+ class Relation
4
+
5
+ attr_reader :klass
6
+ attr_reader :values
7
+ attr_reader :loaded
8
+
9
+ alias :model :klass
10
+ alias :loaded? :loaded
11
+
12
+
13
+ def initialize(klass, **values)
14
+ @klass = klass
15
+ @values = values
16
+ @loaded = false
17
+ end
18
+
19
+
20
+ def new(*args, &block)
21
+ @klass.new(*args, &block)
22
+ end
23
+
24
+ alias build new
25
+
26
+
27
+ end
28
+
29
+ end
@@ -67,6 +67,7 @@ module OceanDynamo
67
67
  # Barf on unknown attributes here?
68
68
  attrs && attrs.delete_if { |k, v| !fields.has_key?(k) }
69
69
  super(attrs)
70
+ yield self if block_given?
70
71
  end
71
72
 
72
73
 
@@ -1,3 +1,3 @@
1
1
  module OceanDynamo
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-dynamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-01 00:00:00.000000000 Z
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -160,12 +160,19 @@ extensions: []
160
160
  extra_rdoc_files: []
161
161
  files:
162
162
  - config/routes.rb
163
+ - lib/ocean-dynamo/active_record_stuff/association.rb
164
+ - lib/ocean-dynamo/active_record_stuff/collection_association.rb
163
165
  - lib/ocean-dynamo/active_record_stuff/collection_proxy.rb
166
+ - lib/ocean-dynamo/active_record_stuff/has_and_belongs_to_many_association.rb
167
+ - lib/ocean-dynamo/active_record_stuff/has_many_association.rb
164
168
  - lib/ocean-dynamo/active_record_stuff/reflection.rb
165
169
  - lib/ocean-dynamo/active_record_stuff/relation.rb
170
+ - lib/ocean-dynamo/associations/association.rb
166
171
  - lib/ocean-dynamo/associations/associations.rb
167
172
  - lib/ocean-dynamo/associations/belongs_to.rb
173
+ - lib/ocean-dynamo/associations/collection_association.rb
168
174
  - lib/ocean-dynamo/associations/has_many.rb
175
+ - lib/ocean-dynamo/associations/relation.rb
169
176
  - lib/ocean-dynamo/attributes.rb
170
177
  - lib/ocean-dynamo/basal.rb
171
178
  - lib/ocean-dynamo/class_variables.rb