baby_squeel 1.0.2 → 1.0.3

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: 5af60f5e34fa18ceb9ad797eecadbce54748f62a
4
- data.tar.gz: d517b61dbeca8309c511f3aff60ca2d180f1c7fa
3
+ metadata.gz: 4e25c11d1ea3b43b1911854cc0966350877f7d62
4
+ data.tar.gz: a203af4f8f653617a5a64930e43501daf314489a
5
5
  SHA512:
6
- metadata.gz: 440bd7a2c660302617fd8b67bcc7dfd9cfb919a3f16cb9dac76c23a467a3ad9935b77ed97d4c5847170d16315c19c9dbbed0a4ad4be0fa8f330abadbfd339503
7
- data.tar.gz: 2693828aa10e64d7f724270d1be14fc47d72d8ab1c93169da703bef43395132ea51c2365b865d149c8b1c965592238d3982cee2b9a2be22370ce10a0a5185ed3
6
+ metadata.gz: 1a0528486cceb39952ad82687a69a9a6fb920a1ba6faf16ebdf4544bcfd5d6769d457ce10c87b4ad167f3a4a17c5234a6c36a78609fad03806d983232df4b743
7
+ data.tar.gz: aa45ff551f8d7c86c761749af179482011a2da522c9261ced4fab70ee1f5547f1b94eb6c93df3b5cf250e9169b72a3184bf1689c5bf614b7db20a69b476b3f88
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  *Nothing yet.*
4
4
 
5
+ ## [1.0.3] - 2017-02-09
6
+ ### Added
7
+ - Support for `pluck`.
8
+ - Support for `not_in`.
9
+
5
10
  ## [1.0.2] - 2017-02-07
6
11
  ### Added
7
12
  - `BabySqueel::Association` now has `#==` and `#!=`. This is only supported for Rails 5+. Example: `Post.where { author: Author.last }`.
@@ -88,7 +93,8 @@
88
93
  ### Added
89
94
  - Initial support for selects, orders, wheres, and joins.
90
95
 
91
- [Unreleased]: https://github.com/rzane/baby_squeel/compare/v1.0.2...HEAD
96
+ [Unreleased]: https://github.com/rzane/baby_squeel/compare/v1.0.3...HEAD
97
+ [1.0.3]: https://github.com/rzane/baby_squeel/compare/v1.0.2...v1.0.3
92
98
  [1.0.2]: https://github.com/rzane/baby_squeel/compare/v1.0.1...v1.0.2
93
99
  [1.0.1]: https://github.com/rzane/baby_squeel/compare/v1.0.0...v1.0.1
94
100
  [1.0.0]: https://github.com/rzane/baby_squeel/compare/v0.3.1...v1.0.0
@@ -4,7 +4,7 @@ module BabySqueel
4
4
  module ActiveRecord
5
5
  module Base
6
6
  delegate :joining, :joining!, :selecting, :ordering,
7
- :grouping, :when_having, to: :all
7
+ :grouping, :when_having, :plucking, to: :all
8
8
 
9
9
  # Define a sifter that can be used within DSL blocks.
10
10
  #
@@ -29,6 +29,40 @@ module BabySqueel
29
29
  having DSL.evaluate(self, &block)
30
30
  end
31
31
 
32
+ if ::ActiveRecord::VERSION::MAJOR >= 5
33
+ def plucking(&block)
34
+ pluck DSL.evaluate(self, &block)
35
+ end
36
+ elsif ::ActiveRecord::VERSION::STRING >= '4.2.0'
37
+ def plucking(&block)
38
+ relation = selecting(&block)
39
+ binds = relation.arel.bind_values + bind_values
40
+ result = klass.connection.select_all(relation.arel, nil, binds)
41
+ result.cast_values(klass.column_types)
42
+ end
43
+ else
44
+ def plucking(&block)
45
+ relation = selecting(&block)
46
+ binds = relation.arel.bind_values + bind_values
47
+ result = klass.connection.select_all(relation.arel, nil, binds)
48
+ columns = result.columns.map do |key|
49
+ klass.column_types.fetch(key) {
50
+ result.column_types.fetch(key) { result.identity_type }
51
+ }
52
+ end
53
+
54
+ result = result.rows.map do |values|
55
+ values = result.columns.zip(values).map do |column_name, value|
56
+ single_attr_hash = { column_name => value }
57
+ klass.initialize_attributes(single_attr_hash).values.first
58
+ end
59
+
60
+ columns.zip(values).map { |column, value| column.type_cast value }
61
+ end
62
+ columns.one? ? result.map!(&:first) : result
63
+ end
64
+ end
65
+
32
66
  private
33
67
 
34
68
  # This is a monkey patch, and I'm not happy about it.
@@ -1,3 +1,3 @@
1
1
  module BabySqueel
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baby_squeel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Zane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -148,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.5.1
151
+ rubygems_version: 2.6.8
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: A tiny squeel implementation without all of the evil.
155
155
  test_files: []
156
- has_rdoc: