Skip to content

Commit ecce3eb

Browse files
authored
Update for Rails 7 (#1)
1 parent cc3aaca commit ecce3eb

File tree

467 files changed

+699
-47933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

467 files changed

+699
-47933
lines changed

.rubocop.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Layout/LineLength:
2+
Enabled: false
3+
4+
Metrics/AbcSize:
5+
Enabled: false
6+
7+
Metrics/MethodLength:
8+
Enabled: false
9+
10+
Metrics/ModuleLength:
11+
Enabled: false
12+
13+
Metrics/ClassLength:
14+
Enabled: false
15+
16+
Metrics/ParameterLists:
17+
Enabled: false
18+
19+
Metrics/CyclomaticComplexity:
20+
Enabled: false
21+
22+
Metrics/PerceivedComplexity:
23+
Enabled: false
24+
25+
Naming/MethodName:
26+
Enabled: false
27+
28+
Naming/PredicateName:
29+
Enabled: false
30+
31+
Naming/MethodParameterName:
32+
Enabled: false
33+
34+
Layout/BlockEndNewline:
35+
Enabled: true
36+
37+
Layout/BlockAlignment:
38+
EnforcedStyleAlignWith: start_of_block
39+
40+
Layout/MultilineOperationIndentation:
41+
EnforcedStyle: indented
42+
43+
Layout/MultilineMethodCallIndentation:
44+
Enabled: true
45+
EnforcedStyle: indented
46+
IndentationWidth: 2
47+
48+
Style/OptionalBooleanParameter:
49+
Enabled: false
50+
51+
Style/Documentation:
52+
Enabled: false
53+
54+
Style/CaseEquality:
55+
Enabled: false
56+
57+
Style/FormatString:
58+
Enabled: false
59+
60+
Style/NumericPredicate:
61+
EnforcedStyle: comparison
62+
63+
Lint/SuppressedException:
64+
Enabled: false
65+
66+
Lint/UnusedMethodArgument:
67+
Enabled: false

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
source "http://rubygems.org"
1+
source 'http://rubygems.org'
22
gemspec

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
activerecord6-redshift-adapter
22
==============================
33

4-
Amazon Redshift adapter for ActiveRecord 6 (Rails 6).
5-
I forked the project from https://github.com/ConsultingMD/activerecord5-redshift-adapter
4+
Amazon Redshift adapter for ActiveRecord 7 (Rails 7).
5+
I forked the project from https://github.com/kwent/activerecord6-redshift-adapter
66

77
Thanks for the auhors.
88

99
Usage
1010
-------------------
1111

12-
For Rails 6, write following in Gemfile:
12+
For Rails 7, write following in Gemfile:
1313

1414
```ruby
15-
gem 'activerecord6-redshift-adapter'
15+
gem 'activerecord7-redshift-adapter'
1616
```
1717

1818
In database.yml

Rakefile

-20
This file was deleted.
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
Gem::Specification.new do |s|
22
s.platform = Gem::Platform::RUBY
3-
s.name = 'activerecord6-redshift-adapter'
4-
s.version = '1.3.0'
3+
s.name = 'activerecord7-redshift-adapter'
4+
s.version = '1.0.0'
55
s.summary = 'Amazon Redshift adapter for ActiveRecord '
6-
s.description = 'Amazon Redshift adapter for ActiveRecord 6.x.'
6+
s.description = 'Amazon Redshift adapter for ActiveRecord 7.x.'
77
s.license = 'MIT'
88

9-
s.author = ['Nancy Foen', 'Minero Aoki', 'iamdbc', 'Quentin Rousseau']
10-
s.email = 'contact@quent.in'
11-
s.homepage = 'https://github.com/kwent/activerecord6-redshift-adapter'
9+
s.author = ['Nancy Foen', 'Minero Aoki', 'iamdbc', 'Quentin Rousseau', 'Johan Le Bray']
10+
s.email = 'johan@pennylane.com'
11+
s.homepage = 'https://github.com/pennylane-hq/activerecord7-redshift-adapter'
1212

1313
s.files = Dir.glob(['LICENSE', 'README.md', 'lib/**/*.rb'])
1414
s.require_path = 'lib'
1515

1616
s.required_ruby_version = '>= 3.0'
17+
s.add_runtime_dependency 'activerecord', '~> 7.0'
1718
s.add_runtime_dependency 'pg', '~> 1.0'
18-
s.add_runtime_dependency 'activerecord', '~> 6.0'
1919
end

lib/active_record/connection_adapters/redshift/array_parser.rb

+54-55
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1+
# frozen_string_literal: true
2+
13
module ActiveRecord
24
module ConnectionAdapters
35
module Redshift
46
module ArrayParser # :nodoc:
5-
67
DOUBLE_QUOTE = '"'
7-
BACKSLASH = "\\"
8+
BACKSLASH = '\\'
89
COMMA = ','
910
BRACKET_OPEN = '{'
1011
BRACKET_CLOSE = '}'
1112

1213
def parse_pg_array(string) # :nodoc:
1314
local_index = 0
1415
array = []
15-
while(local_index < string.length)
16+
while local_index < string.length
1617
case string[local_index]
1718
when BRACKET_OPEN
18-
local_index,array = parse_array_contents(array, string, local_index + 1)
19+
local_index, array = parse_array_contents(array, string, local_index + 1)
1920
when BRACKET_CLOSE
2021
return array
2122
end
@@ -27,66 +28,64 @@ def parse_pg_array(string) # :nodoc:
2728

2829
private
2930

30-
def parse_array_contents(array, string, index)
31-
is_escaping = false
32-
is_quoted = false
33-
was_quoted = false
34-
current_item = ''
31+
def parse_array_contents(array, string, index)
32+
is_escaping = false
33+
is_quoted = false
34+
was_quoted = false
35+
current_item = ''
3536

36-
local_index = index
37-
while local_index
38-
token = string[local_index]
39-
if is_escaping
37+
local_index = index
38+
while local_index
39+
token = string[local_index]
40+
if is_escaping
41+
current_item << token
42+
is_escaping = false
43+
elsif is_quoted
44+
case token
45+
when DOUBLE_QUOTE
46+
is_quoted = false
47+
was_quoted = true
48+
when BACKSLASH
49+
is_escaping = true
50+
else
4051
current_item << token
41-
is_escaping = false
52+
end
53+
else
54+
case token
55+
when BACKSLASH
56+
is_escaping = true
57+
when COMMA
58+
add_item_to_array(array, current_item, was_quoted)
59+
current_item = ''
60+
was_quoted = false
61+
when DOUBLE_QUOTE
62+
is_quoted = true
63+
when BRACKET_OPEN
64+
internal_items = []
65+
local_index, internal_items = parse_array_contents(internal_items, string, local_index + 1)
66+
array.push(internal_items)
67+
when BRACKET_CLOSE
68+
add_item_to_array(array, current_item, was_quoted)
69+
return local_index, array
4270
else
43-
if is_quoted
44-
case token
45-
when DOUBLE_QUOTE
46-
is_quoted = false
47-
was_quoted = true
48-
when BACKSLASH
49-
is_escaping = true
50-
else
51-
current_item << token
52-
end
53-
else
54-
case token
55-
when BACKSLASH
56-
is_escaping = true
57-
when COMMA
58-
add_item_to_array(array, current_item, was_quoted)
59-
current_item = ''
60-
was_quoted = false
61-
when DOUBLE_QUOTE
62-
is_quoted = true
63-
when BRACKET_OPEN
64-
internal_items = []
65-
local_index,internal_items = parse_array_contents(internal_items, string, local_index + 1)
66-
array.push(internal_items)
67-
when BRACKET_CLOSE
68-
add_item_to_array(array, current_item, was_quoted)
69-
return local_index,array
70-
else
71-
current_item << token
72-
end
73-
end
71+
current_item << token
7472
end
75-
76-
local_index += 1
7773
end
78-
return local_index,array
74+
75+
local_index += 1
7976
end
77+
[local_index, array]
78+
end
8079

81-
def add_item_to_array(array, current_item, quoted)
82-
return if !quoted && current_item.length == 0
80+
def add_item_to_array(array, current_item, quoted)
81+
return if !quoted && current_item.empty?
8382

84-
if !quoted && current_item == 'NULL'
85-
array.push nil
86-
else
87-
array.push current_item
88-
end
83+
if !quoted && current_item == 'NULL'
84+
array.push nil
85+
else
86+
array.push current_item
8987
end
88+
end
9089
end
9190
end
9291
end

lib/active_record/connection_adapters/redshift/column.rb

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1+
# frozen_string_literal: true
2+
13
module ActiveRecord
24
module ConnectionAdapters
3-
class RedshiftColumn < Column #:nodoc:
5+
class RedshiftColumn < Column # :nodoc:
46
delegate :oid, :fmod, to: :sql_type_metadata
57

6-
if ActiveRecord::VERSION::MAJOR >= 6 && ActiveRecord::VERSION::MINOR >= 1
7-
# Required for Rails 6.1, see https://github.com/rails/rails/pull/41756
8-
mattr_reader :array, default: false
9-
alias :array? :array
8+
# Required for Rails 6.1, see https://github.com/rails/rails/pull/41756
9+
mattr_reader :array, default: false
10+
alias array? array
1011

11-
def initialize(name, default, sql_type_metadata, null = true, default_function = nil, **)
12-
super name, default, sql_type_metadata, null, default_function
13-
end
14-
else
15-
def initialize(name, default, sql_type_metadata, null = true, default_function = nil)
16-
super name, default, sql_type_metadata, null, default_function
17-
end
12+
def initialize(name, default, sql_type_metadata, null = true, default_function = nil, **)
13+
super name, default, sql_type_metadata, null, default_function
1814
end
1915
end
2016
end

0 commit comments

Comments
 (0)