/strainer

Identify incompatible + synvert-able code in rails apps when migrating from 4.2 to 6.0.x

Primary LanguageRubyMIT LicenseMIT

Strainer Icon

Strainer

Gem Version

Code Climate Maintainability Code Climate Test Coverage Circle CI Status

Table of Contents

Requirements

  1. Ruby 2.6.5
  2. [Rails 6.x]

Usage

To install add the gem in your Gemfile. This will downgrade some rails behavior to look like Rails 4 (for which behaviors are downgraded see lib/strainer/behaviors)

Adding a behavior:

Basic behavior looks like this (needs to be place in lib/strainer/behaviors):

module Strainer
  module Behaviors
    # Comment describing the override
    class {{BehaviorClassName}} < Strainer::RuntimeBehavior
      module {{ModuleThatImplementsOverride}}
        include Strainer::Logable

        def uniq(value = true)
          # The strainer_log method is used to dump data identifying the kind of rails
          # incompatibility and the source location along with extra payload data
          strainer_log('BEHAVIOR_IDENTIFIER', custom: { CUSTOM_DATA_KEY: 'CUSTOM_DATA_VALUE' })
          distinct(value)
        end

      end

      def apply_patch!
        # Place code here that patches rails behavior
        # eg. to add this behavior to ActiveRecord::Relation do:
        # ActiveRecord::Relation.include({{ModuleThatImplementsOverride}})
      end
    end
  end
end

# To enable the patch onload of the railtie add this behavior in patches.rb

def self.setup!(component)
  case component
  when :action_controller
    load_behaviors Behaviors::ParametersAsHash
  when :active_record
    load_behaviors(
      Behaviors::ForcedReloading,
      Behaviors::RelationDelegationChanges,
      Behaviors::FinderChanges,
      Behaviors::RelationQueryMethodChanges,
      {{*Behaviors::BehaviorClassName*}},
    )
  end
end


Tests

TBD

Versioning

Read Semantic Versioning for details. Briefly, it means:

  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
  • Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.

Contributions

Read CONTRIBUTING for details.

License

Copyright 2019 . Read LICENSE for details.

History

Read CHANGES for details. Built with Gemsmith.

Credits

Developed by Rishab Govind at .