occams-record 0.8.1 → 0.9.0
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/lib/occams-record/eager_loaders.rb +2 -2
- data/lib/occams-record/eager_loaders/base.rb +5 -3
- data/lib/occams-record/eager_loaders/polymorphic_belongs_to.rb +3 -2
- data/lib/occams-record/merge.rb +3 -3
- data/lib/occams-record/query.rb +10 -0
- data/lib/occams-record/raw_query.rb +9 -0
- data/lib/occams-record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 011e5e6f67a6eeb9ad95fe8e314c443099e9d06c
|
4
|
+
data.tar.gz: 595a4ed16e94f1abf7fc33e32f1d067308f814fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca932af1da71d11622e5cdf077ae48b9a5114c144ed01ef4b3cd590ba06f4916ab539df201fd01fa14477239ebd78598bdd031380d87aaa73b9d5b626a2ed5ca
|
7
|
+
data.tar.gz: d8755fb3d2c0520531aaea1f7266e5420f755277a394a35138a8a7be6fe3a35c0f061bfbf479ece0900518cb50448d1847a5166eb00c98594bff07f7ada5657a
|
@@ -24,11 +24,11 @@ module OccamsRecord
|
|
24
24
|
# @param eval_block [Proc] a block where you may perform eager loading on *this* association (optional)
|
25
25
|
# @return [OccamsRecord::Query] returns self
|
26
26
|
#
|
27
|
-
def eager_load(assoc, scope = nil, select: nil, use: nil, &eval_block)
|
27
|
+
def eager_load(assoc, scope = nil, select: nil, use: nil, as: nil, &eval_block)
|
28
28
|
ref = @model ? @model.reflections[assoc.to_s] : nil
|
29
29
|
raise "OccamsRecord: No assocation `:#{assoc}` on `#{@model&.name || '<model missing>'}`" if ref.nil?
|
30
30
|
scope ||= -> { self.select select } if select
|
31
|
-
@eager_loaders << eager_loader_for_association(ref).new(ref, scope, use, &eval_block)
|
31
|
+
@eager_loaders << eager_loader_for_association(ref).new(ref, scope, use: use, as: as, &eval_block)
|
32
32
|
self
|
33
33
|
end
|
34
34
|
|
@@ -15,11 +15,13 @@ module OccamsRecord
|
|
15
15
|
# @param ref [ActiveRecord::Association] the ActiveRecord association
|
16
16
|
# @param scope [Proc] a scope to apply to the query (optional)
|
17
17
|
# @param use [Array(Module)] optional Module to include in the result class (single or array)
|
18
|
+
# @param as [Symbol] Load the association into this attr instead
|
18
19
|
# @param eval_block [Proc] a block where you may perform eager loading on *this* association (optional)
|
19
20
|
#
|
20
|
-
def initialize(ref, scope = nil, use
|
21
|
-
@ref, @scope, @use, @eval_block = ref, scope, use, eval_block
|
22
|
-
@
|
21
|
+
def initialize(ref, scope = nil, use: nil, as: nil, &eval_block)
|
22
|
+
@ref, @scope, @use, @as, @eval_block = ref, scope, use, as, eval_block
|
23
|
+
@model = ref.klass
|
24
|
+
@name = (as || ref.name).to_s
|
23
25
|
end
|
24
26
|
|
25
27
|
#
|
@@ -13,11 +13,12 @@ module OccamsRecord
|
|
13
13
|
# @param ref [ActiveRecord::Association] the ActiveRecord association
|
14
14
|
# @param scope [Proc] a scope to apply to the query (optional)
|
15
15
|
# @param use [Array<Module>] optional Module to include in the result class (single or array)
|
16
|
+
# @param as [Symbol] Load the association into this attr instead
|
16
17
|
# @param eval_block [Proc] a block where you may perform eager loading on *this* association (optional)
|
17
18
|
#
|
18
|
-
def initialize(ref, scope = nil, use
|
19
|
+
def initialize(ref, scope = nil, use: nil, as: nil, &eval_block)
|
19
20
|
@ref, @scope, @use, @eval_block = ref, scope, use, eval_block
|
20
|
-
@name = ref.name.to_s
|
21
|
+
@name = (as || ref.name).to_s
|
21
22
|
@foreign_type = @ref.foreign_type.to_sym
|
22
23
|
@foreign_key = @ref.foreign_key.to_sym
|
23
24
|
end
|
data/lib/occams-record/merge.rb
CHANGED
@@ -13,11 +13,11 @@ module OccamsRecord
|
|
13
13
|
# Initialize a new Merge operation.
|
14
14
|
#
|
15
15
|
# @param target_rows [Array<OccamsRecord::Results::Row] the rows into which associated rows should be merged
|
16
|
-
# @param
|
16
|
+
# @param assoc_attr [String|Symbol] name of the attribute where associated rows will be put
|
17
17
|
#
|
18
|
-
def initialize(target_rows,
|
18
|
+
def initialize(target_rows, assoc_attr)
|
19
19
|
@target_rows = target_rows
|
20
|
-
@assign = "#{
|
20
|
+
@assign = "#{assoc_attr}="
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
data/lib/occams-record/query.rb
CHANGED
@@ -74,6 +74,16 @@ module OccamsRecord
|
|
74
74
|
|
75
75
|
alias_method :to_a, :run
|
76
76
|
|
77
|
+
#
|
78
|
+
# Run the query and return the first result (which could be nil). This WILL append a LIMIT 1 to the query.
|
79
|
+
#
|
80
|
+
# @return [OccamsRecord::Results::Row]
|
81
|
+
#
|
82
|
+
def first
|
83
|
+
scope.limit! 1
|
84
|
+
run[0]
|
85
|
+
end
|
86
|
+
|
77
87
|
#
|
78
88
|
# If you pass a block, each result row will be yielded to it. If you don't,
|
79
89
|
# an Enumerable will be returned.
|
@@ -97,6 +97,15 @@ module OccamsRecord
|
|
97
97
|
|
98
98
|
alias_method :to_a, :run
|
99
99
|
|
100
|
+
#
|
101
|
+
# Run the query and return the first result (which could be nil). IMPORTANT you MUST add LIMIT 1 yourself!
|
102
|
+
#
|
103
|
+
# @return [OccamsRecord::Results::Row]
|
104
|
+
#
|
105
|
+
def first
|
106
|
+
run[0]
|
107
|
+
end
|
108
|
+
|
100
109
|
#
|
101
110
|
# If you pass a block, each result row will be yielded to it. If you don't,
|
102
111
|
# an Enumerable will be returned.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: occams-record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|