No commit activity in last 3 years
No release in over 3 years
Sort declarative methods of Rails model, as an extension to RuboCop.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 2.13.0
~> 1.0.0
~> 4.6.4
~> 10.0
~> 3.4.0

Runtime

= 0.37.2
 Project Readme

Rubocop::Rails::OrderModelDeclarativeMethods

Gem Version Build Status

Sort declarative methods of Rails model, as an extension to RuboCop.

What's this?

Bad code

class User < ActiveRecord::Base
  belongs_to :plan
  validate :validate_name
  after_create :after_create_1
  has_many :messages
  attr_readonly :email
  after_create :after_create_2
  belongs_to :role
  before_create :set_name
end

Declarative methods are not sorted...

Run rubocop --auto-correct

class User < ActiveRecord::Base
  belongs_to :plan
  belongs_to :role
  has_many :messages

  validate :validate_name
  before_create :set_name
  after_create :after_create_1
  after_create :after_create_2

  attr_readonly :email

end
  • Group by associations, callbacks, and others.
  • Sort by execution order if it's callback method.

Installation

Just install the rubocop-rails-order_model_declarative_methods gem.

gem install rubocop-rails-order_model_declarative_methods

or if you use bundler put this in your Gemfile.

gem 'rubocop-rails-order_model_declarative_methods'

Usage

RuboCop configuration file

Put this into your .rubocop.yml.

require: rubocop-rails-order_model_declarative_methods

Command line

rubocop --require rubocop-rails-order_model_declarative_methods

Rake task

RuboCop::RakeTask.new do |task|
  task.requires << 'rubocop-rails-order_model_declarative_methods'
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Links

License

These codes are licensed under CC0.

CC0