occams-record 0.11.0 → 0.12.0

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
  SHA256:
3
- metadata.gz: 68db1cbd50ea9da8301200e9d57ca2517fe28624663c3d3ea2e463c99825f8d4
4
- data.tar.gz: 4d55fddeaf26d1b2bc6b84ca09ec1d7a6d4ea23e5847b537c98f9ff5827bbc24
3
+ metadata.gz: a33f839ea9d811478c883f3cf8e54ad3c67c366761db4281ad7994d54234e519
4
+ data.tar.gz: f3370573806301fd8b7beeb60d66fce4cd37160d147f9a626a3ba228430ba935
5
5
  SHA512:
6
- metadata.gz: 5924cf19d1fa6923146b289a661d80a964aa2616bc09768e8967dbe3a849349bb7aaf6c6edcb9fbe9301bf88cbad6f5a6dfb7397f8287c61b332d316197a18cb
7
- data.tar.gz: f186dbeb9ea6f15cc4eebcb5cb2e6b135e5ba5b967c12e1162c938253f22fda343b3e2cc0401b93ba591fa94ebd695e6535e3a1ea8b4447aba11759dda549d28
6
+ metadata.gz: b28285305d8e16e497e813e1e89362b27f2d6a35f79bdb529d175dfbd07741592fd168150bfc8170eea8fcf1a538b0c22a6e1258615632240e2661c184583fc8
7
+ data.tar.gz: 3ed3e6cee8688afd1227d3aa736d4744e78102cc040735691f753ee32943be8a71ea24044570a64aa02739e52a5b4303b8d1c79be3359a7cd10e11e67056b7da
data/README.md CHANGED
@@ -12,7 +12,7 @@ Occam's Record is a high-efficiency query API for ActiveRecord. It is **not** an
12
12
  * Allows eager loading of associations when using raw SQL.
13
13
  * Allows `find_each`/`find_in_batches` when using raw SQL.
14
14
 
15
- [Look over the speed and memory measurements yourself!](https://github.com/jhollinger/occams-record/wiki/Measurements). OccamsRecord achieves all of this by making some very specific trade-offs:
15
+ [Look over the speed and memory measurements yourself!](https://github.com/jhollinger/occams-record/wiki/Measurements) OccamsRecord achieves all of this by making some very specific trade-offs:
16
16
 
17
17
  * OccamsRecord results are **read-only**.
18
18
  * OccamsRecord results are **purely database rows** - they don't have any instance methods from your Rails models.
@@ -140,7 +140,9 @@ widgets = OccamsRecord.sql(%(
140
140
  }).run
141
141
  ```
142
142
 
143
- To perform eager loading, you must specify the base model. NOTE some database adapters, notably SQLite, require you to always specify the model.
143
+ **Performing eager loading with raw SQL**
144
+
145
+ To perform eager loading with raw SQL you must specify the base model. NOTE some database adapters, notably SQLite, require you to always specify the model.
144
146
 
145
147
  ```ruby
146
148
  widgets = OccamsRecord.
@@ -155,7 +157,9 @@ widgets = OccamsRecord.
155
157
  run
156
158
  ```
157
159
 
158
- To use `find_each` or `find_in_batches` with raw SQL you must provide the `LIMIT` and `OFFSET` statements yourself.
160
+ **Using find_each/find_in_batches with raw SQL**
161
+
162
+ To use `find_each` or `find_in_batches` with raw SQL you must provide the `LIMIT` and `OFFSET` statements yourself. The bind values for these will be filled in by OccamsRecord.
159
163
 
160
164
  ```ruby
161
165
  widgets = OccamsRecord.sql(%(
@@ -27,7 +27,8 @@ module OccamsRecord
27
27
  #
28
28
  def eager_load(assoc, scope = nil, select: nil, use: nil, as: nil, &eval_block)
29
29
  ref = @model ? @model.reflections[assoc.to_s] : nil
30
- raise "OccamsRecord: No assocation `:#{assoc}` on `#{@model&.name || '<model missing>'}`" if ref.nil?
30
+ ref ||= @model.subclasses.map(&:reflections).detect { |x| x.has_key? assoc.to_s }&.[](assoc.to_s) if @model
31
+ raise "OccamsRecord: No assocation `:#{assoc}` on `#{@model&.name || '<model missing>'}` or subclasses" if ref.nil?
31
32
  scope ||= ->(q) { q.select select } if select
32
33
  @eager_loaders << eager_loader_for_association(ref).new(ref, scope, use: use, as: as, &eval_block)
33
34
  self
@@ -40,6 +40,9 @@ module OccamsRecord
40
40
  case type.type
41
41
  when :datetime
42
42
  define_method(col) { @cast_values[idx] ||= type.send(CASTER, @raw_values[idx])&.in_time_zone }
43
+ when :boolean
44
+ define_method(col) { @cast_values[idx] ||= type.send(CASTER, @raw_values[idx]) }
45
+ define_method("#{col}?") { !!send(col) }
43
46
  else
44
47
  define_method(col) { @cast_values[idx] ||= type.send(CASTER, @raw_values[idx]) }
45
48
  end
@@ -3,5 +3,5 @@
3
3
  #
4
4
  module OccamsRecord
5
5
  # Library version
6
- VERSION = '0.11.0'.freeze
6
+ VERSION = '0.12.0'.freeze
7
7
  end
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.11.0
4
+ version: 0.12.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-03-18 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord