relation_to_struct 0.0.1 → 0.0.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f46cb4692b014b55ed3b9ef36eac25637fdd67e5
|
4
|
+
data.tar.gz: 233671dec235b9d0c0a1bd50625043f0a71b3c1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a7866549d1f975630261f903ffabbf38b5a6940c7811268275c46cca2b53a06502863c28ae7fbf37492cdfef2c9b505e47d4301a8fedf9ff1bc440d37c615af
|
7
|
+
data.tar.gz: e9b8d9a58cb1c904311b15284fd79fab9faec140e5068c4889f66b52b472b1c42bea48a4b191b58a170b1f4ff6a4dc3b11a3ea975a23f4c44d9bc6961dc371c6
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RelationToStruct::ActiveRecordBaseExtension
|
2
|
+
extend ::ActiveSupport::Concern
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def structs_from_sql(struct_class, sql, binds=[])
|
6
|
+
result = connection.select_all(sanitize_sql(sql, nil), "Structs SQL Load", binds)
|
7
|
+
result.cast_values().map do |tuple|
|
8
|
+
struct_class.new(*tuple)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
::ActiveRecord::Base.send(:include, RelationToStruct::ActiveRecordBaseExtension)
|
data/lib/relation_to_struct.rb
CHANGED
@@ -62,12 +62,14 @@ describe RelationToStruct do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
describe 'non-model specific querying' do
|
65
|
-
it 'should
|
66
|
-
|
65
|
+
it 'ActiveRecord::Base should respond to :structs_from_sql' do
|
66
|
+
expect(ActiveRecord::Base.respond_to?(:structs_from_sql)).to eq(true)
|
67
67
|
end
|
68
68
|
|
69
|
-
it 'should allow
|
70
|
-
|
69
|
+
it 'should allow querying with SQL directly' do
|
70
|
+
test_struct = Struct.new(:number)
|
71
|
+
sql = "SELECT 1 * 23"
|
72
|
+
expect(ActiveRecord::Base.structs_from_sql(test_struct, sql)).to eq([test_struct.new(23)])
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relation_to_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Coleman
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
138
|
- lib/relation_to_struct.rb
|
139
|
+
- lib/relation_to_struct/active_record_base_extension.rb
|
139
140
|
- lib/relation_to_struct/active_record_relation_extension.rb
|
140
141
|
- lib/relation_to_struct/version.rb
|
141
142
|
- relation_to_struct.gemspec
|