activerecord-oracle_enhanced-adapter-monky_patch_755 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a1d096fb6d5aa8923da8064b7881bce16ea4800
4
+ data.tar.gz: 41a7c6f4b5076319d89dfa7158d43b8b8c25e321
5
+ SHA512:
6
+ metadata.gz: d93085cb8dfd54c75c43ec8a5893a5fd63bc32147fea63209d7bc59d4878fceffc8058d8f791143d7901ca3398f63acfd2739effa657e4471000bbd08b8293e2
7
+ data.tar.gz: 0bcb9e3ae38109bb235d41ef0408952c3a4ad2e30024a838c0e4bcccea726ec53040024d8919f06a88f8bfc9655c6f54cea98aa3e3ab4c2abe70ee233fc116ea
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2016 Koichi ITO
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # activerecord-oracle_enhanced-adapter-monky_patch_755
2
+
3
+ A monkey patch for oracle-enhanced ISSUE [#755](https://github.com/rsim/oracle-enhanced/issues/755).
4
+
5
+ ## Installation
6
+
7
+ Add these lines to your application's Gemfile:
8
+
9
+ ```
10
+ gem 'activerecord-oracle_enhanced-adapter-monky_patch_755'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install activerecord-oracle_enhanced-adapter-monky_patch_755
23
+ ```
24
+
25
+ ## Target
26
+
27
+ * 'activerecord', '~>4.2.1'
28
+ * 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
29
+
30
+ ## Motivation
31
+
32
+ This library is bound to solve this problem in Rails 4.2.x with Oracle.
33
+
34
+ ```ruby
35
+ > created_at = Model.first.created_at
36
+ > Model.where(created_at: created_at)
37
+ => []
38
+ ```
39
+
40
+ Above is not expected. This library will apply a patch as a following behavior.
41
+
42
+ ```ruby
43
+ > created_at = Model.first.created_at
44
+ > Model.where(created_at: created_at)
45
+ => [#<Model id: ***snip***>]
46
+ ```
47
+
48
+ To explain this a little further: oracle-enhanced ISSUE [#755](https://github.com/rsim/oracle-enhanced/issues/755).
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
57
+
58
+ ## License
59
+
60
+ activerecord-oracle_enhanced-adapter-monky_patch_755 is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module MonkeyPatch
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,90 @@
1
+ #
2
+ # This code is a monkey patch for oracle-enhanced ISSUE #755.
3
+ #
4
+ # https://github.com/rsim/oracle-enhanced/issues/755
5
+ #
6
+ module ActiveRecord
7
+ module MonkeyPatch
8
+ MINIMUM_SUPPORTED_VERSION = '4.2.1'.freeze
9
+ MAXIMUM_SUPPORTED_VERSION = '4.2.6'.freeze
10
+
11
+ def adjust_timezone_offset(opts)
12
+ if ActiveRecord::Base.connection_config[:adapter] != 'oracle_enhanced' ||
13
+ Gem::Version.create(Rails.version) < Gem::Version.create(MINIMUM_SUPPORTED_VERSION) ||
14
+ Gem::Version.create(Rails.version) > Gem::Version.create(MAXIMUM_SUPPORTED_VERSION)
15
+ return opts
16
+ end
17
+
18
+ case opts
19
+ when Array
20
+ opts.each_with_object([]) {|v, ret|
21
+ ret << if v.is_a?(Time) || v.is_a?(Date)
22
+ offset = v.to_time.utc_offset
23
+
24
+ offset.positive? ? v.to_time.ago(offset) : v.to_time.since(offset)
25
+ else
26
+ v
27
+ end
28
+ }
29
+ when Hash
30
+ opts.each_with_object({}) {|(c, v), ret|
31
+ ret[c] = if v.is_a?(Time) || v.is_a?(Date)
32
+ offset = v.to_time.utc_offset
33
+
34
+ offset.positive? ? v.to_time.ago(offset) : v.to_time.since(offset)
35
+ else
36
+ v
37
+ end
38
+ }
39
+ else
40
+ opts
41
+ end
42
+ end
43
+
44
+ module_function :adjust_timezone_offset
45
+ end
46
+
47
+ #
48
+ # Original code is the following URL.
49
+ #
50
+ # https://github.com/rails/rails/blob/v4.2.6/activerecord/lib/active_record/relation/query_methods.rb#L947
51
+ #
52
+ module QueryMethods
53
+ def build_where(opts, other = [])
54
+ case opts
55
+ when String, Array
56
+ [@klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
57
+ when Hash
58
+ opts = ActiveRecord::MonkeyPatch.adjust_timezone_offset(opts)
59
+ opts = PredicateBuilder.resolve_column_aliases(klass, opts)
60
+
61
+ tmp_opts, bind_values = create_binds(opts)
62
+ self.bind_values += bind_values
63
+
64
+ attributes = @klass.send(:expand_hash_conditions_for_aggregates, tmp_opts)
65
+ add_relations_to_bind_values(attributes)
66
+
67
+ PredicateBuilder.build_from_hash(klass, attributes, table)
68
+ else
69
+ [opts]
70
+ end
71
+ end
72
+ end
73
+
74
+ #
75
+ # Original code is the following URL.
76
+ #
77
+ # https://github.com/rails/rails/blob/v4.2.6/activerecord/lib/active_record/statement_cache.rb#L81
78
+ #
79
+ class StatementCache # :nodoc:
80
+ class BindMap # :nodoc:
81
+ def bind(values)
82
+ values = ActiveRecord::MonkeyPatch.adjust_timezone_offset(values)
83
+
84
+ bvs = @bind_values.map { |pair| pair.dup }
85
+ @indexes.each_with_index { |offset,i| bvs[offset][1] = values[i] }
86
+ bvs
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,7 @@
1
+ module OracleEnhanced
2
+ class MonkeyPatch755Railtie < ::Rails::Railtie
3
+ ActiveSupport.on_load(:active_record) do
4
+ require 'activerecord/monkey_patch'
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-oracle_enhanced-adapter-monky_patch_755
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Koichi ITO
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord-oracle_enhanced-adapter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.2.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.2.1
55
+ description: 'A monkey patch for oracle-enhanced ISSUE #755.'
56
+ email: koic.ito@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - LICENSE
62
+ - README.md
63
+ - lib/activerecord-oracle_enhanced-adapter-monky_patch_755.rb
64
+ - lib/activerecord/monkey_patch.rb
65
+ - lib/activerecord/monkey_patch/version.rb
66
+ homepage: http://github.com/koic/oracle-enhanced-monky_patch_755
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.0.0
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.5.1
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: 'A monkey patch for oracle-enhanced ISSUE #755.'
90
+ test_files: []
91
+ has_rdoc: