Skip to content

Commit

Permalink
Require ruby 3.2+.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Mar 1, 2024
1 parent 58c32fd commit 7e27159
Show file tree
Hide file tree
Showing 24 changed files with 130 additions and 131 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ruby-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.7", "3.0", "3.1"]
node: ["16", "18"]
ruby: ["3.2", "3.3"]
node: ["18", "20"]
gemfile:
- Gemfile
if: |
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ inherit_gem:
rubocop-fnando: .rubocop.yml

AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 3.2
NewCops: enable
Exclude:
- tmp/**/*
Expand Down
4 changes: 2 additions & 2 deletions i18n-js.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative "./lib/i18n-js/version"
require_relative "lib/i18n-js/version"

Gem::Specification.new do |spec|
spec.name = "i18n-js"
Expand All @@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
spec.summary = "Export i18n translations and use them on JavaScript."
spec.description = spec.summary
spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
spec.metadata = {"rubygems_mfa_required" => "true"}

github_url = "https://github.com/fnando/i18n-js"
Expand Down
7 changes: 3 additions & 4 deletions lib/i18n-js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
require "fileutils"
require "optparse"
require "erb"
require "set"
require "digest/md5"

require_relative "i18n-js/schema"
Expand All @@ -28,7 +27,7 @@ def self.call(config_file: nil, config: nil)
config = Glob::SymbolizeKeys.call(config || load_config_file(config_file))

load_plugins!
initialize_plugins!(config: config)
initialize_plugins!(config:)
Schema.validate!(config)

exported_files = []
Expand Down Expand Up @@ -59,7 +58,7 @@ def self.export_group(group)

if output_file_path.include?(":locale")
filtered_translations.each_key do |locale|
locale_file_path = output_file_path.gsub(/:locale/, locale.to_s)
locale_file_path = output_file_path.gsub(":locale", locale.to_s)
exported_files << write_file(locale_file_path,
locale => filtered_translations[locale])
end
Expand All @@ -75,7 +74,7 @@ def self.write_file(file_path, translations)

contents = ::JSON.pretty_generate(translations)
digest = Digest::MD5.hexdigest(contents)
file_path = file_path.gsub(/:digest/, digest)
file_path = file_path.gsub(":digest", digest)

# Don't rewrite the file if it already exists and has the same content.
# It helps the asset pipeline or webpack understand that file wasn't
Expand Down
4 changes: 2 additions & 2 deletions lib/i18n-js/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CLI

def initialize(argv:, stdout:, stderr:, colored: stdout.tty?)
@argv = argv.dup
@ui = UI.new(stdout: stdout, stderr: stderr, colored: colored)
@ui = UI.new(stdout:, stderr:, colored:)
end

def call
Expand All @@ -43,7 +43,7 @@ def call

private def commands
command_classes.map do |command_class|
command_class.new(argv: @argv, ui: ui)
command_class.new(argv: @argv, ui:)
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/i18n-js/cli/export_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ class ExportCommand < Command

time = Benchmark.realtime do
load_require_file!(require_file) if require_file
I18nJS.call(config_file: config_file)
I18nJS.call(config_file:)
end

log("=> Done in #{time.round(2)}s")
end

private def log(*args)
private def log(*)
return if options[:quiet]

ui.stdout_print(*args)
ui.stdout_print(*)
end

private def set_defaults!
Expand Down
4 changes: 2 additions & 2 deletions lib/i18n-js/cli/lint_scripts_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class LintScriptsCommand < Command

config = load_config_file(config_file)
I18nJS.load_plugins!
I18nJS.initialize_plugins!(config: config)
I18nJS.initialize_plugins!(config:)
Schema.validate!(config)

load_require_file!(require_file) if require_file
Expand All @@ -91,7 +91,7 @@ class LintScriptsCommand < Command

ui.stdout_print "=> Available locales: #{available_locales.inspect}"

exported_files = I18nJS.call(config_file: config_file)
exported_files = I18nJS.call(config_file:)
data = exported_files.each_with_object({}) do |file, buffer|
buffer.merge!(JSON.load_file(file, symbolize_names: true))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n-js/cli/lint_translations_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class LintTranslationsCommand < Command

config = load_config_file(config_file)
I18nJS.load_plugins!
I18nJS.initialize_plugins!(config: config)
I18nJS.initialize_plugins!(config:)
Schema.validate!(config)

load_require_file!(require_file) if require_file
Expand Down
14 changes: 7 additions & 7 deletions lib/i18n-js/export_files_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ def after_export(files:)
config[:files].each do |export|
translations = JSON.load_file(file)
template = Template.new(
file: file,
translations: translations,
file:,
translations:,
template: export[:template]
)

contents = template.render

output = format(
export[:output],
dir: dir,
name: name,
extension: extension,
dir:,
name:,
extension:,
digest: Digest::MD5.hexdigest(contents),
base_name: base_name
base_name:
)

File.open(output, "w") do |io|
Expand All @@ -82,7 +82,7 @@ class Template

def initialize(**kwargs)
kwargs.each do |key, value|
public_send("#{key}=", value)
public_send(:"#{key}=", value)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/i18n-js/listen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.listen(
debug("Watching #{relative_paths.inspect}")

listener(config_file, locales_dirs.map(&:to_s), options).start
I18nJS.call(config_file: config_file) if run_on_start
I18nJS.call(config_file:) if run_on_start
end

def self.relative_path(path)
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n-js/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.load_plugins!

def self.initialize_plugins!(config:)
@plugins = available_plugins.map do |plugin|
plugin.new(config: config).tap(&:setup)
plugin.new(config:).tap(&:setup)
end
end

Expand Down
18 changes: 9 additions & 9 deletions lib/i18n-js/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def reject(error_message, node = nil)
end

def expect_type(path:, types:)
path = prepare_path(path: path)
value = value_for(path: path)
path = prepare_path(path:)
value = value_for(path:)
types = Array(types)

return if types.any? {|type| value.is_a?(type) }
Expand All @@ -156,10 +156,10 @@ def expect_type(path:, types:)
end

def expect_array_with_items(path:)
expect_type(path: path, types: Array)
expect_type(path:, types: Array)

path = prepare_path(path: path)
value = value_for(path: path)
path = prepare_path(path:)
value = value_for(path:)

return unless value.empty?

Expand All @@ -168,8 +168,8 @@ def expect_array_with_items(path:)
end

def expect_required_keys(keys:, path:)
path = prepare_path(path: path)
value = value_for(path: path)
path = prepare_path(path:)
value = value_for(path:)
actual_keys = value.keys.map(&:to_sym)

keys.each do |key|
Expand All @@ -186,8 +186,8 @@ def expect_required_keys(keys:, path:)
end

def reject_extraneous_keys(keys:, path:)
path = prepare_path(path: path)
value = value_for(path: path)
path = prepare_path(path:)
value = value_for(path:)

actual_keys = value.keys.map(&:to_sym)
extraneous = actual_keys.to_a - keys.to_a
Expand Down
36 changes: 18 additions & 18 deletions test/i18n-js/cli/check_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class CheckCommandTest < Minitest::Test
test "displays help" do
cli = I18nJS::CLI.new(
argv: %w[check --help],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(0) { cli.call }
Expand All @@ -20,8 +20,8 @@ class CheckCommandTest < Minitest::Test
test "without a config file" do
cli = I18nJS::CLI.new(
argv: %w[check],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(1) { cli.call }
Expand All @@ -35,8 +35,8 @@ class CheckCommandTest < Minitest::Test

cli = I18nJS::CLI.new(
argv: %W[check --config #{config_file}],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(1) { cli.call }
Expand All @@ -54,8 +54,8 @@ class CheckCommandTest < Minitest::Test
--config test/config/everything.yml
--require #{require_file}
],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(1) { cli.call }
Expand All @@ -68,8 +68,8 @@ class CheckCommandTest < Minitest::Test

cli = I18nJS::CLI.new(
argv: %w[check --config test/config/everything.yml],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(0) { cli.call }
Expand All @@ -85,8 +85,8 @@ class CheckCommandTest < Minitest::Test
--config test/config/everything.yml
--require test/config/require_error.rb
],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(1) { cli.call }
Expand All @@ -105,8 +105,8 @@ class CheckCommandTest < Minitest::Test
--require test/config/require.rb
--color
],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(1) { cli.call }
Expand All @@ -125,8 +125,8 @@ class CheckCommandTest < Minitest::Test
--config test/config/everything.yml
--require test/config/require.rb
],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(1) { cli.call }
Expand All @@ -150,8 +150,8 @@ class CheckCommandTest < Minitest::Test
--config test/config/check.yml
--require test/config/require.rb
],
stdout: stdout,
stderr: stderr
stdout:,
stderr:
)

assert_exit_code(0) { cli.call }
Expand Down
Loading

0 comments on commit 7e27159

Please sign in to comment.