relation_to_struct 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f46cb4692b014b55ed3b9ef36eac25637fdd67e5
4
- data.tar.gz: 233671dec235b9d0c0a1bd50625043f0a71b3c1f
3
+ metadata.gz: 5b62c263648a096f761f894079cb6d4e67a65cae
4
+ data.tar.gz: 0135d8bf011a7376f9147719c32ff16b4228550b
5
5
  SHA512:
6
- metadata.gz: 1a7866549d1f975630261f903ffabbf38b5a6940c7811268275c46cca2b53a06502863c28ae7fbf37492cdfef2c9b505e47d4301a8fedf9ff1bc440d37c615af
7
- data.tar.gz: e9b8d9a58cb1c904311b15284fd79fab9faec140e5068c4889f66b52b472b1c42bea48a4b191b58a170b1f4ff6a4dc3b11a3ea975a23f4c44d9bc6961dc371c6
6
+ metadata.gz: b1bf48925ba3b32d38fd0bb66e367e7653b8d968b6bcd8bc3a207d3458a4daa5b45cde15f6e9970c0c15a49e7f2701f8b15aa0818152de1322786afb9ce3fa88
7
+ data.tar.gz: 6bf2353d27fbd5d9330698c29bb99fa77d053a00973b06af7c383c0a97545c3110ceeee9798a9171b0f4233246bd52db99ffe353ec65a2586da0fcc738c8b3b8
@@ -8,6 +8,11 @@ module RelationToStruct::ActiveRecordBaseExtension
8
8
  struct_class.new(*tuple)
9
9
  end
10
10
  end
11
+
12
+ def pluck_from_sql(sql, binds=[])
13
+ result = connection.select_all(sanitize_sql(sql, nil), "Structs SQL Load", binds)
14
+ result.cast_values()
15
+ end
11
16
  end
12
17
  end
13
18
 
@@ -1,3 +1,3 @@
1
1
  module RelationToStruct
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -71,5 +71,15 @@ describe RelationToStruct do
71
71
  sql = "SELECT 1 * 23"
72
72
  expect(ActiveRecord::Base.structs_from_sql(test_struct, sql)).to eq([test_struct.new(23)])
73
73
  end
74
+
75
+ it 'should allow plucking with SQL directly' do
76
+ sql = "SELECT 1 * 23"
77
+ expect(ActiveRecord::Base.pluck_from_sql(sql)).to eq([23])
78
+ end
79
+
80
+ it 'should allow plucking multiple columns with SQL directly' do
81
+ sql = "SELECT 1 * 23, 25"
82
+ expect(ActiveRecord::Base.pluck_from_sql(sql)).to eq([[23, 25]])
83
+ end
74
84
  end
75
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relation_to_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coleman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-15 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler