Skip to content

Commit

Permalink
Update for Rails 7 (pennylane-hq#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlebray authored Apr 6, 2022
1 parent cc3aaca commit ecce3eb
Show file tree
Hide file tree
Showing 467 changed files with 699 additions and 47,933 deletions.
67 changes: 67 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Layout/LineLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/ParameterLists:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Naming/MethodName:
Enabled: false

Naming/PredicateName:
Enabled: false

Naming/MethodParameterName:
Enabled: false

Layout/BlockEndNewline:
Enabled: true

Layout/BlockAlignment:
EnforcedStyleAlignWith: start_of_block

Layout/MultilineOperationIndentation:
EnforcedStyle: indented

Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented
IndentationWidth: 2

Style/OptionalBooleanParameter:
Enabled: false

Style/Documentation:
Enabled: false

Style/CaseEquality:
Enabled: false

Style/FormatString:
Enabled: false

Style/NumericPredicate:
EnforcedStyle: comparison

Lint/SuppressedException:
Enabled: false

Lint/UnusedMethodArgument:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source "http://rubygems.org"
source 'http://rubygems.org'
gemspec
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
activerecord6-redshift-adapter
==============================

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

Thanks for the auhors.

Usage
-------------------

For Rails 6, write following in Gemfile:
For Rails 7, write following in Gemfile:

```ruby
gem 'activerecord6-redshift-adapter'
gem 'activerecord7-redshift-adapter'
```

In database.yml
Expand Down
20 changes: 0 additions & 20 deletions Rakefile

This file was deleted.

14 changes: 7 additions & 7 deletions activerecord6-redshift-adapter.gemspec
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'activerecord6-redshift-adapter'
s.version = '1.3.0'
s.name = 'activerecord7-redshift-adapter'
s.version = '1.0.0'
s.summary = 'Amazon Redshift adapter for ActiveRecord '
s.description = 'Amazon Redshift adapter for ActiveRecord 6.x.'
s.description = 'Amazon Redshift adapter for ActiveRecord 7.x.'
s.license = 'MIT'

s.author = ['Nancy Foen', 'Minero Aoki', 'iamdbc', 'Quentin Rousseau']
s.email = '[email protected]'
s.homepage = 'https://github.com/kwent/activerecord6-redshift-adapter'
s.author = ['Nancy Foen', 'Minero Aoki', 'iamdbc', 'Quentin Rousseau', 'Johan Le Bray']
s.email = '[email protected]'
s.homepage = 'https://github.com/pennylane-hq/activerecord7-redshift-adapter'

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

s.required_ruby_version = '>= 3.0'
s.add_runtime_dependency 'activerecord', '~> 7.0'
s.add_runtime_dependency 'pg', '~> 1.0'
s.add_runtime_dependency 'activerecord', '~> 6.0'
end
109 changes: 54 additions & 55 deletions lib/active_record/connection_adapters/redshift/array_parser.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# frozen_string_literal: true

module ActiveRecord
module ConnectionAdapters
module Redshift
module ArrayParser # :nodoc:

DOUBLE_QUOTE = '"'
BACKSLASH = "\\"
BACKSLASH = '\\'
COMMA = ','
BRACKET_OPEN = '{'
BRACKET_CLOSE = '}'

def parse_pg_array(string) # :nodoc:
local_index = 0
array = []
while(local_index < string.length)
while local_index < string.length
case string[local_index]
when BRACKET_OPEN
local_index,array = parse_array_contents(array, string, local_index + 1)
local_index, array = parse_array_contents(array, string, local_index + 1)
when BRACKET_CLOSE
return array
end
Expand All @@ -27,66 +28,64 @@ def parse_pg_array(string) # :nodoc:

private

def parse_array_contents(array, string, index)
is_escaping = false
is_quoted = false
was_quoted = false
current_item = ''
def parse_array_contents(array, string, index)
is_escaping = false
is_quoted = false
was_quoted = false
current_item = ''

local_index = index
while local_index
token = string[local_index]
if is_escaping
local_index = index
while local_index
token = string[local_index]
if is_escaping
current_item << token
is_escaping = false
elsif is_quoted
case token
when DOUBLE_QUOTE
is_quoted = false
was_quoted = true
when BACKSLASH
is_escaping = true
else
current_item << token
is_escaping = false
end
else
case token
when BACKSLASH
is_escaping = true
when COMMA
add_item_to_array(array, current_item, was_quoted)
current_item = ''
was_quoted = false
when DOUBLE_QUOTE
is_quoted = true
when BRACKET_OPEN
internal_items = []
local_index, internal_items = parse_array_contents(internal_items, string, local_index + 1)
array.push(internal_items)
when BRACKET_CLOSE
add_item_to_array(array, current_item, was_quoted)
return local_index, array
else
if is_quoted
case token
when DOUBLE_QUOTE
is_quoted = false
was_quoted = true
when BACKSLASH
is_escaping = true
else
current_item << token
end
else
case token
when BACKSLASH
is_escaping = true
when COMMA
add_item_to_array(array, current_item, was_quoted)
current_item = ''
was_quoted = false
when DOUBLE_QUOTE
is_quoted = true
when BRACKET_OPEN
internal_items = []
local_index,internal_items = parse_array_contents(internal_items, string, local_index + 1)
array.push(internal_items)
when BRACKET_CLOSE
add_item_to_array(array, current_item, was_quoted)
return local_index,array
else
current_item << token
end
end
current_item << token
end

local_index += 1
end
return local_index,array

local_index += 1
end
[local_index, array]
end

def add_item_to_array(array, current_item, quoted)
return if !quoted && current_item.length == 0
def add_item_to_array(array, current_item, quoted)
return if !quoted && current_item.empty?

if !quoted && current_item == 'NULL'
array.push nil
else
array.push current_item
end
if !quoted && current_item == 'NULL'
array.push nil
else
array.push current_item
end
end
end
end
end
Expand Down
20 changes: 8 additions & 12 deletions lib/active_record/connection_adapters/redshift/column.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# frozen_string_literal: true

module ActiveRecord
module ConnectionAdapters
class RedshiftColumn < Column #:nodoc:
class RedshiftColumn < Column # :nodoc:
delegate :oid, :fmod, to: :sql_type_metadata

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

def initialize(name, default, sql_type_metadata, null = true, default_function = nil, **)
super name, default, sql_type_metadata, null, default_function
end
else
def initialize(name, default, sql_type_metadata, null = true, default_function = nil)
super name, default, sql_type_metadata, null, default_function
end
def initialize(name, default, sql_type_metadata, null = true, default_function = nil, **)
super name, default, sql_type_metadata, null, default_function
end
end
end
Expand Down
Loading

0 comments on commit ecce3eb

Please sign in to comment.