Skip to content

Commit

Permalink
Merge pull request #235 from kpumuk/ruby-31
Browse files Browse the repository at this point in the history
Ruby 3.1 Support
  • Loading branch information
kpumuk authored Jul 5, 2022
2 parents 7c40235 + 6ab38f4 commit 29a47de
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 193 deletions.
205 changes: 93 additions & 112 deletions .circleci/config.yml

Large diffs are not rendered by default.

49 changes: 27 additions & 22 deletions .circleci/config.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@
# rake circleci
#
<%
builds = [
# 2.5
['2.5', '5.1.7'],
['2.5', '5.2.6'],
['2.5', '6.0.4'],
['2.5', '6.1.0'],
rails51 = '5.1.7'
rails52 = '5.2.8'
rails60 = '6.0.5'
rails61 = '6.1.6'
rails70 = '7.0.3'

builds = [
# 2.6
['2.6', '5.1.7'],
['2.6', '5.2.6'],
['2.6', '6.0.4'],
['2.6', '6.1.4'],
['2.6', rails51],
['2.6', rails52],
['2.6', rails60],
['2.6', rails61],

# 2.7
['2.7', '5.1.7'],
['2.7', '5.2.6'],
['2.7', '6.0.4'],
['2.7', '6.1.4'],
['2.7', '7.0.0.alpha2'],
['2.7', rails51],
['2.7', rails52],
['2.7', rails60],
['2.7', rails61],
['2.7', rails70],

# 3.0
['3.0', '6.0.4'],
['3.0', '6.1.4', true],
['3.0', '7.0.0.alpha2'],
['3.0', rails60],
['3.0', rails61],
['3.0', rails70],

# 3.1
['3.1', rails60],
['3.1', rails61],
['3.1', rails70, true],
]

main_build = builds.find { |_, _, is_main_build| is_main_build }
Expand Down Expand Up @@ -62,12 +67,12 @@ shared_build_steps: &shared_build_steps
- run:
name: Installing Dependencies
command: |
bundle check || (bundle install --jobs=4 --retry=3 --path vendor/bundle && bundle clean)
bundle config set --local path vendor/bundle
bundle check || (bundle install --jobs=4 --retry=3 && bundle clean)

- save_cache:
paths:
- ./vendor/bundle
- /usr/local/bundle/config
key: dependencies-{{ .Environment.CACHE_VERSION }}-{{ checksum "RAILS_VERSION" }}-{{ checksum "Gemfile" }}-{{ checksum "meta-tags.gemspec" }}

# run tests!
Expand Down Expand Up @@ -122,7 +127,7 @@ jobs:
type: boolean
default: false
docker:
- image: circleci/ruby:<%= ruby_version %>
- image: cimg/ruby:<%= ruby_version %>
environment:
RAILS_VERSION: <%= rails_version %>
ENABLE_CODE_COVERAGE: 1
Expand All @@ -133,7 +138,7 @@ jobs:

upload-coverage:
docker:
- image: circleci/ruby:<%= main_build[0] %>
- image: cimg/ruby:<%= main_build[0] %>
environment:
CC_TEST_REPORTER_ID: 8792cbc0d1780830ddd3dd7eb1c25f09f386ba8f04449ad830039469406a6ab3
steps:
Expand Down
3 changes: 2 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ engines:

rubocop:
enabled: true
channel: rubocop-0-75
# Check https://github.com/codeclimate/codeclimate-rubocop/branches/all?query=channel%2Frubocop
channel: rubocop-1-31-0

ratings:
paths:
Expand Down
19 changes: 1 addition & 18 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ AllCops:
# We do not specify Ruby version, because CodeClimate should by default
# read .ruby-version, and send it down to Rubocop
# (see https://github.com/codeclimate/codeclimate-rubocop/pull/68)
TargetRubyVersion: 2.5
TargetRubyVersion: 2.6
# We will lock Rails version to the newest we have in the company, so we're
# always looking to the future.
TargetRailsVersion: 5.1
Expand All @@ -40,10 +40,7 @@ Layout/DotPosition:
Layout/LineLength:
Max: 120
Exclude:
- "db/migrate/*"
- "spec/**/*"
IgnoredPatterns:
- "^#.*"

Layout/MultilineAssignmentLayout:
EnforcedStyle: same_line
Expand All @@ -58,13 +55,9 @@ Layout/SpaceInsideArrayLiteralBrackets:

Metrics/AbcSize:
Max: 25
Exclude:
- "db/migrate/*.rb"

Metrics/BlockLength:
Exclude:
- "db/migrate/*.rb"
- "config/routes.rb"
- "**/*.rake"
- "spec/**/*_spec.rb"
- "spec/spec_helper.rb"
Expand All @@ -76,21 +69,11 @@ Metrics/ClassLength:

Metrics/MethodLength:
Max: 30
Exclude:
- "db/migrate/*"

Metrics/ModuleLength:
Max: 250
CountComments: false

Rails/UnknownEnv:
Environments:
- development
- test
- production
- staging
- migration

Rails/SafeNavigation:
ConvertTry: true

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 2.17.0 (Development) [](https://github.com/kpumuk/meta-tags/compare/v2.16.0...HEAD)

Changes:

- Separate RBS files to _internal directory to avoid exposing RBS ([237](https://github.com/kpumuk/meta-tags/pull/237))
- Added Ruby 3.1 to supported versions, Ruby 2.6 is minimum supported version ([235](https://github.com/kpumuk/meta-tags/pull/235/))

## 2.16.0 (September 24, 2021) [](https://github.com/kpumuk/meta-tags/compare/v2.15.0...v2.16.0)

Changes:
Expand Down
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ if ENV['RAILS_VERSION']
gem 'railties', "~> #{ENV['RAILS_VERSION']}"
end

# Ruby typings
gem 'steep', platform: :mri unless ENV["NO_STEEP"] == '1'
unless ENV["NO_STEEP"] == '1'
# Ruby typings
gem 'steep', '~> 1.0.1', platform: :mri
end

group :test do
# Lock rubocop to a specific version we use on CI. If you update this,
# don't forget to switch rubocop channel in the .codeclimate.yml
gem 'rubocop', '~> 1.18.0'
gem 'rubocop', '= 1.31.0'
# Cops for rails apps
gem 'rubocop-rails'
# Apply RSpec rubocop cops
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
## Ruby on Rails

MetaTags main branch fully supports Ruby on Rails 5.1+, and is tested against all
major Rails releases up to 6.1.
major Rails releases up to 7.0.

Ruby versions older than 2.5 are no longer officially supported.
Ruby versions older than 2.6 are no longer officially supported.

_Please note_ that we are no longer support Ruby versions older than 2.4.0 and
Ruby on Rails older than 5.1, because they [reached their End of Life](https://github.com/kpumuk/meta-tags/pull/143).
_Please note_ that we no longer support Ruby versions older than 2.6.0 and
Ruby on Rails older than 5.1, because they reached their [End of Life](https://endoflife.date/ruby).

## Installation

Expand Down
2 changes: 2 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ target :lib do
# (because we don't have RBS files for it)
ignore "lib/meta_tags/railtie.rb"
ignore "lib/generators"

library "set"
end
3 changes: 3 additions & 0 deletions lib/meta_tags.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require 'set'
require 'active_support/core_ext/hash/indifferent_access'

# MetaTags gem namespace.
module MetaTags
# Returns MetaTags gem configuration.
Expand Down
6 changes: 3 additions & 3 deletions lib/meta_tags/meta_tags_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MetaTagsCollection
# Initializes a new instance of MetaTagsCollection.
#
def initialize
@meta_tags = HashWithIndifferentAccess.new
@meta_tags = ActiveSupport::HashWithIndifferentAccess.new
end

# Returns meta tag value by name.
Expand Down Expand Up @@ -170,10 +170,10 @@ def extract_robots
# Converts input hash to HashWithIndifferentAccess and renames :open_graph to :og.
#
# @param [Hash] meta_tags list of meta tags.
# @return [HashWithIndifferentAccess] normalized meta tags list.
# @return [ActiveSupport::HashWithIndifferentAccess] normalized meta tags list.
#
def normalize_open_graph(meta_tags)
meta_tags = meta_tags.kind_of?(HashWithIndifferentAccess) ? meta_tags.dup : meta_tags.with_indifferent_access
meta_tags = meta_tags.with_indifferent_access
meta_tags[:og] = meta_tags.delete(:open_graph) if meta_tags.key?(:open_graph)
meta_tags
end
Expand Down
2 changes: 1 addition & 1 deletion lib/meta_tags/text_normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def calculate_title_limits(site_title, title, separator, global_limit)
# What should we truncate first: site title or page title?
main_title = MetaTags.config.truncate_site_title_first ? title : [site_title]

main_length = main_title.map(&:length).sum + (main_title.size - 1) * separator.length
main_length = main_title.map(&:length).sum + ((main_title.size - 1) * separator.length)
main_limited_length = global_limit

secondary_limited_length = global_limit - (main_length > 0 ? main_length + separator.length : 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/meta_tags/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def meta_tags
#
# @see #display_meta_tags
#
def set_meta_tags(meta_tags = {}) # rubocop:disable Naming/AccessorMethodName
def set_meta_tags(meta_tags = {})
self.meta_tags.update(meta_tags)
end

Expand Down
13 changes: 7 additions & 6 deletions meta-tags.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/kpumuk/meta-tags"
spec.license = "MIT"
spec.platform = Gem::Platform::RUBY
spec.required_ruby_version = '>= 2.5.0'
spec.required_ruby_version = '>= 2.6.0'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(\.|(bin|test|spec|features)/)}) }
spec.bindir = "exe"
Expand All @@ -33,10 +33,11 @@ Gem::Specification.new do |spec|
spec.signing_key = File.expand_path("~/.ssh/gem-kpumuk.pem") if $PROGRAM_NAME.end_with?('gem')

spec.metadata = {
"bug_tracker_uri" => "https://github.com/kpumuk/meta-tags/issues/",
"changelog_uri" => "https://github.com/kpumuk/meta-tags/blob/main/CHANGELOG.md",
"documentation_uri" => "https://rubydoc.info/github/kpumuk/meta-tags/",
"homepage_uri" => "https://github.com/kpumuk/meta-tags/",
"source_code_uri" => "https://github.com/kpumuk/meta-tags/",
"bug_tracker_uri" => "https://github.com/kpumuk/meta-tags/issues/",
"changelog_uri" => "https://github.com/kpumuk/meta-tags/blob/main/CHANGELOG.md",
"documentation_uri" => "https://rubydoc.info/github/kpumuk/meta-tags/",
"homepage_uri" => "https://github.com/kpumuk/meta-tags/",
"source_code_uri" => "https://github.com/kpumuk/meta-tags/",
"rubygems_mfa_required" => "true",
}
end
50 changes: 48 additions & 2 deletions sig/lib/_internal/rails.rbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
class ::Hash[unchecked out K, unchecked out V]
def with_indifferent_access: () -> instance
def deep_merge!: (instance other) -> self
def with_indifferent_access: () -> ActiveSupport::HashWithIndifferentAccess[K, V]
def deep_merge!: (instance | ActiveSupport::HashWithIndifferentAccess[K, V] other) -> self
end

class ::Object
def presence: () -> String?
def blank?: () -> bool
def present?: () -> bool
end

class ::Loofah
module TextBehavior
def text: (?Hash[Symbol, untyped]? options) -> String
end

class DocumentFragment
include TextBehavior
end

def self.fragment: (String tags, ?String? encoding) -> DocumentFragment
end

class ::Rails
end

module ActionController
class Base
include _ActionControllerBase

def self.helpers: () -> _ActionViewBase
end
end

module ActiveSupport
class HashWithIndifferentAccess[unchecked out K, unchecked out V] < Hash[K, V]
def with_indifferent_access: () -> self
def deep_merge!: (instance | Hash[K, V] other) -> self
end
end

interface _ActionControllerBase
def render: (*untyped args) { () -> untyped } -> untyped
end

interface _ActionViewBase
def tag: (String name, ?Hash[String | Symbol, untyped] options, ?bool open) -> void

def content_tag: (String name, String content, ?Hash[String | Symbol, untyped] options, ?bool open) -> void

def safe_join: (Array[String], String) -> String

def truncate: (String text, ?Hash[Symbol, untyped] options) -> String

def strip_tags: (String html) -> String
end
17 changes: 0 additions & 17 deletions sig/lib/_rails.rbs

This file was deleted.

2 changes: 1 addition & 1 deletion sig/lib/meta_tags/meta_tags_collection.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module MetaTags

def extract_robots: () -> Hash[String, String]

def normalize_open_graph: (Hash[String | Symbol, untyped] meta_tags) -> Hash[String | Symbol, untyped]
def normalize_open_graph: (Hash[String | Symbol, untyped] meta_tags) -> ActiveSupport::HashWithIndifferentAccess[String | Symbol, untyped]

def extract_separator_section: (String | Symbol name, String default) -> String

Expand Down
2 changes: 1 addition & 1 deletion sig/lib/meta_tags/text_normalizer.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module MetaTags

def cleanup_strings: (keywords? strings, ?strip: bool strip) -> Array[String]

def truncate: (String string, ?Integer limit, ?String natural_separator) -> String
def truncate: (String string, ?Integer? limit, ?String natural_separator) -> String

def truncate_array: (Array[String] string_array, ?Integer? limit, ?String separator, ?String natural_separator) -> Array[String]

Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples_for_set_meta_tags.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

shared_examples_for '.set_meta_tags' do # rubocop:disable Metrics/BlockLength
shared_examples_for '.set_meta_tags' do
context 'with a Hash parameter' do
it 'updates meta tags' do
subject.set_meta_tags(title: 'hello')
Expand Down

0 comments on commit 29a47de

Please sign in to comment.