duck_record 0.0.3 → 0.0.5
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/README.md +25 -6
- data/Rakefile +0 -1
- data/lib/duck_record/associations/association.rb +86 -0
- data/lib/duck_record/associations/builder/association.rb +98 -0
- data/lib/duck_record/associations/builder/collection_association.rb +48 -0
- data/lib/duck_record/associations/builder/has_many.rb +7 -0
- data/lib/duck_record/associations/builder/has_one.rb +15 -0
- data/lib/duck_record/associations/builder/singular_association.rb +22 -0
- data/lib/duck_record/associations/collection_association.rb +187 -0
- data/lib/duck_record/associations/collection_proxy.rb +894 -0
- data/lib/duck_record/associations/has_many_association.rb +12 -0
- data/lib/duck_record/associations/has_one_association.rb +12 -0
- data/lib/duck_record/associations/singular_association.rb +39 -0
- data/lib/duck_record/associations.rb +1317 -0
- data/lib/duck_record/base.rb +4 -0
- data/lib/duck_record/errors.rb +8 -0
- data/lib/duck_record/locale/en.yml +1 -5
- data/lib/duck_record/nested_attributes.rb +531 -0
- data/lib/duck_record/nested_validate_association.rb +262 -0
- data/lib/duck_record/reflection.rb +309 -0
- data/lib/duck_record/version.rb +1 -1
- data/lib/duck_record.rb +10 -4
- metadata +17 -2
@@ -0,0 +1,12 @@
|
|
1
|
+
module DuckRecord
|
2
|
+
# = Active Record Has Many Association
|
3
|
+
module Associations
|
4
|
+
# This is the proxy that handles a has many association.
|
5
|
+
#
|
6
|
+
# If the association has a <tt>:through</tt> option further specialization
|
7
|
+
# is provided by its child HasManyThroughAssociation.
|
8
|
+
class HasManyAssociation < CollectionAssociation #:nodoc:
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module DuckRecord
|
2
|
+
module Associations
|
3
|
+
class SingularAssociation < Association #:nodoc:
|
4
|
+
# Implements the reader method, e.g. foo.bar for Foo.has_one :bar
|
5
|
+
def reader
|
6
|
+
target
|
7
|
+
end
|
8
|
+
|
9
|
+
# Implements the writer method, e.g. foo.bar= for Foo.belongs_to :bar
|
10
|
+
def writer(record)
|
11
|
+
replace(record)
|
12
|
+
end
|
13
|
+
|
14
|
+
def build(attributes = {})
|
15
|
+
record = build_record(attributes)
|
16
|
+
yield(record) if block_given?
|
17
|
+
set_new_record(record)
|
18
|
+
record
|
19
|
+
end
|
20
|
+
|
21
|
+
# Implements the reload reader method, e.g. foo.reload_bar for
|
22
|
+
# Foo.has_one :bar
|
23
|
+
def force_reload_reader
|
24
|
+
klass.uncached { reload }
|
25
|
+
target
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def replace(_record)
|
31
|
+
raise NotImplementedError, "Subclasses must implement a replace(record) method"
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_new_record(record)
|
35
|
+
replace(record)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|