Skip to content

Commit

Permalink
Support Ruby 2.7-3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zverok committed Dec 22, 2024
1 parent 33af702 commit 8705edf
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 55 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ jobs:
build:

runs-on: ubuntu-latest

name: build ${{ matrix.ruby }}
strategy:
fail-fast: false
matrix:
ruby: [ '2.7', '3.0', '3.1', '3.2', '3.3' ]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.x
- name: Build and test with Rake
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: RSpec
run: bundle exec rspec
10 changes: 8 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ AllCops:
- 'spec/fixtures/**/*.rb'
- 'spec/spec_helper.rb'
DisplayCopNames: true
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7
NewCops: enable
SuggestExtensions: false

# That's my style

Layout/LineLength:
Max: 100
IgnoredPatterns: ['\#.*'] # ignore long comments
AllowedPatterns: ['\#.*'] # ignore long comments

Style/AndOr:
EnforcedStyle: conditionals
Expand All @@ -33,6 +33,12 @@ Style/BlockDelimiters:
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

Lint/AmbiguousOperatorPrecedence:
Enabled: false

Style/SafeNavigationChainLength:
Enabled: false

# Auto-correcting is hard job!

Metrics/AbcSize:
Expand Down
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# the-schema-is changes

## 2024-12-22 - 0.0.6

* Drop support for Ruby < 2.7;
* Ensure support for all Ruby versions from 2.7 to 3.4-dev (replace memoist with memery);
* Slightly update code with the new Rubocop.

## 2021-11-04 - 0.0.5

* Support `enum` column type;
Expand Down
73 changes: 43 additions & 30 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
PATH
remote: .
specs:
the_schema_is (0.0.5)
the_schema_is (0.0.6)
activesupport
backports (>= 3.16.0)
memoist
memery
rubocop (>= 1.0.0)

GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.3.2)
activesupport (7.1.4.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.2)
backports (3.21.0)
backports (3.25.0)
base64 (0.2.0)
bigdecimal (3.1.8)
byebug (11.1.3)
concurrent-ruby (1.1.8)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
diff-lcs (1.4.4)
i18n (1.8.10)
drb (2.2.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
io-console (0.5.6)
irb (1.2.4)
reline (>= 0.0.1)
memoist (0.16.2)
minitest (5.14.4)
parallel (1.20.1)
parser (3.0.2.0)
json (2.9.1)
language_server-protocol (3.17.0.3)
memery (1.6.0)
minitest (5.25.4)
mutex_m (0.3.0)
parallel (1.26.3)
parser (3.3.6.0)
ast (~> 2.4.1)
rainbow (3.0.0)
racc
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.1)
regexp_parser (2.1.1)
regexp_parser (2.9.3)
reline (0.1.4)
io-console (~> 0.5)
rexml (3.2.5)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
Expand All @@ -53,30 +65,31 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
rubocop (1.19.0)
rubocop (1.69.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.9.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.10.0)
parser (>= 3.0.1.1)
rubocop-rspec (2.4.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
rubocop-rspec (3.3.0)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.2)
rubygems-tasks (0.2.5)
irb (~> 1.0)
saharspec (0.0.7)
ruby2_keywords
tzinfo (2.0.4)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
zeitwerk (2.4.2)
unicode-display_width (3.1.2)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)

PLATFORMS
ruby
Expand All @@ -93,4 +106,4 @@ DEPENDENCIES
the_schema_is!

BUNDLED WITH
2.2.0
2.4.22
8 changes: 4 additions & 4 deletions lib/the_schema_is/cops.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'memoist'
require 'memery'
require 'rubocop'
require 'backports/latest'

Expand All @@ -16,7 +16,7 @@ module TheSchemaIs

module Cops
class << self
extend Memoist
include Memery

memoize def fetch_schema(path, remove_definition_attrs: [])
Cops::Parser.schema(path, remove_definition_attrs: remove_definition_attrs)
Expand All @@ -25,7 +25,7 @@ class << self
end

module Common
extend Memoist
include Memery

def self.included(cls)
cls.define_singleton_method(:badge) do
Expand Down Expand Up @@ -189,7 +189,7 @@ class UnknownColumn < RuboCop::Cop::Base
def register_offense(_node)
return if model.schema.nil? || schema.nil?

extra_columns.each do |_, col|
extra_columns.each_value do |col|
add_offense(col.source, message: MSG % col.name) do |corrector|
src_range = col.source.loc.expression
end_pos = col.source.next_sibling.then { |n|
Expand Down
2 changes: 1 addition & 1 deletion lib/the_schema_is/cops/node_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Patterns
extend RuboCop::AST::NodePattern::Macros

class << self
extend Memoist
include Memery

def search(pattern, node)
search_methods[pattern].then { |m| instance.send(m, node) }
Expand Down
3 changes: 1 addition & 2 deletions lib/the_schema_is/cops/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def self.node2model(name_node, definition_node, table_prefix) # rubocop:disable

Model.new(
class_name: class_name,
table_name: table_name ||
table_prefix.+(ActiveSupport::Inflector.tableize(class_name)),
table_name: table_name || table_prefix + ActiveSupport::Inflector.tableize(class_name),
source: definition_node,
schema: schema_node,
table_name_node: name_node&.first
Expand Down
8 changes: 4 additions & 4 deletions spec/the_schema_is/cops/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class User < ActiveRecord::Base
end
end
RUBY
{class_name: 'User', table_name: 'users', schema: ::Parser::AST::Node}
{class_name: 'User', table_name: 'users', schema: Parser::AST::Node}

it_behaves_like 'model extractor',
<<~RUBY,
Expand All @@ -61,7 +61,7 @@ class User < ApplicationRecord
end
end
RUBY
{class_name: 'User', table_name: 'users', schema: ::Parser::AST::Node}
{class_name: 'User', table_name: 'users', schema: Parser::AST::Node}

it_behaves_like 'model extractor',
<<~RUBY,
Expand All @@ -79,14 +79,14 @@ class User < ActiveRecord::Base

it { is_expected.to be_a(Hash) }
its(:keys) { is_expected.to start_with('articles', 'comments', 'favorites') }
its(:values) { is_expected.to all be_a ::Parser::AST::Node }
its(:values) { is_expected.to all be_a Parser::AST::Node }
end

describe '.columns' do
shared_examples 'column extractor' do |code, attrs|
subject { described_class.columns(described_class.parse(code)) }

it { is_expected.to contain_exactly(*attrs.map { |a| have_attributes(a) }) }
it { is_expected.to match_array(attrs.map { |a| have_attributes(a) }) }
end

it_behaves_like 'column extractor',
Expand Down
6 changes: 3 additions & 3 deletions the_schema_is.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'the_schema_is'
s.version = '0.0.5'
s.version = '0.0.6'
s.authors = ['Victor Shepelev']
s.email = '[email protected]'
s.homepage = 'https://github.com/zverok/the_schema_is'
Expand All @@ -12,15 +12,15 @@ Gem::Specification.new do |s|
EOF
s.licenses = ['MIT']

s.required_ruby_version = '>= 2.5.0'
s.required_ruby_version = '>= 2.7.0'

s.files = `git ls-files lib config LICENSE.txt *.md`.split($RS)
s.require_paths = ["lib"]

s.add_runtime_dependency 'backports', '>= 3.16.0'
s.add_runtime_dependency 'rubocop', '>= 1.0.0'
s.add_runtime_dependency 'activesupport' # it is a plugin for ActiveRecord anyways, and we need perfectly same inflection
s.add_runtime_dependency 'memoist'
s.add_runtime_dependency 'memery'

s.add_development_dependency 'rubocop-rspec'
s.add_development_dependency 'rake'
Expand Down

0 comments on commit 8705edf

Please sign in to comment.