diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4d54c75 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: ci + +on: + - push + - pull_request + +jobs: + test: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + gemfile: ['rails_7.1', 'rails_7.0'] + ruby: [3.3, 3.2, 3.1] + include: + - gemfile: rails_7.1 + ruby: '3.0' + - gemfile: rails_7.1 + ruby: 2.7 + - gemfile: rails_7.0 + ruby: '3.0' + - gemfile: rails_7.0 + ruby: 2.7 + - gemfile: rails_6.1 + ruby: 2.7 + - gemfile: rails_6.0 + ruby: 2.7 + - gemfile: rails_5.2 + ruby: 2.7 + - gemfile: rails_5.1 + ruby: 2.7 + - gemfile: rails_5.0 + ruby: 2.7 + + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile + CI: true + COVERALLS_REPO_TOKEN: 3PVU3qEEgaWdwemUGBjnbYwv87BPTti9u + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: RSpec and Rubocop + run: | + bundle exec rubocop -c .rubocop.yml + bundle exec rspec diff --git a/.rubocop.hound.yml b/.rubocop.hound.yml deleted file mode 100644 index 0a94997..0000000 --- a/.rubocop.hound.yml +++ /dev/null @@ -1,261 +0,0 @@ -# this is the default from hound's github, do not modify -AllCops: - Exclude: - - db/schema.rb - -AccessorMethodName: - Enabled: false - -ActionFilter: - Enabled: false - -Alias: - Enabled: false - -ArrayJoin: - Enabled: false - -AsciiComments: - Enabled: false - -AsciiIdentifiers: - Enabled: false - -Attr: - Enabled: false - -BlockNesting: - Enabled: false - -CaseEquality: - Enabled: false - -CharacterLiteral: - Enabled: false - -ClassAndModuleChildren: - Enabled: false - -ClassLength: - Enabled: false - -ClassVars: - Enabled: false - -CollectionMethods: - PreferredMethods: - find: detect - reduce: inject - collect: map - find_all: select - -ColonMethodCall: - Enabled: false - -CommentAnnotation: - Enabled: false - -CyclomaticComplexity: - Enabled: false - -Delegate: - Enabled: false - -DeprecatedHashMethods: - Enabled: false - -Documentation: - Enabled: false - -DotPosition: - EnforcedStyle: trailing - -DoubleNegation: - Enabled: false - -EachWithObject: - Enabled: false - -EmptyLiteral: - Enabled: false - -Encoding: - Enabled: false - -EvenOdd: - Enabled: false - -FileName: - Enabled: false - -FlipFlop: - Enabled: false - -FormatString: - Enabled: false - -GlobalVars: - Enabled: false - -GuardClause: - Enabled: false - -IfUnlessModifier: - Enabled: false - -IfWithSemicolon: - Enabled: false - -InlineComment: - Enabled: false - -Lambda: - Enabled: false - -LambdaCall: - Enabled: false - -LineEndConcatenation: - Enabled: false - -LineLength: - Max: 120 - AllowURI: true - -MethodLength: - Enabled: false - -ModuleFunction: - Enabled: false - -NegatedIf: - Enabled: false - -NegatedWhile: - Enabled: false - -Next: - Enabled: false - -NilComparison: - Enabled: false - -Not: - Enabled: false - -NumericLiterals: - Enabled: false - -OneLineConditional: - Enabled: false - -OpMethod: - Enabled: false - -ParameterLists: - Enabled: false - -PercentLiteralDelimiters: - Enabled: false - -PerlBackrefs: - Enabled: false - -PredicateName: - NamePrefixBlacklist: - - is_ - -Proc: - Enabled: false - -RaiseArgs: - Enabled: false - -RegexpLiteral: - Enabled: false - -SelfAssignment: - Enabled: false - -SingleLineBlockParams: - Enabled: false - -SingleLineMethods: - Enabled: false - -SignalException: - Enabled: false - -SpecialGlobalVars: - Enabled: false - -StringLiterals: - EnforcedStyle: double_quotes - -VariableInterpolation: - Enabled: false - -TrailingComma: - Enabled: false - -TrivialAccessors: - Enabled: false - -VariableInterpolation: - Enabled: false - -WhenThen: - Enabled: false - -WhileUntilModifier: - Enabled: false - -WordArray: - Enabled: false - -# Lint - -AmbiguousOperator: - Enabled: false - -AmbiguousRegexpLiteral: - Enabled: false - -AssignmentInCondition: - Enabled: false - -ConditionPosition: - Enabled: false - -DeprecatedClassMethods: - Enabled: false - -ElseLayout: - Enabled: false - -HandleExceptions: - Enabled: false - -InvalidCharacterLiteral: - Enabled: false - -LiteralInCondition: - Enabled: false - -LiteralInInterpolation: - Enabled: false - -Loop: - Enabled: false - -ParenthesesAsGroupedExpression: - Enabled: false - -RequireParentheses: - Enabled: false - -UnderscorePrefixedVariableName: - Enabled: false - -Void: - Enabled: false diff --git a/.rubocop.yml b/.rubocop.yml index 222945a..8cc6a71 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,19 +1,16 @@ -inherit_from: - - .rubocop.hound.yml +inherit_from: .rubocop_todo.yml AllCops: - TargetRubyVersion: 2.1 - Exclude: - - '*.gemspec' - - 'Gemfile' + NewCops: enable + TargetRubyVersion: 2.7 -Style/EmptyLinesAroundClassBody: +Layout/EmptyLinesAroundClassBody: Enabled: false -Style/EmptyLinesAroundModuleBody: +Layout/EmptyLinesAroundModuleBody: Enabled: false -Style/EmptyLinesAroundMethodBody: +Layout/EmptyLinesAroundMethodBody: Enabled: false Style/ClassCheck: @@ -23,7 +20,7 @@ Style/ClassCheck: Style/StringLiterals: Enabled: false -Style/FileName: +Naming/FileName: Enabled: false Style/RedundantException: @@ -35,19 +32,11 @@ Style/SignalException: Style/BlockDelimiters: Enabled: false -Style/CollectionMethods: - PreferredMethods: - detect: find - # Github's PR width is 120 characters -Metrics/LineLength: +Layout/LineLength: Max: 120 AllowURI: true -# Align with the style guide, we don't prefer anything -Style/CollectionMethods: - Enabled: false - Metrics/AbcSize: Description: A calculated magnitude based on number of assignments, branches, and conditions. diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..e5dba3f --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,284 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 250` +# on 2023-10-30 06:15:37 UTC using RuboCop version 1.57.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'gemfiles/rails_7.1.gemfile' + +# Offense count: 9 +# Configuration parameters: EnforcedStyle, AllowedGems, Include. +# SupportedStyles: Gemfile, gems.rb, gemspec +# Include: **/*.gemspec, **/Gemfile, **/gems.rb +Gemspec/DevelopmentDependencies: + Exclude: + - 'ph_model.gemspec' + +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'ph_model.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'ph_model.gemspec' + +# Offense count: 1 +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'ph_model.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'lib/ph_model/concerns/attribute_nested_validation.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'lib/ph_model/version.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space +Layout/LineContinuationSpacing: + Exclude: + - 'spec/active_model/validations/collection_items_validator_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/LineEndStringConcatenationIndentation: + Exclude: + - 'spec/active_model/validations/collection_items_validator_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/MultilineOperationIndentation: + Exclude: + - 'lib/ph_model/concerns/attribute_nested_validation.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: require_no_space, require_space +Layout/SpaceInLambdaLiteral: + Exclude: + - 'lib/active_model/validations/collection_items_validator/array_attribute_reader.rb' + - 'spec/active_model/validations/collection_items_validator/array_attribute_getter_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'lib/ph_model.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +Lint/UnusedMethodArgument: + Exclude: + - 'lib/ph_model/concerns/attribute_nested_validation.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: CheckForMethodsWithNoSideEffects. +Lint/Void: + Exclude: + - 'lib/ph_model.rb' + +# Offense count: 3 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 61 + +# Offense count: 2 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 9 + +# Offense count: 2 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 23 + +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 11 + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'lib/active_model/validations/collection_items_validator/array_attribute_getter.rb' + - 'lib/active_model/validations/collection_items_validator/array_attribute_reader.rb' + - 'lib/active_model/validations/collection_items_validator/inner_validator_builder.rb' + +# Offense count: 5 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/ph_model.rb' + - 'lib/ph_model/concerns.rb' + - 'lib/ph_model/concerns/attribute_nested_validation.rb' + - 'lib/ph_model/concerns/attribute_of_array_type_initialization.rb' + - 'lib/ph_model/concerns/attribute_required_validation.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/Encoding: + Exclude: + - 'ph_model.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/ExpandPathArguments: + Exclude: + - 'ph_model.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/FileWrite: + Exclude: + - 'Rakefile' + +# Offense count: 23 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Exclude: + - 'Gemfile' + - 'Rakefile' + - 'lib/active_model/validations/collection_items_validator.rb' + - 'lib/active_model/validations/collection_items_validator/array_attribute_getter.rb' + - 'lib/active_model/validations/collection_items_validator/array_attribute_reader.rb' + - 'lib/active_model/validations/collection_items_validator/inner_validator_builder.rb' + - 'lib/active_model/validations/type_validator.rb' + - 'lib/ph_model.rb' + - 'lib/ph_model/concerns.rb' + - 'lib/ph_model/concerns/attribute_nested_validation.rb' + - 'lib/ph_model/concerns/attribute_of_array_type_initialization.rb' + - 'lib/ph_model/concerns/attribute_required_validation.rb' + - 'lib/ph_model/concerns/attribute_type_validation.rb' + - 'lib/ph_model/concerns/initialize_callback.rb' + - 'lib/ph_model/concerns/validated_factory.rb' + - 'lib/ph_model/validation_failed.rb' + - 'ph_model.gemspec' + - 'spec/active_model/validations/collection_items_validator/array_attribute_getter_spec.rb' + - 'spec/active_model/validations/collection_items_validator/inner_validator_builder_spec.rb' + - 'spec/active_model/validations/collection_items_validator_spec.rb' + - 'spec/active_model/validations/type_validator_spec.rb' + - 'spec/model_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. +Style/GuardClause: + Exclude: + - 'lib/active_model/validations/type_validator.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowIfModifier. +Style/IfInsideElse: + Exclude: + - 'lib/ph_model/concerns/attribute_type_validation.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/IfUnlessModifier: + Exclude: + - 'lib/ph_model/concerns/attribute_required_validation.rb' + - 'lib/ph_model/concerns/validated_factory.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/MultilineIfModifier: + Exclude: + - 'lib/ph_model.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: . +# SupportedStyles: same_as_string_literals, single_quotes, double_quotes +Style/QuotedSymbols: + EnforcedStyle: double_quotes + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantFreeze: + Exclude: + - 'lib/ph_model/version.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantSelf: + Exclude: + - 'lib/ph_model.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/ph_model.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowModifier. +Style/SoleNestedConditional: + Exclude: + - 'lib/ph_model/concerns/attribute_of_array_type_initialization.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/StderrPuts: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MinSize. +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets diff --git a/gemfiles/rails_5.0.gemfile b/gemfiles/rails_5.0.gemfile new file mode 100644 index 0000000..1ea8295 --- /dev/null +++ b/gemfiles/rails_5.0.gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "rails", "~> 5.0.7" + +gemspec path: "../" diff --git a/gemfiles/rails_5.1.gemfile b/gemfiles/rails_5.1.gemfile new file mode 100644 index 0000000..525f0e0 --- /dev/null +++ b/gemfiles/rails_5.1.gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "rails", "~> 5.1.7" + +gemspec path: "../" diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile new file mode 100644 index 0000000..da8403a --- /dev/null +++ b/gemfiles/rails_5.2.gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "rails", "~> 5.2.6" + +gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile new file mode 100644 index 0000000..12bfdb7 --- /dev/null +++ b/gemfiles/rails_6.0.gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "rails", "~> 6.0.4" + +gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile new file mode 100644 index 0000000..72e5a47 --- /dev/null +++ b/gemfiles/rails_6.1.gemfile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "minitest" +gem "rails", "~> 6.1.4" + +gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile new file mode 100644 index 0000000..4ff9fd5 --- /dev/null +++ b/gemfiles/rails_7.0.gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "rails", "~> 7.0.2" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 0000000..8cdff14 --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "rails", "~> 7.1.1" +gem "active_attr", git: "https://github.com/mathieujobin/active_attr", branch: "rails-7.1-support" + +gemspec path: "../" diff --git a/lib/active_model/validations/collection_items_validator/inner_validator_builder.rb b/lib/active_model/validations/collection_items_validator/inner_validator_builder.rb index bb09969..b031d7b 100644 --- a/lib/active_model/validations/collection_items_validator/inner_validator_builder.rb +++ b/lib/active_model/validations/collection_items_validator/inner_validator_builder.rb @@ -14,7 +14,7 @@ def initialize(validator_name, options) end def build - validator_class.new inner_options.merge(attributes: [:base]) + validator_class.new(**inner_options.merge(attributes: [:base])) end private diff --git a/lib/ph_model.rb b/lib/ph_model.rb index e9faacc..54e79d7 100644 --- a/lib/ph_model.rb +++ b/lib/ph_model.rb @@ -40,8 +40,8 @@ def as_json(*) end def inspect - attr_info = self.class.attributes.map { |attr_name, info| "#{attr_name}: #{self.send(attr_name).inspect}" }.join(", ") - "#<#{self.model_name} #{attr_info}>" + attr_info = self.class.attributes.map { |attr_name, info| "#{attr_name}: #{self.send(attr_name).inspect}" } + "#<#{self.model_name} #{attr_info.join(', ')}>" end # Monkey patch #assign_attributes inside ActiveAttr::MassAssignment diff --git a/lib/ph_model/version.rb b/lib/ph_model/version.rb index 4343d28..714f492 100644 --- a/lib/ph_model/version.rb +++ b/lib/ph_model/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module PhModel - VERSION = '1.1.3'.freeze + VERSION = '1.2.0'.freeze end diff --git a/ph_model.gemspec b/ph_model.gemspec index 9b93221..a16dafc 100644 --- a/ph_model.gemspec +++ b/ph_model.gemspec @@ -18,19 +18,19 @@ Gem::Specification.new do |gem| gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } gem.require_paths = ['lib'] - gem.add_runtime_dependency 'activesupport', '> 3.2' - gem.add_runtime_dependency 'activemodel', '> 3.2' - gem.add_runtime_dependency 'active_attr', '~> 0.8' + gem.add_runtime_dependency 'activesupport', '> 5.0' + gem.add_runtime_dependency 'activemodel', '> 5.0' + gem.add_runtime_dependency 'active_attr', '~> 0.15' # 0.16 for rails 7.1 gem.add_development_dependency 'faraday' - gem.add_development_dependency 'bundler', '~> 1.0' - gem.add_development_dependency 'rake', '~> 10.0' + gem.add_development_dependency 'bundler', '> 2.2' + gem.add_development_dependency 'rake', '> 10.0' gem.add_development_dependency 'rspec', '~> 3.0' gem.add_development_dependency 'rubygems-tasks', '~> 0.2' gem.add_development_dependency 'pry', '> 0' gem.add_development_dependency 'github_changelog_generator', '~> 1.6' # static analysis gems - gem.add_development_dependency 'rubocop', '~> 0.36.0' - gem.add_development_dependency 'reek', '~> 3.10' + gem.add_development_dependency 'rubocop', '~> 1.33' + gem.add_development_dependency 'reek', '> 3.10' end diff --git a/spec/model_spec.rb b/spec/model_spec.rb index 236de79..44e6e99 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -21,7 +21,7 @@ example do expect { klass.build one: 'two', foo: :bar - }.to raise_exception(NoMethodError, /undefined method `one=' for #/) + }.to raise_exception(NoMethodError, /undefined method `one=' for .*FooModel/) end end