Skip to content

Commit

Permalink
Merge pull request #217 from countries/code-cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
pmor authored Apr 29, 2023
2 parents 796ae17 + de3acd0 commit a8734cf
Show file tree
Hide file tree
Showing 17 changed files with 317 additions and 196 deletions.
61 changes: 61 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: "2"
checks:
argument-count:
enabled: true
config:
threshold: 4
complex-logic:
enabled: true
config:
threshold: 4
file-lines:
enabled: true
config:
threshold: 250
method-complexity:
enabled: true
config:
threshold: 5
method-count:
enabled: true
config:
threshold: 20
method-lines:
enabled: true
config:
threshold: 25
nested-control-flow:
enabled: true
config:
threshold: 4
return-statements:
enabled: true
config:
threshold: 4
plugins:
rubocop:
enabled: true
channel: rubocop-1-48-1
reek:
enabled: true
checks:
IrresponsibleModule:
enabled: false
TooManyStatements:
max_statements: 7
flog:
enabled: true
bundler-audit:
enabled: true
exclude_patterns:
- "config/"
- "db/"
- "dist/"
- "features/"
- "**/node_modules/"
- "script/"
- "**/spec/"
- "**/test/"
- "**/tests/"
- "**/vendor/"
- "**/*.d.ts"
33 changes: 33 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
AllCops:
NewCops: enable
TargetRubyVersion: 2.7

Metrics/MethodLength:
Enabled: false

Metrics/LineLength:
Max: 120

Style/Documentation:
Enabled: false

Bundler/OrderedGems:
Enabled: false

Naming/FileName:
Exclude:
- 'gemfiles/*'

Metrics/BlockLength:
Exclude:
- 'spec/**/*'

Style/MutableConstant:
Exclude:
- 'lib/country_select/defaults.rb'
- 'lib/country_select/formats.rb'

Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'lib/country_select/tag_helper.rb'

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
23 changes: 10 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,25 @@ RSpec::Core::RakeTask.new(:spec)

task default: 'spec'


task :update_gemfiles do
require 'pry'
Dir.glob('gemfiles/*.gemfile').each do |gemfile|
puts "Updating #{gemfile}...\n\n"
ENV['BUNDLE_GEMFILE']=gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
puts `bundle install --gemfile=#{gemfile} --no-cache`
puts `bundle update --gemfile=#{gemfile}`

lockfile = "#{gemfile}.lock"

if File.exist? lockfile
parsed_lockfile = Bundler::LockfileParser.new(Bundler.read_file(lockfile))
# Ensure lockfile has x86_64-linux
if parsed_lockfile.platforms.map(&:to_s).none? {|p| p == 'x86_64-linux' }
puts "Adding platform x86_64-linux to #{lockfile}\n\n"
puts `bundle lock --add-platform x86_64-linux --gemfile=#{gemfile}`
end

puts ""
else
raise StandardError.new("Expected #{lockfile} to exist.")
raise(StandardError, "Expected #{lockfile} to exist.") unless File.exist?(lockfile)

parsed_lockfile = Bundler::LockfileParser.new(Bundler.read_file(lockfile))
# Ensure lockfile has x86_64-linux
if parsed_lockfile.platforms.map(&:to_s).none? { |p| p == 'x86_64-linux' }
puts "Adding platform x86_64-linux to #{lockfile}\n\n"
puts `bundle lock --add-platform x86_64-linux --gemfile=#{gemfile}`
end

puts ''
end
end
19 changes: 11 additions & 8 deletions country_select.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'country_select/version'

Gem::Specification.new do |s|
Expand All @@ -9,16 +10,18 @@ Gem::Specification.new do |s|
s.authors = ['Stefan Penner']
s.email = ['[email protected]']
s.homepage = 'https://github.com/countries/country_select'
s.summary = %q{Country Select Plugin}
s.description = %q{Provides a simple helper to get an HTML select list of countries. The list of countries comes from the ISO 3166 standard. While it is a relatively neutral source of country names, it will still offend some users.}
s.summary = 'Country Select Plugin'
s.description = 'Provides a simple helper to get an HTML select list of countries. \
The list of countries comes from the ISO 3166 standard. \
While it is a relatively neutral source of country names, it will still offend some users.'

s.metadata = { 'bug_tracker_uri' => 'http://github.com/countries/country_select/issues',
'changelog_uri' => 'https://github.com/countries/country_select/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/countries/country_select' }
'changelog_uri' => 'https://github.com/countries/country_select/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/countries/country_select',
'rubygems_mfa_required' => 'true' }

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

s.required_ruby_version = '>= 2.7'
Expand Down
10 changes: 6 additions & 4 deletions gemfiles/actionpack-5.2.gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
source "https://rubygems.org"
# frozen_string_literal: true

gemspec :path => "../"
source 'https://rubygems.org'

gem "railties", "~> 5.2.0"
gem "actionpack", "~> 5.2.0"
gemspec path: '../'

gem 'railties', '~> 5.2.0'
gem 'actionpack', '~> 5.2.0'
gem 'nokogiri', '= 1.14.0.rc1'
10 changes: 6 additions & 4 deletions gemfiles/actionpack-6.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
source "https://rubygems.org"
# frozen_string_literal: true

gemspec :path => "../"
source 'https://rubygems.org'

gem "railties", "~> 6.0.0"
gem "actionpack", "~> 6.0.0"
gemspec path: '../'

gem 'railties', '~> 6.0.0'
gem 'actionpack', '~> 6.0.0'
gem 'nokogiri', '= 1.14.0.rc1'
10 changes: 6 additions & 4 deletions gemfiles/actionpack-6.1.gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
source "https://rubygems.org"
# frozen_string_literal: true

gemspec :path => "../"
source 'https://rubygems.org'

gem "railties", "~> 6.1.0"
gem "actionpack", "~> 6.1.0"
gemspec path: '../'

gem 'railties', '~> 6.1.0'
gem 'actionpack', '~> 6.1.0'
gem 'nokogiri', '= 1.14.0.rc1'
10 changes: 6 additions & 4 deletions gemfiles/actionpack-7.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
source "https://rubygems.org"
# frozen_string_literal: true

gemspec :path => "../"
source 'https://rubygems.org'

gem "railties", "~> 7.0.0"
gem "actionpack", "~> 7.0.0"
gemspec path: '../'

gem 'railties', '~> 7.0.0'
gem 'actionpack', '~> 7.0.0'
gem 'nokogiri', '= 1.14.0.rc1'
2 changes: 1 addition & 1 deletion lib/country_select.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8
# frozen_string_literal: true

require 'countries'

Expand Down
10 changes: 7 additions & 3 deletions lib/country_select/country_select_helper.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# frozen_string_literal: true

module ActionView
module Helpers
class FormBuilder
def country_select(method, priority_or_options = {}, options = {}, html_options = {})
if Hash === priority_or_options
if priority_or_options.is_a? Hash
html_options = options
options = priority_or_options
else
if RUBY_VERSION =~ /^3\.\d\.\d/
warn "DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. Please use the `priority_countries:` option.", uplevel: 1, category: :deprecated
warn 'DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. \
Please use the `priority_countries:` option.', uplevel: 1, category: :deprecated
else
warn "DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. Please use the `priority_countries:` option.", uplevel: 1
warn 'DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. \
Please use the `priority_countries:` option.', uplevel: 1
end
options[:priority_countries] = priority_or_options
end
Expand Down
4 changes: 3 additions & 1 deletion lib/country_select/defaults.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

module CountrySelect
DEFAULTS = {
except: nil,
format: :default,
locale: nil,
only: nil,
priority_countries: nil,
priority_countries_divider: "-" * 15,
priority_countries_divider: '-' * 15,
sort_provided: true
}
end
2 changes: 2 additions & 0 deletions lib/country_select/formats.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module CountrySelect
FORMATS = {}

Expand Down
Loading

0 comments on commit a8734cf

Please sign in to comment.