├── .ruby-version
├── spec
├── internal
│ ├── log
│ │ └── .gitignore
│ ├── public
│ │ └── favicon.ico
│ ├── app
│ │ ├── decorators
│ │ │ ├── tag_decorator.rb
│ │ │ ├── application_decorator.rb
│ │ │ ├── author_decorator.rb
│ │ │ └── post_decorator.rb
│ │ ├── models
│ │ │ ├── author.rb
│ │ │ ├── post_tag.rb
│ │ │ ├── tag.rb
│ │ │ └── post.rb
│ │ ├── controllers
│ │ │ ├── application_controller.rb
│ │ │ └── posts_controller.rb
│ │ └── views
│ │ │ ├── posts
│ │ │ └── show.html.erb
│ │ │ └── layouts
│ │ │ └── application.html.erb
│ ├── config
│ │ ├── database.yml
│ │ └── routes.rb
│ └── db
│ │ └── schema.rb
├── factories
│ ├── post_tag.rb
│ ├── tag.rb
│ ├── author.rb
│ └── post.rb
├── integration
│ └── posts_spec.rb
├── spec_helper.rb
├── generators
│ ├── install
│ │ └── install_generator_spec.rb
│ └── decorator
│ │ └── decorator_generator_spec.rb
└── decorators
│ ├── post_decorator_spec.rb
│ └── author_decorator_spec.rb
├── .rspec
├── Gemfile
├── lib
├── generators
│ ├── rails
│ │ ├── decorator
│ │ │ ├── templates
│ │ │ │ └── decorator.rb
│ │ │ └── decorator_generator.rb
│ │ └── hooks.rb
│ ├── test_unit
│ │ └── decorator
│ │ │ ├── templates
│ │ │ └── decorator_test.rb
│ │ │ └── decorator_generator.rb
│ ├── rspec
│ │ └── decorator
│ │ │ ├── templates
│ │ │ └── decorator_spec.rb
│ │ │ └── decorator_generator.rb
│ └── light
│ │ └── decorator
│ │ └── install
│ │ ├── templates
│ │ └── application_decorator.rb
│ │ └── install_generator.rb
└── light
│ ├── decorator
│ ├── version.rb
│ ├── exceptions.rb
│ ├── view_context.rb
│ ├── railtie.rb
│ ├── concerns
│ │ ├── associations
│ │ │ └── collection_proxy.rb
│ │ ├── relation.rb
│ │ └── base.rb
│ └── decorate.rb
│ └── decorator.rb
├── Rakefile
├── bin
├── setup
└── console
├── config.ru
├── gemfiles
├── rails_4_0.gemfile
├── rails_4_1.gemfile
├── rails_4_2.gemfile
├── rails_5_0.gemfile
├── rails_4_0.gemfile.lock
├── rails_4_1.gemfile.lock
├── rails_4_2.gemfile.lock
└── rails_5_0.gemfile.lock
├── .gitignore
├── .codeclimate.yml
├── Appraisals
├── .travis.yml
├── LICENSE.txt
├── light-decorator.gemspec
├── CODE_OF_CONDUCT.md
├── README.md
└── .rubocop.yml
/.ruby-version:
--------------------------------------------------------------------------------
1 | 2.3.3
2 |
--------------------------------------------------------------------------------
/spec/internal/log/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
--------------------------------------------------------------------------------
/spec/internal/public/favicon.ico:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --format documentation
2 | --color
3 |
--------------------------------------------------------------------------------
/spec/internal/app/decorators/tag_decorator.rb:
--------------------------------------------------------------------------------
1 | class TagDecorator < ApplicationDecorator
2 | end
3 |
--------------------------------------------------------------------------------
/spec/internal/app/models/author.rb:
--------------------------------------------------------------------------------
1 | class Author < ActiveRecord::Base
2 | has_many :posts
3 | end
4 |
--------------------------------------------------------------------------------
/spec/internal/config/database.yml:
--------------------------------------------------------------------------------
1 | test:
2 | adapter: sqlite3
3 | database: db/combustion_test.sqlite
4 |
--------------------------------------------------------------------------------
/spec/internal/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | resources :posts, only: [:show]
3 | end
4 |
--------------------------------------------------------------------------------
/spec/internal/app/decorators/application_decorator.rb:
--------------------------------------------------------------------------------
1 | class ApplicationDecorator < Light::Decorator::Base
2 | end
3 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | # Specify your gem's dependencies in light-decorator.gemspec
4 | gemspec
5 |
--------------------------------------------------------------------------------
/lib/generators/rails/decorator/templates/decorator.rb:
--------------------------------------------------------------------------------
1 | class <%= class_name %>Decorator < ApplicationDecorator
2 | end
3 |
--------------------------------------------------------------------------------
/lib/light/decorator/version.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | VERSION = '1.0.1'.freeze
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/spec/factories/post_tag.rb:
--------------------------------------------------------------------------------
1 | FactoryGirl.define do
2 | factory :post_tag do
3 | post
4 | tag
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/spec/factories/tag.rb:
--------------------------------------------------------------------------------
1 | FactoryGirl.define do
2 | factory :tag do
3 | name { FFaker::Job.title }
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/spec/internal/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | end
3 |
--------------------------------------------------------------------------------
/spec/internal/app/models/post_tag.rb:
--------------------------------------------------------------------------------
1 | class PostTag < ActiveRecord::Base
2 | belongs_to :post
3 | belongs_to :tag
4 | end
5 |
--------------------------------------------------------------------------------
/spec/internal/app/models/tag.rb:
--------------------------------------------------------------------------------
1 | class Tag < ActiveRecord::Base
2 | has_many :post_tags
3 | has_many :posts, through: :post_tags
4 | end
5 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'bundler/gem_tasks'
2 | require 'rspec/core/rake_task'
3 |
4 | RSpec::Core::RakeTask.new(:spec)
5 |
6 | task default: :spec
7 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 | set -vx
5 |
6 | bundle install
7 |
8 | # Do any other automated setup that you need to do here
9 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'bundler'
3 |
4 | Bundler.require :default, :development
5 |
6 | Combustion.initialize! :all
7 | run Combustion::Application
8 |
--------------------------------------------------------------------------------
/gemfiles/rails_4_0.gemfile:
--------------------------------------------------------------------------------
1 | # This file was generated by Appraisal
2 |
3 | source "https://rubygems.org"
4 |
5 | gem "rails", "4.0.13"
6 |
7 | gemspec :path => "../"
8 |
--------------------------------------------------------------------------------
/gemfiles/rails_4_1.gemfile:
--------------------------------------------------------------------------------
1 | # This file was generated by Appraisal
2 |
3 | source "https://rubygems.org"
4 |
5 | gem "rails", "4.1.15"
6 |
7 | gemspec :path => "../"
8 |
--------------------------------------------------------------------------------
/gemfiles/rails_4_2.gemfile:
--------------------------------------------------------------------------------
1 | # This file was generated by Appraisal
2 |
3 | source "https://rubygems.org"
4 |
5 | gem "rails", "4.2.6"
6 |
7 | gemspec :path => "../"
8 |
--------------------------------------------------------------------------------
/spec/internal/app/models/post.rb:
--------------------------------------------------------------------------------
1 | class Post < ActiveRecord::Base
2 | belongs_to :author
3 | has_many :post_tags
4 | has_many :tags, through: :post_tags
5 | end
6 |
--------------------------------------------------------------------------------
/gemfiles/rails_5_0.gemfile:
--------------------------------------------------------------------------------
1 | # This file was generated by Appraisal
2 |
3 | source "https://rubygems.org"
4 |
5 | gem "rails", "5.0.0.rc1"
6 |
7 | gemspec :path => "../"
8 |
--------------------------------------------------------------------------------
/lib/light/decorator/exceptions.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | class Error < StandardError; end
4 | class NotFound < Light::Decorator::Error; end
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/spec/factories/author.rb:
--------------------------------------------------------------------------------
1 | FactoryGirl.define do
2 | factory :author do
3 | first_name { FFaker::Name.first_name }
4 | last_name { FFaker::Name.last_name }
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/spec/internal/app/views/posts/show.html.erb:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 | <%= post.author.full_name %>
7 |
8 |
--------------------------------------------------------------------------------
/lib/generators/test_unit/decorator/templates/decorator_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class <%= class_name %>DecoratorTest < ActiveSupport::TestCase
4 | def test_decorate
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/lib/generators/rspec/decorator/templates/decorator_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe <%= class_name %>Decorator do
4 | pending "add some examples to (or delete) #{__FILE__}"
5 | end
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /Gemfile.lock
4 | /_yardoc/
5 | /coverage/
6 | /doc/
7 | /pkg/
8 | /spec/reports/
9 | /tmp/
10 | /.idea/
11 | /spec/internal/db/combustion_test.sqlite
12 | /*.gem
13 | /.ruby-version
14 |
--------------------------------------------------------------------------------
/spec/internal/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Light Decorator
6 |
7 |
8 | <%= yield %>
9 |
10 |
11 |
--------------------------------------------------------------------------------
/spec/internal/app/decorators/author_decorator.rb:
--------------------------------------------------------------------------------
1 | class AuthorDecorator < ApplicationDecorator
2 | def first_name
3 | object.first_name * 3
4 | end
5 |
6 | def full_name
7 | "#{object.first_name} #{object.last_name}"
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/.codeclimate.yml:
--------------------------------------------------------------------------------
1 | ---
2 | engines:
3 | duplication:
4 | enabled: true
5 | config:
6 | languages:
7 | - ruby
8 | fixme:
9 | enabled: true
10 | rubocop:
11 | enabled: true
12 | ratings:
13 | paths:
14 | - "**.rb"
15 | exclude_paths:
16 | - spec/
17 |
--------------------------------------------------------------------------------
/Appraisals:
--------------------------------------------------------------------------------
1 | appraise 'rails-4-0' do
2 | gem 'rails', '4.0.13'
3 | end
4 |
5 | appraise 'rails-4-1' do
6 | gem 'rails', '4.1.15'
7 | end
8 |
9 | appraise 'rails-4-2' do
10 | gem 'rails', '4.2.6'
11 | end
12 |
13 | appraise 'rails-5-0' do
14 | gem 'rails', '5.0.0.rc1'
15 | end
16 |
17 |
--------------------------------------------------------------------------------
/spec/internal/app/decorators/post_decorator.rb:
--------------------------------------------------------------------------------
1 | class PostDecorator < ApplicationDecorator
2 | def title_h1
3 | helpers.content_tag :h1, object.title
4 | end
5 |
6 | def title_h1_h
7 | h.content_tag :h1, object.title
8 | end
9 |
10 | def title_o
11 | o.title
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/spec/internal/app/controllers/posts_controller.rb:
--------------------------------------------------------------------------------
1 | class PostsController < ApplicationController
2 | def show
3 | render locals: { post: post.decorate }
4 | end
5 |
6 | private
7 |
8 | def post
9 | return @post if defined?(@post)
10 | @post = Post.find(params[:id])
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/spec/factories/post.rb:
--------------------------------------------------------------------------------
1 | FactoryGirl.define do
2 | factory :post do
3 | author
4 | title { FFaker::Job.title }
5 | body { FFaker::HipsterIpsum.phrase }
6 | published { true }
7 |
8 | after :create do |post|
9 | create_list(:post_tag, 3, post: post)
10 | end
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/lib/generators/light/decorator/install/templates/application_decorator.rb:
--------------------------------------------------------------------------------
1 | class ApplicationDecorator < Light::Decorator::Base
2 | # Use `object` or `o` to access object
3 | # Use `helpers` or `h` to access helpers
4 | #
5 | # Example:
6 | #
7 | # def created_at
8 | # h.content_tag :span, o.created_at.to_s(:long)
9 | # end
10 | end
11 |
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'bundler/setup'
4 | require 'light/decorator'
5 |
6 | # You can add fixtures and/or initialization code here to make experimenting
7 | # with your gem easier. You can also use a different console, if you like.
8 |
9 | # (If you use this, don't forget to add pry to your Gemfile!)
10 | # require "pry"
11 | # Pry.start
12 |
13 | require 'irb'
14 | IRB.start
15 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: ruby
3 |
4 | rvm:
5 | - 2.3.3
6 |
7 | before_install: gem install bundler -v 1.12.5
8 |
9 | gemfile:
10 | - gemfiles/rails_4_0.gemfile
11 | - gemfiles/rails_4_1.gemfile
12 | - gemfiles/rails_4_2.gemfile
13 | - gemfiles/rails_5_0.gemfile
14 |
15 | addons:
16 | code_climate:
17 | repo_token: f5d73d0bacb7771f55364c3af480bf0338cef449dcea216f8f73097acdb93642
18 |
--------------------------------------------------------------------------------
/lib/generators/rspec/decorator/decorator_generator.rb:
--------------------------------------------------------------------------------
1 | module RSpec
2 | module Generators
3 | class DecoratorGenerator < ::Rails::Generators::NamedBase
4 | source_root File.expand_path('../templates', __FILE__)
5 |
6 | def create_decorator_spec
7 | template 'decorator_spec.rb', File.join('spec/decorators', class_path, "#{file_name}_decorator_spec.rb")
8 | end
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/generators/test_unit/decorator/decorator_generator.rb:
--------------------------------------------------------------------------------
1 | module TestUnit
2 | module Generators
3 | class DecoratorGenerator < ::Rails::Generators::NamedBase
4 | source_root File.expand_path('../templates', __FILE__)
5 |
6 | def create_decorator_test
7 | template 'decorator_test.rb', File.join('test/decorators', class_path, "#{file_name}_decorator_test.rb")
8 | end
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/generators/light/decorator/install/install_generator.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | module Generators
4 | class InstallGenerator < ::Rails::Generators::Base
5 | source_root File.expand_path('../templates', __FILE__)
6 |
7 | def create_application_decorator
8 | template 'application_decorator.rb', File.join('app/decorators', 'application_decorator.rb')
9 | end
10 | end
11 | end
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/spec/integration/posts_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | RSpec.describe 'GET /posts/:id' do
4 | let(:post) { create(:post) }
5 |
6 | it 'check title h1' do
7 | visit "/posts/#{post.id}"
8 | expect(page.find('.post-header h1')).to have_content(post.title)
9 | end
10 |
11 | it 'check author full name' do
12 | visit "/posts/#{post.id}"
13 | expect(page).to have_content("#{post.author.first_name} #{post.author.last_name}")
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/lib/generators/rails/decorator/decorator_generator.rb:
--------------------------------------------------------------------------------
1 | module Rails
2 | module Generators
3 | class DecoratorGenerator < ::Rails::Generators::NamedBase
4 | source_root File.expand_path('../templates', __FILE__)
5 | check_class_collision suffix: 'Decorator'
6 |
7 | def create_decorator
8 | template 'decorator.rb', File.join('app/decorators', class_path, "#{file_name}_decorator.rb")
9 | end
10 |
11 | hook_for :test_framework
12 | end
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/lib/light/decorator/view_context.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | module ViewContext
4 | def view_context
5 | super.tap do |context|
6 | RequestStore[:light_decorator_context] = context
7 | end
8 | end
9 |
10 | def self.current
11 | RequestStore[:light_decorator_context] || fake_context
12 | end
13 |
14 | # @private
15 | def self.fake_context
16 | ActionView::Base.new
17 | end
18 | end
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/spec/internal/db/schema.rb:
--------------------------------------------------------------------------------
1 | ActiveRecord::Schema.define do
2 | create_table :authors do |t|
3 | t.string :first_name, null: false
4 | t.string :last_name, null: false
5 | end
6 |
7 | create_table :posts do |t|
8 | t.integer :author_id, null: false
9 | t.string :title
10 | t.text :body
11 | t.boolean :published, default: true
12 | end
13 |
14 | create_table :tags do |t|
15 | t.string :name
16 | end
17 |
18 | create_table :post_tags do |t|
19 | t.integer :post_id
20 | t.integer :tag_id
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/light/decorator.rb:
--------------------------------------------------------------------------------
1 | require 'rails'
2 | require 'active_record'
3 | require 'request_store'
4 |
5 | require 'light/decorator/version'
6 | require 'light/decorator/exceptions'
7 | require 'light/decorator/concerns/base'
8 | require 'light/decorator/concerns/relation'
9 | require 'light/decorator/concerns/associations/collection_proxy'
10 | require 'light/decorator/railtie'
11 | require 'light/decorator/view_context'
12 | require 'light/decorator/decorate'
13 |
14 | module Light
15 | module Decorator
16 | FORCE_DELEGATE = [:to_param].freeze
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'simplecov'
2 | SimpleCov.start
3 |
4 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5 | require 'light/decorator'
6 |
7 | require 'rubygems'
8 | require 'bundler/setup'
9 |
10 | require 'ffaker'
11 | require 'combustion'
12 | require 'factory_girl'
13 | require 'capybara/rspec'
14 |
15 | Combustion.initialize! :all
16 |
17 | require 'capybara/rails'
18 |
19 | RSpec.configure do |config|
20 | config.include FactoryGirl::Syntax::Methods
21 |
22 | config.before(:suite) do
23 | FactoryGirl.find_definitions
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/lib/generators/rails/hooks.rb:
--------------------------------------------------------------------------------
1 | require 'rails/generators'
2 | require 'rails/generators/rails/model/model_generator'
3 | require 'rails/generators/rails/resource/resource_generator'
4 | require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
5 |
6 | module Rails
7 | module Generators
8 | class ModelGenerator
9 | hook_for :decorator, default: true
10 | end
11 |
12 | class ResourceGenerator
13 | hook_for :decorator, default: true
14 | end
15 |
16 | class ScaffoldControllerGenerator
17 | hook_for :decorator, default: true
18 | end
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/spec/generators/install/install_generator_spec.rb:
--------------------------------------------------------------------------------
1 | require 'generator_spec'
2 | require 'generators/light/decorator/install/install_generator'
3 |
4 | RSpec.describe Light::Decorator::Generators::InstallGenerator, type: :generator do
5 | destination File.expand_path('../../../../tmp', __FILE__)
6 |
7 | before(:all) do
8 | prepare_destination
9 | run_generator
10 | end
11 |
12 | it 'creates application_decorator.rb' do
13 | assert_file 'app/decorators/application_decorator.rb' do |content|
14 | expect(content).to include('class ApplicationDecorator < Light::Decorator::Base')
15 | end
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/spec/generators/decorator/decorator_generator_spec.rb:
--------------------------------------------------------------------------------
1 | require 'generator_spec'
2 | require 'generators/rails/decorator/decorator_generator'
3 |
4 | RSpec.describe Rails::Generators::DecoratorGenerator, type: :generator do
5 | destination File.expand_path('../../../../tmp', __FILE__)
6 | arguments %w(User::Profile)
7 |
8 | before(:all) do
9 | prepare_destination
10 | run_generator
11 | end
12 |
13 | it 'creates user/profile_decorator.rb' do
14 | assert_file 'app/decorators/user/profile_decorator.rb' do |content|
15 | expect(content).to include('class User::ProfileDecorator < ApplicationDecorator')
16 | end
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Andrew Emelianenko
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/lib/light/decorator/railtie.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | class Railtie < Rails::Railtie
4 | config.after_initialize do |app|
5 | app.config.paths.add 'app/decorators', eager_load: true
6 | end
7 |
8 | initializer 'light.decorator.inject_orm' do
9 | ActiveSupport.on_load :active_record do
10 | ActiveRecord::Base.send(:include, ::Light::Decorator::Concerns::Base)
11 | ActiveRecord::Relation.send(:include, ::Light::Decorator::Concerns::Relation)
12 | ActiveRecord::Associations::CollectionProxy.send(
13 | :include, ::Light::Decorator::Concerns::Associations::CollectionProxy
14 | )
15 | end
16 | end
17 |
18 | initializer 'light.decorator.load_view_context' do
19 | [:action_controller, :action_mailer].each do |action_module|
20 | ActiveSupport.on_load action_module do
21 | include ::Light::Decorator::ViewContext
22 | end
23 | end
24 | end
25 |
26 | generators do |app|
27 | Rails::Generators.configure! app.config.generators
28 | Rails::Generators.hidden_namespaces.uniq!
29 |
30 | require 'generators/rails/hooks'
31 | end
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/lib/light/decorator/concerns/associations/collection_proxy.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | module Concerns
4 | module Associations
5 | module CollectionProxy
6 | extend ActiveSupport::Concern
7 |
8 | # Decorate ActiveRecord::Model associations
9 | #
10 | # @param [Hash] options (optional)
11 | # @return [ActiveRecord::Associations::CollectionProxy]
12 | def decorate(options = {})
13 | @decorated = true
14 |
15 | override_scope(options)
16 | override_load_target(options)
17 |
18 | self
19 | end
20 |
21 | # Check current association is decorated or not
22 | #
23 | # @return [Bool]
24 | def decorated?
25 | !@decorated.nil?
26 | end
27 |
28 | private
29 |
30 | def override_scope(options)
31 | @association.define_singleton_method :scope do
32 | super().decorate(options)
33 | end
34 | end
35 |
36 | def override_load_target(options)
37 | @association.define_singleton_method :load_target do
38 | super().map { |target| target.decorate(options) }
39 | end
40 | end
41 | end
42 | end
43 | end
44 | end
45 | end
46 |
--------------------------------------------------------------------------------
/light-decorator.gemspec:
--------------------------------------------------------------------------------
1 | # encoding: utf-8
2 | lib = File.expand_path('../lib', __FILE__)
3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4 | require 'light/decorator/version'
5 |
6 | Gem::Specification.new do |spec|
7 | spec.name = 'light-decorator'
8 | spec.version = Light::Decorator::VERSION
9 | spec.authors = ['Andrew Emelianenko']
10 | spec.email = ['emelianenko.web@gmail.com']
11 |
12 | spec.summary = 'Light pattern Decorator for Rails'
13 | spec.description = 'Light pattern Decorator for Rails from Light Ruby'
14 | spec.homepage = 'https://github.com/light-ruby/light-decorator'
15 | spec.license = 'MIT'
16 |
17 | spec.files = `git ls-files -z`
18 | .split("\x0")
19 | .reject { |f| f.match(%r{^(test|spec|features)/}) }
20 |
21 | spec.bindir = 'exe'
22 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23 | spec.require_paths = ['lib']
24 |
25 | spec.add_dependency 'rails', '>= 4.0.0'
26 | spec.add_dependency 'request_store', '>= 1.0.0'
27 |
28 | spec.add_development_dependency 'bundler', '~> 1.12'
29 | spec.add_development_dependency 'rake', '~> 10.0'
30 | spec.add_development_dependency 'sqlite3', '~> 1.3.11'
31 | spec.add_development_dependency 'combustion', '~> 0.5.4'
32 | spec.add_development_dependency 'appraisal', '~> 2.1'
33 | spec.add_development_dependency 'rspec', '~> 3.0'
34 | spec.add_development_dependency 'simplecov', '~> 0.11.2'
35 | spec.add_development_dependency 'capybara', '~> 2.7.0'
36 | spec.add_development_dependency 'factory_girl', '~> 4.0'
37 | spec.add_development_dependency 'ffaker', '~> 2.2.0'
38 | spec.add_development_dependency 'generator_spec', '~> 0.9.3'
39 | spec.add_development_dependency 'codeclimate-test-reporter'
40 | end
41 |
--------------------------------------------------------------------------------
/lib/light/decorator/concerns/relation.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | module Concerns
4 | module Relation
5 | extend ActiveSupport::Concern
6 |
7 | # Decorate ActiveRecord::Relation
8 | #
9 | # @param [Hash] options
10 | # @return [ActiveRecord::Relation] decorated collection
11 | def decorate(options = {})
12 | @decorated = true
13 |
14 | override_exec_queries(options)
15 |
16 | self
17 | end
18 |
19 | # Check current ActiveRecord::Relation is decorated or not
20 | #
21 | # @return [Bool]
22 | def decorated?
23 | !@decorated.nil?
24 | end
25 |
26 | private
27 |
28 | def override_exec_queries(options)
29 | define_singleton_method :exec_queries do
30 | super()
31 |
32 | @records = @records.map do |record|
33 | decorate_associations(record, options.reverse_merge(soft: true))
34 | record.decorate(options)
35 | end
36 | end
37 | end
38 |
39 | def decorate_associations(record, options)
40 | record.instance_variable_get(:@association_cache).each do |_, association|
41 | next if association.inversed || association.target.blank?
42 |
43 | if association.target.is_a?(Array)
44 | targets = association.target.map do |target|
45 | decorate_associations(target, options)
46 | target.decorate(options)
47 | end
48 |
49 | association.instance_variable_set(:@target, targets)
50 | else
51 | decorate_associations(association.target, options)
52 | association.instance_variable_set(:@target, association.target.decorate(options))
53 | end
54 | end
55 | end
56 | end
57 | end
58 | end
59 | end
60 |
--------------------------------------------------------------------------------
/lib/light/decorator/concerns/base.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | module Concerns
4 | module Base
5 | extend ActiveSupport::Concern
6 |
7 | # Decorate ActiveRecord::Model
8 | #
9 | # @param [Hash] options (optional)
10 | # @return [Object] decorator or self
11 | def decorate(options = {})
12 | return self if decorated?
13 |
14 | klass = decorator_class(options)
15 | klass.decorate(self, options)
16 | rescue Light::Decorator::NotFound => e
17 | raise e unless options[:soft]
18 | self
19 | end
20 |
21 | # Check current ActiveRecord::Model is decorated or not
22 | #
23 | # @return [Bool]
24 | def decorated?
25 | false
26 | end
27 |
28 | def ==(other)
29 | super || other.respond_to?(:object) && self == other.object
30 | end
31 |
32 | def eql?(other)
33 | super || other.respond_to?(:object) && eql?(other.object)
34 | end
35 |
36 | private
37 |
38 | def decorator_class(options)
39 | with = options.delete(:with)
40 | return "#{self.class}Decorator".constantize unless with
41 |
42 | with = with.constantize unless with.is_a?(Class)
43 | with
44 | rescue NameError
45 | raise Light::Decorator::NotFound, "Decorator#{with ? " #{with}" : ''} for #{self.class} not found"
46 | end
47 |
48 | module ClassMethods
49 | # Decorate all scope for ActiveRecord::Model
50 | #
51 | # @param [Hash] options (optional)
52 | # @return [ActiveRecord::Relation]
53 | def decorate(options = {})
54 | all.decorate(options)
55 | end
56 |
57 | # Find ActiveRecord::Model and decorate it
58 | #
59 | # @param [Integer] id
60 | # @param [Hash] options (optional)
61 | # @return [ActiveRecord::Model]
62 | def find_and_decorate(id, options = {})
63 | find(id).decorate(options)
64 | end
65 | end
66 | end
67 | end
68 | end
69 | end
70 |
--------------------------------------------------------------------------------
/lib/light/decorator/decorate.rb:
--------------------------------------------------------------------------------
1 | module Light
2 | module Decorator
3 | class Base
4 | # @return original object
5 | attr_reader :object
6 |
7 | # Decorate the object
8 | #
9 | # @param [Object] object for decoration
10 | # @param [Hash] options
11 | #
12 | # @return [Object] decorated object
13 | def initialize(object, options = {})
14 | @object = object
15 | @options = options
16 |
17 | delegate_methods
18 | decorate_associations
19 | end
20 |
21 | # Check current ActiveRecord::Model is decorated or not
22 | #
23 | # @return [Bool]
24 | def decorated?
25 | true
26 | end
27 |
28 | # Current view scope
29 | #
30 | # @return [ActionView::Base]
31 | def helpers
32 | return @helpers if defined?(@helpers)
33 | @helpers = Light::Decorator::ViewContext.current
34 | end
35 |
36 | def ==(other)
37 | super || object == other
38 | end
39 |
40 | def eql?(other)
41 | super || object.eql?(other)
42 | end
43 |
44 | def is_a?(klass)
45 | super || object.is_a?(klass)
46 | end
47 |
48 | def kind_of?(klass)
49 | super || object.kind_of?(klass)
50 | end
51 |
52 | class << self
53 | alias decorate new
54 | end
55 |
56 | alias o object
57 | alias h helpers
58 |
59 | private
60 |
61 | def delegate_methods
62 | # It's more faster than using Forwardable
63 | (object.public_methods - methods + Light::Decorator::FORCE_DELEGATE).each do |method|
64 | define_singleton_method method do |*args, &block|
65 | object.__send__(method, *args, &block)
66 | end
67 | end
68 | end
69 |
70 | def decorate_associations
71 | object.class.reflect_on_all_associations.map(&:name).each do |reflection_name|
72 | define_singleton_method reflection_name do
73 | reflection = object.public_send(reflection_name)
74 | reflection.decorate(@options.reverse_merge(soft: true)) if reflection
75 | end
76 | end
77 | end
78 | end
79 | end
80 | end
81 |
--------------------------------------------------------------------------------
/spec/decorators/post_decorator_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | RSpec.describe PostDecorator do
4 | let(:post) { create(:post) }
5 | let(:decorated_post) { post.decorate }
6 |
7 | it 'decorator exist' do
8 | expect { PostDecorator }.to_not raise_error
9 | end
10 |
11 | it 'decorate post' do
12 | expect(post).to_not be_decorated
13 | expect(post.decorate).to be_decorated
14 | end
15 |
16 | it 'decorate post via method' do
17 | expect(post).to_not be_decorated
18 | expect(post.decorate).to be_decorated
19 | end
20 |
21 | it 'decorate post via class' do
22 | expect(post).to_not be_decorated
23 |
24 | expect(PostDecorator.new(post)).to be_decorated
25 | expect(PostDecorator.decorate(post)).to be_decorated
26 | end
27 |
28 | it 'title h1 method' do
29 | expect(decorated_post.title_h1).to eql("#{post.title}
".html_safe)
30 | end
31 |
32 | it 'h alias of helpers' do
33 | expect(decorated_post.title_h1_h).to eql("#{post.title}
".html_safe)
34 | end
35 |
36 | it 'o alias of object' do
37 | expect(decorated_post.title_o).to eql(post.title)
38 | end
39 |
40 | it 'decorate belongs to association' do
41 | expect(decorated_post.author).to be_decorated
42 | end
43 |
44 | it 'decorate has many through association' do
45 | expect(decorated_post.tags.take).to be_decorated
46 |
47 | decorated_post.tags.each do |tag|
48 | expect(tag).to be_decorated
49 | end
50 |
51 | decorated_post.tags.where.not(id: nil).each do |tag|
52 | expect(tag).to be_decorated
53 | end
54 |
55 | decorated_post.tags.limit(2).each do |tag|
56 | expect(tag).to be_decorated
57 | end
58 | end
59 |
60 | it 'find and decorate' do
61 | expect(Post.find_and_decorate(post.id)).to be_decorated
62 | end
63 |
64 | it '==' do
65 | expect(decorated_post == post).to be(true)
66 | expect(post == decorated_post).to be(true)
67 |
68 | # rubocop:disable Lint/UselessComparison
69 | expect(decorated_post == decorated_post).to be(true)
70 | end
71 |
72 | it 'eql' do
73 | expect(decorated_post.eql?(post)).to be(true)
74 | expect(post.eql?(decorated_post)).to be(true)
75 | expect(decorated_post.eql?(decorated_post)).to be(true)
76 | end
77 |
78 | it 'equal' do
79 | expect(decorated_post.equal?(post)).to be(false)
80 | expect(post.equal?(decorated_post)).to be(false)
81 | end
82 | end
83 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 |
2 | # Contributor Code of Conduct
3 |
4 | As contributors and maintainers of this project, and in the interest of
5 | fostering an open and welcoming community, we pledge to respect all people who
6 | contribute through reporting issues, posting feature requests, updating
7 | documentation, submitting pull requests or patches, and other activities.
8 |
9 | We are committed to making participation in this project a harassment-free
10 | experience for everyone, regardless of level of experience, gender, gender
11 | identity and expression, sexual orientation, disability, personal appearance,
12 | body size, race, ethnicity, age, religion, or nationality.
13 |
14 | Examples of unacceptable behavior by participants include:
15 |
16 | * The use of sexualized language or imagery
17 | * Personal attacks
18 | * Trolling or insulting/derogatory comments
19 | * Public or private harassment
20 | * Publishing other's private information, such as physical or electronic
21 | addresses, without explicit permission
22 | * Other unethical or unprofessional conduct
23 |
24 | Project maintainers have the right and responsibility to remove, edit, or
25 | reject comments, commits, code, wiki edits, issues, and other contributions
26 | that are not aligned to this Code of Conduct, or to ban temporarily or
27 | permanently any contributor for other behaviors that they deem inappropriate,
28 | threatening, offensive, or harmful.
29 |
30 | By adopting this Code of Conduct, project maintainers commit themselves to
31 | fairly and consistently applying these principles to every aspect of managing
32 | this project. Project maintainers who do not follow or enforce the Code of
33 | Conduct may be permanently removed from the project team.
34 |
35 | This code of conduct applies both within project spaces and in public spaces
36 | when an individual is representing the project or its community.
37 |
38 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
39 | reported by contacting a project maintainer at emelianenko.web@gmail.com. All
40 | complaints will be reviewed and investigated and will result in a response that
41 | is deemed necessary and appropriate to the circumstances. Maintainers are
42 | obligated to maintain confidentiality with regard to the reporter of an
43 | incident.
44 |
45 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
46 | version 1.3.0, available at
47 | [http://contributor-covenant.org/version/1/3/0/][version]
48 |
49 | [homepage]: http://contributor-covenant.org
50 | [version]: http://contributor-covenant.org/version/1/3/0/
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Light Decorator
2 |
3 | [](https://travis-ci.org/light-ruby/light-decorator)
4 | [](https://codeclimate.com/github/light-ruby/light-decorator)
5 | [](https://codeclimate.com/github/light-ruby/light-decorator/coverage)
6 |
7 | Easiest and fast way to decorate Ruby on Rails models. Compatible with Rails 5.0 and 4.2, 4.1, 4.0.
8 |
9 | Decorator Pattern – What is it? Check it here:
10 | - [Wikipedia](https://en.wikipedia.org/wiki/Decorator_pattern)
11 | - [Thoughtbot](https://robots.thoughtbot.com/evaluating-alternative-decorator-implementations-in)
12 |
13 | ## Installation
14 |
15 | Add this line to your application's Gemfile:
16 |
17 | ```ruby
18 | gem 'light-decorator', '~> 1.0.1'
19 | ```
20 |
21 | Create base class `ApplicationDecorator` in folder `app/decorators/application_decorator.rb`
22 |
23 | ```
24 | rails g light:decorator:install
25 | ```
26 |
27 | ## Usage
28 |
29 | Create decorator for your model. For example we will use the `User` model.
30 | We can manually create file:
31 |
32 | ```ruby
33 | # app/decorators/user_decorator.rb
34 | class UserDecorator < ApplicationDecorator
35 | def full_name
36 | "#{object.first_name} #{object.last_name}"
37 | end
38 | end
39 | ```
40 |
41 | Or we can just use command to create this file:
42 |
43 | ```
44 | rails g decorator User
45 | ```
46 |
47 | Decorate your model in controller or anywhere.
48 |
49 | ```ruby
50 | # Single record
51 | User.find(params[:id]).decorate
52 | User.find_and_decorate(params[:id])
53 | User.decorate.find(params[:id])
54 |
55 | # Collection
56 | User.all.decorate
57 | User.decorate
58 | User.limit(10).decorate
59 | User.decorate.limit(10)
60 |
61 | # Options
62 | User.find_and_decorate(params[:id], with: AnotherUserDecorator)
63 |
64 | # Associations will be decorated automatically
65 | user = User.find_and_decorate(params[:id])
66 | user.decorated? # true
67 | user.comments.decorated? # true
68 | user.comments.first.decorated? # true
69 | ```
70 |
71 | Example of Decorator
72 | ```ruby
73 | class UserDecorator < ApplicationDecorator
74 | def full_name
75 | "#{object.first_name} #{object.last_name}"
76 | # or
77 | "#{o.first_name} #{o.last_name}"
78 | end
79 |
80 | def full_name_link
81 | helpers.link_to full_name, user_path(object)
82 | # or
83 | h.link_to full_name, user_path(o)
84 | end
85 | end
86 | ```
87 |
88 | ## Next steps
89 |
90 | - [x] Create installation generator
91 | - [x] Create decorator generator
92 | - [ ] Create configuration file
93 |
94 | ## Contributing
95 |
96 | Bug reports and pull requests are welcome on GitHub at https://github.com/light-ruby/light-decorator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
97 |
98 | ## License
99 |
100 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
101 |
102 |
--------------------------------------------------------------------------------
/spec/decorators/author_decorator_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | RSpec.describe AuthorDecorator do
4 | let(:author) { create(:author) }
5 | let(:decorated_author) { author.decorate }
6 |
7 | it 'decorator exist' do
8 | expect { AuthorDecorator }.to_not raise_error
9 | end
10 |
11 | it 'decorate author via method' do
12 | author.posts.count
13 | expect(author).to_not be_decorated
14 | expect(author.decorate).to be_decorated
15 | expect(author.decorate(with: AuthorDecorator)).to be_decorated
16 | end
17 |
18 | it 'decorate author via class' do
19 | expect(author).to_not be_decorated
20 |
21 | expect(AuthorDecorator.new(author)).to be_decorated
22 | expect(AuthorDecorator.decorate(author)).to be_decorated
23 | end
24 |
25 | it 'decoration with not existed decorator' do
26 | expect { author.decorate(with: 'SuperDecorator') }.to raise_error Light::Decorator::NotFound
27 | end
28 |
29 | it 'soft decoration' do
30 | expect(author.decorate(soft: true, with: 'SuperDecorator')).to eql(author)
31 | end
32 |
33 | it 'override model methods' do
34 | expect(author.decorate.first_name).to eql(author.first_name * 3)
35 | end
36 |
37 | it 'decorate collection' do
38 | expect(Author.all).to_not be_decorated
39 | expect(Author.decorate).to be_decorated
40 |
41 | create(:author)
42 | expect(Author.all.take).to_not be_decorated
43 | expect(Author.decorate.take).to be_decorated
44 | end
45 |
46 | it 'full name method' do
47 | expect(decorated_author.full_name).to eql("#{author.first_name} #{author.last_name}")
48 | end
49 |
50 | it 'full name method for collection' do
51 | 5.times { create(:author) }
52 |
53 | authors = Author.all
54 | authors.decorate.each do |author|
55 | expect(author.full_name).to eql("#{author.object.first_name} #{author.object.last_name}")
56 | end
57 | end
58 |
59 | it 'decorate has many association' do
60 | 5.times { create(:post, author: author) }
61 |
62 | expect(author.reload.decorate.posts).to be_decorated
63 | expect(author.reload.decorate.posts.take).to be_decorated
64 |
65 | author.decorate.posts.each do |post|
66 | expect(post).to be_decorated
67 | end
68 |
69 | author.decorate.posts.where(published: true).each do |post|
70 | expect(post).to be_decorated
71 | end
72 |
73 | author.decorate.posts.limit(3).each do |post|
74 | expect(post).to be_decorated
75 | end
76 | end
77 |
78 | it 'decorates eager loading' do
79 | 3.times do
80 | author = create(:author)
81 | 3.times { create(:post, author: author) }
82 | end
83 |
84 | Author.includes(:posts).decorate.each do |author|
85 | expect(author).to be_decorated
86 |
87 | author.posts.each do |post|
88 | expect(post).to be_decorated
89 | end
90 | end
91 |
92 | Author.references(:posts).decorate.each do |author|
93 | expect(author).to be_decorated
94 |
95 | author.posts.each do |post|
96 | expect(post).to be_decorated
97 | end
98 | end
99 | end
100 |
101 | it 'decorates deep eager loading' do
102 | Author.includes(posts: :tags).decorate.each do |author|
103 | expect(author).to be_decorated
104 |
105 | author.posts.each do |post|
106 | expect(post).to be_decorated
107 |
108 | post.tags.each do |tag|
109 | expect(tag).to be_decorated
110 | end
111 | end
112 | end
113 | end
114 |
115 | it 'is_a?' do
116 | expect(decorated_author).to be_a(Author)
117 | expect(decorated_author).to be_a(AuthorDecorator)
118 | end
119 | end
120 |
--------------------------------------------------------------------------------
/gemfiles/rails_4_0.gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: ..
3 | specs:
4 | light-decorator (1.0.1)
5 | rails (>= 4.0.0)
6 | request_store (>= 1.0.0)
7 |
8 | GEM
9 | remote: https://rubygems.org/
10 | specs:
11 | actionmailer (4.0.13)
12 | actionpack (= 4.0.13)
13 | mail (~> 2.5, >= 2.5.4)
14 | actionpack (4.0.13)
15 | activesupport (= 4.0.13)
16 | builder (~> 3.1.0)
17 | erubis (~> 2.7.0)
18 | rack (~> 1.5.2)
19 | rack-test (~> 0.6.2)
20 | activemodel (4.0.13)
21 | activesupport (= 4.0.13)
22 | builder (~> 3.1.0)
23 | activerecord (4.0.13)
24 | activemodel (= 4.0.13)
25 | activerecord-deprecated_finders (~> 1.0.2)
26 | activesupport (= 4.0.13)
27 | arel (~> 4.0.0)
28 | activerecord-deprecated_finders (1.0.4)
29 | activesupport (4.0.13)
30 | i18n (~> 0.6, >= 0.6.9)
31 | minitest (~> 4.2)
32 | multi_json (~> 1.3)
33 | thread_safe (~> 0.1)
34 | tzinfo (~> 0.3.37)
35 | addressable (2.4.0)
36 | appraisal (2.1.0)
37 | bundler
38 | rake
39 | thor (>= 0.14.0)
40 | arel (4.0.2)
41 | builder (3.1.4)
42 | capybara (2.7.1)
43 | addressable
44 | mime-types (>= 1.16)
45 | nokogiri (>= 1.3.3)
46 | rack (>= 1.0.0)
47 | rack-test (>= 0.5.4)
48 | xpath (~> 2.0)
49 | codeclimate-test-reporter (0.5.1)
50 | simplecov (>= 0.7.1, < 1.0.0)
51 | combustion (0.5.4)
52 | activesupport (>= 3.0.0)
53 | railties (>= 3.0.0)
54 | thor (>= 0.14.6)
55 | concurrent-ruby (1.0.2)
56 | diff-lcs (1.2.5)
57 | docile (1.1.5)
58 | erubis (2.7.0)
59 | factory_girl (4.7.0)
60 | activesupport (>= 3.0.0)
61 | ffaker (2.2.0)
62 | generator_spec (0.9.3)
63 | activesupport (>= 3.0.0)
64 | railties (>= 3.0.0)
65 | i18n (0.7.0)
66 | json (1.8.6)
67 | mail (2.6.4)
68 | mime-types (>= 1.16, < 4)
69 | mime-types (3.1)
70 | mime-types-data (~> 3.2015)
71 | mime-types-data (3.2016.0521)
72 | mini_portile2 (2.1.0)
73 | minitest (4.7.5)
74 | multi_json (1.12.1)
75 | nokogiri (1.6.8)
76 | mini_portile2 (~> 2.1.0)
77 | pkg-config (~> 1.1.7)
78 | pkg-config (1.1.7)
79 | rack (1.5.5)
80 | rack-test (0.6.3)
81 | rack (>= 1.0)
82 | rails (4.0.13)
83 | actionmailer (= 4.0.13)
84 | actionpack (= 4.0.13)
85 | activerecord (= 4.0.13)
86 | activesupport (= 4.0.13)
87 | bundler (>= 1.3.0, < 2.0)
88 | railties (= 4.0.13)
89 | sprockets-rails (~> 2.0)
90 | railties (4.0.13)
91 | actionpack (= 4.0.13)
92 | activesupport (= 4.0.13)
93 | rake (>= 0.8.7)
94 | thor (>= 0.18.1, < 2.0)
95 | rake (10.5.0)
96 | request_store (1.3.2)
97 | rspec (3.4.0)
98 | rspec-core (~> 3.4.0)
99 | rspec-expectations (~> 3.4.0)
100 | rspec-mocks (~> 3.4.0)
101 | rspec-core (3.4.4)
102 | rspec-support (~> 3.4.0)
103 | rspec-expectations (3.4.0)
104 | diff-lcs (>= 1.2.0, < 2.0)
105 | rspec-support (~> 3.4.0)
106 | rspec-mocks (3.4.1)
107 | diff-lcs (>= 1.2.0, < 2.0)
108 | rspec-support (~> 3.4.0)
109 | rspec-support (3.4.1)
110 | simplecov (0.11.2)
111 | docile (~> 1.1.0)
112 | json (~> 1.8)
113 | simplecov-html (~> 0.10.0)
114 | simplecov-html (0.10.0)
115 | sprockets (3.6.0)
116 | concurrent-ruby (~> 1.0)
117 | rack (> 1, < 3)
118 | sprockets-rails (2.3.3)
119 | actionpack (>= 3.0)
120 | activesupport (>= 3.0)
121 | sprockets (>= 2.8, < 4.0)
122 | sqlite3 (1.3.11)
123 | thor (0.19.1)
124 | thread_safe (0.3.5)
125 | tzinfo (0.3.49)
126 | xpath (2.0.0)
127 | nokogiri (~> 1.3)
128 |
129 | PLATFORMS
130 | ruby
131 |
132 | DEPENDENCIES
133 | appraisal (~> 2.1)
134 | bundler (~> 1.12)
135 | capybara (~> 2.7.0)
136 | codeclimate-test-reporter
137 | combustion (~> 0.5.4)
138 | factory_girl (~> 4.0)
139 | ffaker (~> 2.2.0)
140 | generator_spec (~> 0.9.3)
141 | light-decorator!
142 | rails (= 4.0.13)
143 | rake (~> 10.0)
144 | rspec (~> 3.0)
145 | simplecov (~> 0.11.2)
146 | sqlite3 (~> 1.3.11)
147 |
148 | BUNDLED WITH
149 | 1.14.4
150 |
--------------------------------------------------------------------------------
/gemfiles/rails_4_1.gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: ..
3 | specs:
4 | light-decorator (1.0.1)
5 | rails (>= 4.0.0)
6 | request_store (>= 1.0.0)
7 |
8 | GEM
9 | remote: https://rubygems.org/
10 | specs:
11 | actionmailer (4.1.15)
12 | actionpack (= 4.1.15)
13 | actionview (= 4.1.15)
14 | mail (~> 2.5, >= 2.5.4)
15 | actionpack (4.1.15)
16 | actionview (= 4.1.15)
17 | activesupport (= 4.1.15)
18 | rack (~> 1.5.2)
19 | rack-test (~> 0.6.2)
20 | actionview (4.1.15)
21 | activesupport (= 4.1.15)
22 | builder (~> 3.1)
23 | erubis (~> 2.7.0)
24 | activemodel (4.1.15)
25 | activesupport (= 4.1.15)
26 | builder (~> 3.1)
27 | activerecord (4.1.15)
28 | activemodel (= 4.1.15)
29 | activesupport (= 4.1.15)
30 | arel (~> 5.0.0)
31 | activesupport (4.1.15)
32 | i18n (~> 0.6, >= 0.6.9)
33 | json (~> 1.7, >= 1.7.7)
34 | minitest (~> 5.1)
35 | thread_safe (~> 0.1)
36 | tzinfo (~> 1.1)
37 | addressable (2.4.0)
38 | appraisal (2.1.0)
39 | bundler
40 | rake
41 | thor (>= 0.14.0)
42 | arel (5.0.1.20140414130214)
43 | builder (3.2.2)
44 | capybara (2.7.1)
45 | addressable
46 | mime-types (>= 1.16)
47 | nokogiri (>= 1.3.3)
48 | rack (>= 1.0.0)
49 | rack-test (>= 0.5.4)
50 | xpath (~> 2.0)
51 | codeclimate-test-reporter (0.5.1)
52 | simplecov (>= 0.7.1, < 1.0.0)
53 | combustion (0.5.4)
54 | activesupport (>= 3.0.0)
55 | railties (>= 3.0.0)
56 | thor (>= 0.14.6)
57 | concurrent-ruby (1.0.2)
58 | diff-lcs (1.2.5)
59 | docile (1.1.5)
60 | erubis (2.7.0)
61 | factory_girl (4.7.0)
62 | activesupport (>= 3.0.0)
63 | ffaker (2.2.0)
64 | generator_spec (0.9.3)
65 | activesupport (>= 3.0.0)
66 | railties (>= 3.0.0)
67 | i18n (0.7.0)
68 | json (1.8.6)
69 | mail (2.6.4)
70 | mime-types (>= 1.16, < 4)
71 | mime-types (3.1)
72 | mime-types-data (~> 3.2015)
73 | mime-types-data (3.2016.0521)
74 | mini_portile2 (2.1.0)
75 | minitest (5.9.0)
76 | nokogiri (1.6.8)
77 | mini_portile2 (~> 2.1.0)
78 | pkg-config (~> 1.1.7)
79 | pkg-config (1.1.7)
80 | rack (1.5.5)
81 | rack-test (0.6.3)
82 | rack (>= 1.0)
83 | rails (4.1.15)
84 | actionmailer (= 4.1.15)
85 | actionpack (= 4.1.15)
86 | actionview (= 4.1.15)
87 | activemodel (= 4.1.15)
88 | activerecord (= 4.1.15)
89 | activesupport (= 4.1.15)
90 | bundler (>= 1.3.0, < 2.0)
91 | railties (= 4.1.15)
92 | sprockets-rails (~> 2.0)
93 | railties (4.1.15)
94 | actionpack (= 4.1.15)
95 | activesupport (= 4.1.15)
96 | rake (>= 0.8.7)
97 | thor (>= 0.18.1, < 2.0)
98 | rake (10.5.0)
99 | request_store (1.3.2)
100 | rspec (3.4.0)
101 | rspec-core (~> 3.4.0)
102 | rspec-expectations (~> 3.4.0)
103 | rspec-mocks (~> 3.4.0)
104 | rspec-core (3.4.4)
105 | rspec-support (~> 3.4.0)
106 | rspec-expectations (3.4.0)
107 | diff-lcs (>= 1.2.0, < 2.0)
108 | rspec-support (~> 3.4.0)
109 | rspec-mocks (3.4.1)
110 | diff-lcs (>= 1.2.0, < 2.0)
111 | rspec-support (~> 3.4.0)
112 | rspec-support (3.4.1)
113 | simplecov (0.11.2)
114 | docile (~> 1.1.0)
115 | json (~> 1.8)
116 | simplecov-html (~> 0.10.0)
117 | simplecov-html (0.10.0)
118 | sprockets (3.6.0)
119 | concurrent-ruby (~> 1.0)
120 | rack (> 1, < 3)
121 | sprockets-rails (2.3.3)
122 | actionpack (>= 3.0)
123 | activesupport (>= 3.0)
124 | sprockets (>= 2.8, < 4.0)
125 | sqlite3 (1.3.11)
126 | thor (0.19.1)
127 | thread_safe (0.3.5)
128 | tzinfo (1.2.2)
129 | thread_safe (~> 0.1)
130 | xpath (2.0.0)
131 | nokogiri (~> 1.3)
132 |
133 | PLATFORMS
134 | ruby
135 |
136 | DEPENDENCIES
137 | appraisal (~> 2.1)
138 | bundler (~> 1.12)
139 | capybara (~> 2.7.0)
140 | codeclimate-test-reporter
141 | combustion (~> 0.5.4)
142 | factory_girl (~> 4.0)
143 | ffaker (~> 2.2.0)
144 | generator_spec (~> 0.9.3)
145 | light-decorator!
146 | rails (= 4.1.15)
147 | rake (~> 10.0)
148 | rspec (~> 3.0)
149 | simplecov (~> 0.11.2)
150 | sqlite3 (~> 1.3.11)
151 |
152 | BUNDLED WITH
153 | 1.14.4
154 |
--------------------------------------------------------------------------------
/gemfiles/rails_4_2.gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: ..
3 | specs:
4 | light-decorator (1.0.1)
5 | rails (>= 4.0.0)
6 | request_store (>= 1.0.0)
7 |
8 | GEM
9 | remote: https://rubygems.org/
10 | specs:
11 | actionmailer (4.2.6)
12 | actionpack (= 4.2.6)
13 | actionview (= 4.2.6)
14 | activejob (= 4.2.6)
15 | mail (~> 2.5, >= 2.5.4)
16 | rails-dom-testing (~> 1.0, >= 1.0.5)
17 | actionpack (4.2.6)
18 | actionview (= 4.2.6)
19 | activesupport (= 4.2.6)
20 | rack (~> 1.6)
21 | rack-test (~> 0.6.2)
22 | rails-dom-testing (~> 1.0, >= 1.0.5)
23 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
24 | actionview (4.2.6)
25 | activesupport (= 4.2.6)
26 | builder (~> 3.1)
27 | erubis (~> 2.7.0)
28 | rails-dom-testing (~> 1.0, >= 1.0.5)
29 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
30 | activejob (4.2.6)
31 | activesupport (= 4.2.6)
32 | globalid (>= 0.3.0)
33 | activemodel (4.2.6)
34 | activesupport (= 4.2.6)
35 | builder (~> 3.1)
36 | activerecord (4.2.6)
37 | activemodel (= 4.2.6)
38 | activesupport (= 4.2.6)
39 | arel (~> 6.0)
40 | activesupport (4.2.6)
41 | i18n (~> 0.7)
42 | json (~> 1.7, >= 1.7.7)
43 | minitest (~> 5.1)
44 | thread_safe (~> 0.3, >= 0.3.4)
45 | tzinfo (~> 1.1)
46 | addressable (2.4.0)
47 | appraisal (2.1.0)
48 | bundler
49 | rake
50 | thor (>= 0.14.0)
51 | arel (6.0.3)
52 | builder (3.2.2)
53 | capybara (2.7.1)
54 | addressable
55 | mime-types (>= 1.16)
56 | nokogiri (>= 1.3.3)
57 | rack (>= 1.0.0)
58 | rack-test (>= 0.5.4)
59 | xpath (~> 2.0)
60 | codeclimate-test-reporter (0.5.1)
61 | simplecov (>= 0.7.1, < 1.0.0)
62 | combustion (0.5.4)
63 | activesupport (>= 3.0.0)
64 | railties (>= 3.0.0)
65 | thor (>= 0.14.6)
66 | concurrent-ruby (1.0.2)
67 | diff-lcs (1.2.5)
68 | docile (1.1.5)
69 | erubis (2.7.0)
70 | factory_girl (4.7.0)
71 | activesupport (>= 3.0.0)
72 | ffaker (2.2.0)
73 | generator_spec (0.9.3)
74 | activesupport (>= 3.0.0)
75 | railties (>= 3.0.0)
76 | globalid (0.3.6)
77 | activesupport (>= 4.1.0)
78 | i18n (0.7.0)
79 | json (1.8.6)
80 | loofah (2.0.3)
81 | nokogiri (>= 1.5.9)
82 | mail (2.6.4)
83 | mime-types (>= 1.16, < 4)
84 | mime-types (3.1)
85 | mime-types-data (~> 3.2015)
86 | mime-types-data (3.2016.0521)
87 | mini_portile2 (2.1.0)
88 | minitest (5.9.0)
89 | nokogiri (1.6.8)
90 | mini_portile2 (~> 2.1.0)
91 | pkg-config (~> 1.1.7)
92 | pkg-config (1.1.7)
93 | rack (1.6.4)
94 | rack-test (0.6.3)
95 | rack (>= 1.0)
96 | rails (4.2.6)
97 | actionmailer (= 4.2.6)
98 | actionpack (= 4.2.6)
99 | actionview (= 4.2.6)
100 | activejob (= 4.2.6)
101 | activemodel (= 4.2.6)
102 | activerecord (= 4.2.6)
103 | activesupport (= 4.2.6)
104 | bundler (>= 1.3.0, < 2.0)
105 | railties (= 4.2.6)
106 | sprockets-rails
107 | rails-deprecated_sanitizer (1.0.3)
108 | activesupport (>= 4.2.0.alpha)
109 | rails-dom-testing (1.0.7)
110 | activesupport (>= 4.2.0.beta, < 5.0)
111 | nokogiri (~> 1.6.0)
112 | rails-deprecated_sanitizer (>= 1.0.1)
113 | rails-html-sanitizer (1.0.3)
114 | loofah (~> 2.0)
115 | railties (4.2.6)
116 | actionpack (= 4.2.6)
117 | activesupport (= 4.2.6)
118 | rake (>= 0.8.7)
119 | thor (>= 0.18.1, < 2.0)
120 | rake (10.5.0)
121 | request_store (1.3.2)
122 | rspec (3.4.0)
123 | rspec-core (~> 3.4.0)
124 | rspec-expectations (~> 3.4.0)
125 | rspec-mocks (~> 3.4.0)
126 | rspec-core (3.4.4)
127 | rspec-support (~> 3.4.0)
128 | rspec-expectations (3.4.0)
129 | diff-lcs (>= 1.2.0, < 2.0)
130 | rspec-support (~> 3.4.0)
131 | rspec-mocks (3.4.1)
132 | diff-lcs (>= 1.2.0, < 2.0)
133 | rspec-support (~> 3.4.0)
134 | rspec-support (3.4.1)
135 | simplecov (0.11.2)
136 | docile (~> 1.1.0)
137 | json (~> 1.8)
138 | simplecov-html (~> 0.10.0)
139 | simplecov-html (0.10.0)
140 | sprockets (3.6.0)
141 | concurrent-ruby (~> 1.0)
142 | rack (> 1, < 3)
143 | sprockets-rails (3.0.4)
144 | actionpack (>= 4.0)
145 | activesupport (>= 4.0)
146 | sprockets (>= 3.0.0)
147 | sqlite3 (1.3.11)
148 | thor (0.19.1)
149 | thread_safe (0.3.5)
150 | tzinfo (1.2.2)
151 | thread_safe (~> 0.1)
152 | xpath (2.0.0)
153 | nokogiri (~> 1.3)
154 |
155 | PLATFORMS
156 | ruby
157 |
158 | DEPENDENCIES
159 | appraisal (~> 2.1)
160 | bundler (~> 1.12)
161 | capybara (~> 2.7.0)
162 | codeclimate-test-reporter
163 | combustion (~> 0.5.4)
164 | factory_girl (~> 4.0)
165 | ffaker (~> 2.2.0)
166 | generator_spec (~> 0.9.3)
167 | light-decorator!
168 | rails (= 4.2.6)
169 | rake (~> 10.0)
170 | rspec (~> 3.0)
171 | simplecov (~> 0.11.2)
172 | sqlite3 (~> 1.3.11)
173 |
174 | BUNDLED WITH
175 | 1.14.4
176 |
--------------------------------------------------------------------------------
/gemfiles/rails_5_0.gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: ..
3 | specs:
4 | light-decorator (1.0.1)
5 | rails (>= 4.0.0)
6 | request_store (>= 1.0.0)
7 |
8 | GEM
9 | remote: https://rubygems.org/
10 | specs:
11 | actioncable (5.0.0.rc1)
12 | actionpack (= 5.0.0.rc1)
13 | nio4r (~> 1.2)
14 | websocket-driver (~> 0.6.1)
15 | actionmailer (5.0.0.rc1)
16 | actionpack (= 5.0.0.rc1)
17 | actionview (= 5.0.0.rc1)
18 | activejob (= 5.0.0.rc1)
19 | mail (~> 2.5, >= 2.5.4)
20 | rails-dom-testing (~> 1.0, >= 1.0.5)
21 | actionpack (5.0.0.rc1)
22 | actionview (= 5.0.0.rc1)
23 | activesupport (= 5.0.0.rc1)
24 | rack (~> 2.x)
25 | rack-test (~> 0.6.3)
26 | rails-dom-testing (~> 1.0, >= 1.0.5)
27 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
28 | actionview (5.0.0.rc1)
29 | activesupport (= 5.0.0.rc1)
30 | builder (~> 3.1)
31 | erubis (~> 2.7.0)
32 | rails-dom-testing (~> 1.0, >= 1.0.5)
33 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
34 | activejob (5.0.0.rc1)
35 | activesupport (= 5.0.0.rc1)
36 | globalid (>= 0.3.6)
37 | activemodel (5.0.0.rc1)
38 | activesupport (= 5.0.0.rc1)
39 | activerecord (5.0.0.rc1)
40 | activemodel (= 5.0.0.rc1)
41 | activesupport (= 5.0.0.rc1)
42 | arel (~> 7.0)
43 | activesupport (5.0.0.rc1)
44 | concurrent-ruby (~> 1.0, >= 1.0.2)
45 | i18n (~> 0.7)
46 | minitest (~> 5.1)
47 | tzinfo (~> 1.1)
48 | addressable (2.4.0)
49 | appraisal (2.1.0)
50 | bundler
51 | rake
52 | thor (>= 0.14.0)
53 | arel (7.0.0)
54 | builder (3.2.2)
55 | capybara (2.7.1)
56 | addressable
57 | mime-types (>= 1.16)
58 | nokogiri (>= 1.3.3)
59 | rack (>= 1.0.0)
60 | rack-test (>= 0.5.4)
61 | xpath (~> 2.0)
62 | codeclimate-test-reporter (0.5.1)
63 | simplecov (>= 0.7.1, < 1.0.0)
64 | combustion (0.5.4)
65 | activesupport (>= 3.0.0)
66 | railties (>= 3.0.0)
67 | thor (>= 0.14.6)
68 | concurrent-ruby (1.0.2)
69 | diff-lcs (1.2.5)
70 | docile (1.1.5)
71 | erubis (2.7.0)
72 | factory_girl (4.7.0)
73 | activesupport (>= 3.0.0)
74 | ffaker (2.2.0)
75 | generator_spec (0.9.3)
76 | activesupport (>= 3.0.0)
77 | railties (>= 3.0.0)
78 | globalid (0.3.6)
79 | activesupport (>= 4.1.0)
80 | i18n (0.7.0)
81 | json (1.8.6)
82 | loofah (2.0.3)
83 | nokogiri (>= 1.5.9)
84 | mail (2.6.4)
85 | mime-types (>= 1.16, < 4)
86 | method_source (0.8.2)
87 | mime-types (3.1)
88 | mime-types-data (~> 3.2015)
89 | mime-types-data (3.2016.0521)
90 | mini_portile2 (2.1.0)
91 | minitest (5.9.0)
92 | nio4r (1.2.1)
93 | nokogiri (1.6.8)
94 | mini_portile2 (~> 2.1.0)
95 | pkg-config (~> 1.1.7)
96 | pkg-config (1.1.7)
97 | rack (2.0.0.rc1)
98 | json
99 | rack-test (0.6.3)
100 | rack (>= 1.0)
101 | rails (5.0.0.rc1)
102 | actioncable (= 5.0.0.rc1)
103 | actionmailer (= 5.0.0.rc1)
104 | actionpack (= 5.0.0.rc1)
105 | actionview (= 5.0.0.rc1)
106 | activejob (= 5.0.0.rc1)
107 | activemodel (= 5.0.0.rc1)
108 | activerecord (= 5.0.0.rc1)
109 | activesupport (= 5.0.0.rc1)
110 | bundler (>= 1.3.0, < 2.0)
111 | railties (= 5.0.0.rc1)
112 | sprockets-rails (>= 2.0.0)
113 | rails-deprecated_sanitizer (1.0.3)
114 | activesupport (>= 4.2.0.alpha)
115 | rails-dom-testing (1.0.7)
116 | activesupport (>= 4.2.0.beta, < 5.0)
117 | nokogiri (~> 1.6.0)
118 | rails-deprecated_sanitizer (>= 1.0.1)
119 | rails-html-sanitizer (1.0.3)
120 | loofah (~> 2.0)
121 | railties (5.0.0.rc1)
122 | actionpack (= 5.0.0.rc1)
123 | activesupport (= 5.0.0.rc1)
124 | method_source
125 | rake (>= 0.8.7)
126 | thor (>= 0.18.1, < 2.0)
127 | rake (10.5.0)
128 | request_store (1.3.2)
129 | rspec (3.4.0)
130 | rspec-core (~> 3.4.0)
131 | rspec-expectations (~> 3.4.0)
132 | rspec-mocks (~> 3.4.0)
133 | rspec-core (3.4.4)
134 | rspec-support (~> 3.4.0)
135 | rspec-expectations (3.4.0)
136 | diff-lcs (>= 1.2.0, < 2.0)
137 | rspec-support (~> 3.4.0)
138 | rspec-mocks (3.4.1)
139 | diff-lcs (>= 1.2.0, < 2.0)
140 | rspec-support (~> 3.4.0)
141 | rspec-support (3.4.1)
142 | simplecov (0.11.2)
143 | docile (~> 1.1.0)
144 | json (~> 1.8)
145 | simplecov-html (~> 0.10.0)
146 | simplecov-html (0.10.0)
147 | sprockets (3.6.0)
148 | concurrent-ruby (~> 1.0)
149 | rack (> 1, < 3)
150 | sprockets-rails (3.0.4)
151 | actionpack (>= 4.0)
152 | activesupport (>= 4.0)
153 | sprockets (>= 3.0.0)
154 | sqlite3 (1.3.11)
155 | thor (0.19.1)
156 | thread_safe (0.3.5)
157 | tzinfo (1.2.2)
158 | thread_safe (~> 0.1)
159 | websocket-driver (0.6.4)
160 | websocket-extensions (>= 0.1.0)
161 | websocket-extensions (0.1.2)
162 | xpath (2.0.0)
163 | nokogiri (~> 1.3)
164 |
165 | PLATFORMS
166 | ruby
167 |
168 | DEPENDENCIES
169 | appraisal (~> 2.1)
170 | bundler (~> 1.12)
171 | capybara (~> 2.7.0)
172 | codeclimate-test-reporter
173 | combustion (~> 0.5.4)
174 | factory_girl (~> 4.0)
175 | ffaker (~> 2.2.0)
176 | generator_spec (~> 0.9.3)
177 | light-decorator!
178 | rails (= 5.0.0.rc1)
179 | rake (~> 10.0)
180 | rspec (~> 3.0)
181 | simplecov (~> 0.11.2)
182 | sqlite3 (~> 1.3.11)
183 |
184 | BUNDLED WITH
185 | 1.14.4
186 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | AllCops:
2 | TargetRubyVersion: 2.0
3 | DisabledByDefault: true
4 | Exclude:
5 | - 'lib/generators/rails/decorator/templates/decorator.rb'
6 | - 'lib/generators/rspec/decorator/templates/decorator_spec.rb'
7 | - 'lib/generators/test_unit/decorator/templates/decorator_test.rb'
8 | - 'lib/generators/light/decorator/install/templates/application_decorator.rb'
9 |
10 | #################### Lint ################################
11 |
12 | Lint/AmbiguousOperator:
13 | Description: >-
14 | Checks for ambiguous operators in the first argument of a
15 | method invocation without parentheses.
16 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-as-args'
17 | Enabled: true
18 |
19 | Lint/AmbiguousRegexpLiteral:
20 | Description: >-
21 | Checks for ambiguous regexp literals in the first argument of
22 | a method invocation without parenthesis.
23 | Enabled: true
24 |
25 | Lint/AssignmentInCondition:
26 | Description: "Don't use assignment in conditions."
27 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition'
28 | Enabled: true
29 |
30 | Lint/BlockAlignment:
31 | Description: 'Align block ends correctly.'
32 | Enabled: true
33 |
34 | Lint/CircularArgumentReference:
35 | Description: "Don't refer to the keyword argument in the default value."
36 | Enabled: true
37 |
38 | Lint/ConditionPosition:
39 | Description: >-
40 | Checks for condition placed in a confusing position relative to
41 | the keyword.
42 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#same-line-condition'
43 | Enabled: true
44 |
45 | Lint/Debugger:
46 | Description: 'Check for debugger calls.'
47 | Enabled: true
48 |
49 | Lint/DefEndAlignment:
50 | Description: 'Align ends corresponding to defs correctly.'
51 | Enabled: true
52 |
53 | Lint/DeprecatedClassMethods:
54 | Description: 'Check for deprecated class method calls.'
55 | Enabled: true
56 |
57 | Lint/DuplicateMethods:
58 | Description: 'Check for duplicate methods calls.'
59 | Enabled: true
60 |
61 | Lint/EachWithObjectArgument:
62 | Description: 'Check for immutable argument given to each_with_object.'
63 | Enabled: true
64 |
65 | Lint/ElseLayout:
66 | Description: 'Check for odd code arrangement in an else block.'
67 | Enabled: true
68 |
69 | Lint/EmptyEnsure:
70 | Description: 'Checks for empty ensure block.'
71 | Enabled: true
72 |
73 | Lint/EmptyInterpolation:
74 | Description: 'Checks for empty string interpolation.'
75 | Enabled: true
76 |
77 | Lint/EndAlignment:
78 | Description: 'Align ends correctly.'
79 | Enabled: true
80 |
81 | Lint/EndInMethod:
82 | Description: 'END blocks should not be placed inside method definitions.'
83 | Enabled: true
84 |
85 | Lint/EnsureReturn:
86 | Description: 'Do not use return in an ensure block.'
87 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-return-ensure'
88 | Enabled: true
89 |
90 | Lint/Eval:
91 | Description: 'The use of eval represents a serious security risk.'
92 | Enabled: true
93 |
94 | Lint/FormatParameterMismatch:
95 | Description: 'The number of parameters to format/sprint must match the fields.'
96 | Enabled: true
97 |
98 | Lint/HandleExceptions:
99 | Description: "Don't suppress exception."
100 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions'
101 | Enabled: true
102 |
103 | Lint/InvalidCharacterLiteral:
104 | Description: >-
105 | Checks for invalid character literals with a non-escaped
106 | whitespace character.
107 | Enabled: true
108 |
109 | Lint/LiteralInCondition:
110 | Description: 'Checks of literals used in conditions.'
111 | Enabled: true
112 |
113 | Lint/LiteralInInterpolation:
114 | Description: 'Checks for literals used in interpolation.'
115 | Enabled: true
116 |
117 | Lint/Loop:
118 | Description: >-
119 | Use Kernel#loop with break rather than begin/end/until or
120 | begin/end/while for post-loop tests.
121 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#loop-with-break'
122 | Enabled: true
123 |
124 | Lint/NestedMethodDefinition:
125 | Description: 'Do not use nested method definitions.'
126 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-methods'
127 | Enabled: true
128 |
129 | Lint/NonLocalExitFromIterator:
130 | Description: 'Do not use return in iterator to cause non-local exit.'
131 | Enabled: true
132 |
133 | Lint/ParenthesesAsGroupedExpression:
134 | Description: >-
135 | Checks for method calls with a space before the opening
136 | parenthesis.
137 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
138 | Enabled: true
139 |
140 | Lint/RequireParentheses:
141 | Description: >-
142 | Use parentheses in the method call to avoid confusion
143 | about precedence.
144 | Enabled: true
145 |
146 | Lint/RescueException:
147 | Description: 'Avoid rescuing the Exception class.'
148 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-blind-rescues'
149 | Enabled: true
150 |
151 | Lint/ShadowingOuterLocalVariable:
152 | Description: >-
153 | Do not use the same name as outer local variable
154 | for block arguments or block local variables.
155 | Enabled: true
156 |
157 | Lint/StringConversionInInterpolation:
158 | Description: 'Checks for Object#to_s usage in string interpolation.'
159 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-to-s'
160 | Enabled: true
161 |
162 | Lint/UnderscorePrefixedVariableName:
163 | Description: 'Do not use prefix `_` for a variable that is used.'
164 | Enabled: true
165 |
166 | Lint/UnneededDisable:
167 | Description: >-
168 | Checks for rubocop:disable comments that can be removed.
169 | Note: this cop is not disabled when disabling all cops.
170 | It must be explicitly disabled.
171 | Enabled: true
172 |
173 | Lint/UnusedBlockArgument:
174 | Description: 'Checks for unused block arguments.'
175 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
176 | Enabled: true
177 |
178 | Lint/UnusedMethodArgument:
179 | Description: 'Checks for unused method arguments.'
180 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
181 | Enabled: true
182 |
183 | Lint/UnreachableCode:
184 | Description: 'Unreachable code.'
185 | Enabled: true
186 |
187 | Lint/UselessAccessModifier:
188 | Description: 'Checks for useless access modifiers.'
189 | Enabled: true
190 |
191 | Lint/UselessAssignment:
192 | Description: 'Checks for useless assignment to a local variable.'
193 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
194 | Enabled: true
195 |
196 | Lint/UselessComparison:
197 | Description: 'Checks for comparison of something with itself.'
198 | Enabled: true
199 |
200 | Lint/UselessElseWithoutRescue:
201 | Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
202 | Enabled: true
203 |
204 | Lint/UselessSetterCall:
205 | Description: 'Checks for useless setter call to a local variable.'
206 | Enabled: true
207 |
208 | Lint/Void:
209 | Description: 'Possible use of operator/literal/variable in void context.'
210 | Enabled: true
211 |
212 | ###################### Metrics ####################################
213 |
214 | Metrics/AbcSize:
215 | Description: >-
216 | A calculated magnitude based on number of assignments,
217 | branches, and conditions.
218 | Reference: 'http://c2.com/cgi/wiki?AbcMetric'
219 | Enabled: true
220 | Max: 20
221 |
222 | Metrics/BlockNesting:
223 | Description: 'Avoid excessive block nesting'
224 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
225 | Enabled: true
226 | Max: 4
227 |
228 | Metrics/ClassLength:
229 | Description: 'Avoid classes longer than 250 lines of code.'
230 | Enabled: true
231 | Max: 250
232 |
233 | Metrics/CyclomaticComplexity:
234 | Description: >-
235 | A complexity metric that is strongly correlated to the number
236 | of test cases needed to validate a method.
237 | Enabled: true
238 |
239 | Metrics/LineLength:
240 | Description: 'Limit lines to 80 characters.'
241 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
242 | Enabled: true
243 | Max: 120
244 |
245 | Metrics/MethodLength:
246 | Description: 'Avoid methods longer than 30 lines of code.'
247 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods'
248 | Enabled: true
249 | Max: 30
250 |
251 | Metrics/ModuleLength:
252 | Description: 'Avoid modules longer than 250 lines of code.'
253 | Enabled: true
254 | Max: 250
255 |
256 | Metrics/ParameterLists:
257 | Description: 'Avoid parameter lists longer than three or four parameters.'
258 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#too-many-params'
259 | Enabled: true
260 |
261 | Metrics/PerceivedComplexity:
262 | Description: >-
263 | A complexity metric geared towards measuring complexity for a
264 | human reader.
265 | Enabled: true
266 |
267 | ##################### Performance #############################
268 |
269 | Performance/Count:
270 | Description: >-
271 | Use `count` instead of `select...size`, `reject...size`,
272 | `select...count`, `reject...count`, `select...length`,
273 | and `reject...length`.
274 | Enabled: true
275 |
276 | Performance/Detect:
277 | Description: >-
278 | Use `detect` instead of `select.first`, `find_all.first`,
279 | `select.last`, and `find_all.last`.
280 | Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerabledetect-vs-enumerableselectfirst-code'
281 | Enabled: true
282 |
283 | Performance/FlatMap:
284 | Description: >-
285 | Use `Enumerable#flat_map`
286 | instead of `Enumerable#map...Array#flatten(1)`
287 | or `Enumberable#collect..Array#flatten(1)`
288 | Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code'
289 | Enabled: true
290 | EnabledForFlattenWithoutParams: false
291 | # If enabled, this cop will warn about usages of
292 | # `flatten` being called without any parameters.
293 | # This can be dangerous since `flat_map` will only flatten 1 level, and
294 | # `flatten` without any parameters can flatten multiple levels.
295 |
296 | Performance/ReverseEach:
297 | Description: 'Use `reverse_each` instead of `reverse.each`.'
298 | Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code'
299 | Enabled: true
300 |
301 | Performance/Sample:
302 | Description: >-
303 | Use `sample` instead of `shuffle.first`,
304 | `shuffle.last`, and `shuffle[Fixnum]`.
305 | Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code'
306 | Enabled: true
307 |
308 | Performance/Size:
309 | Description: >-
310 | Use `size` instead of `count` for counting
311 | the number of elements in `Array` and `Hash`.
312 | Reference: 'https://github.com/JuanitoFatas/fast-ruby#arraycount-vs-arraysize-code'
313 | Enabled: true
314 |
315 | Performance/StringReplacement:
316 | Description: >-
317 | Use `tr` instead of `gsub` when you are replacing the same
318 | number of characters. Use `delete` instead of `gsub` when
319 | you are deleting characters.
320 | Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code'
321 | Enabled: true
322 |
323 | ##################### Rails ##################################
324 |
325 | Rails/ActionFilter:
326 | Description: 'Enforces consistent use of action filter methods.'
327 | Enabled: true
328 |
329 | Rails/Date:
330 | Description: >-
331 | Checks the correct usage of date aware methods,
332 | such as Date.today, Date.current etc.
333 | Enabled: true
334 |
335 | Rails/Delegate:
336 | Description: 'Prefer delegate method for delegations.'
337 | Enabled: true
338 |
339 | Rails/FindBy:
340 | Description: 'Prefer find_by over where.first.'
341 | Enabled: true
342 |
343 | Rails/FindEach:
344 | Description: 'Prefer all.find_each over all.find.'
345 | Enabled: true
346 |
347 | Rails/HasAndBelongsToMany:
348 | Description: 'Prefer has_many :through to has_and_belongs_to_many.'
349 | Enabled: false
350 |
351 | Rails/Output:
352 | Description: 'Checks for calls to puts, print, etc.'
353 | Enabled: true
354 |
355 | Rails/ReadWriteAttribute:
356 | Description: >-
357 | Checks for read_attribute(:attr) and
358 | write_attribute(:attr, val).
359 | Enabled: true
360 |
361 | Rails/ScopeArgs:
362 | Description: 'Checks the arguments of ActiveRecord scopes.'
363 | Enabled: true
364 |
365 | Rails/TimeZone:
366 | Description: 'Checks the correct usage of time zone aware methods.'
367 | StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time'
368 | Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
369 | Enabled: true
370 |
371 | Rails/Validation:
372 | Description: 'Use validates :attribute, hash of validations.'
373 | Enabled: true
374 |
375 | ################## Style #################################
376 |
377 | Style/AccessModifierIndentation:
378 | Description: Check indentation of private/protected visibility modifiers.
379 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected'
380 | Enabled: true
381 |
382 | Style/AccessorMethodName:
383 | Description: Check the naming of accessor methods for get_/set_.
384 | Enabled: true
385 |
386 | Style/Alias:
387 | Description: 'Use alias_method instead of alias.'
388 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#alias-method'
389 | Enabled: true
390 |
391 | Style/AlignArray:
392 | Description: >-
393 | Align the elements of an array literal if they span more than
394 | one line.
395 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#align-multiline-arrays'
396 | Enabled: true
397 |
398 | Style/AlignHash:
399 | Description: >-
400 | Align the elements of a hash literal if they span more than
401 | one line.
402 | Enabled: true
403 |
404 | Style/AlignParameters:
405 | Description: >-
406 | Align the parameters of a method call if they span more
407 | than one line.
408 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-double-indent'
409 | Enabled: true
410 |
411 | Style/AndOr:
412 | Description: 'Use &&/|| instead of and/or.'
413 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-and-or-or'
414 | Enabled: true
415 | EnforcedStyle: conditionals
416 |
417 | Style/ArrayJoin:
418 | Description: 'Use Array#join instead of Array#*.'
419 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#array-join'
420 | Enabled: true
421 |
422 | Style/AsciiComments:
423 | Description: 'Use only ascii symbols in comments.'
424 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-comments'
425 | Enabled: true
426 |
427 | Style/AsciiIdentifiers:
428 | Description: 'Use only ascii symbols in identifiers.'
429 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-identifiers'
430 | Enabled: true
431 |
432 | Style/Attr:
433 | Description: 'Checks for uses of Module#attr.'
434 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr'
435 | Enabled: true
436 |
437 | Style/BeginBlock:
438 | Description: 'Avoid the use of BEGIN blocks.'
439 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-BEGIN-blocks'
440 | Enabled: true
441 |
442 | Style/BarePercentLiterals:
443 | Description: 'Checks if usage of %() or %Q() matches configuration.'
444 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q-shorthand'
445 | Enabled: true
446 |
447 | Style/BlockComments:
448 | Description: 'Do not use block comments.'
449 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-block-comments'
450 | Enabled: true
451 |
452 | Style/BlockEndNewline:
453 | Description: 'Put end statement of multiline block on its own line.'
454 | Enabled: true
455 |
456 | Style/BlockDelimiters:
457 | Description: >-
458 | Avoid using {...} for multi-line blocks (multiline chaining is
459 | always ugly).
460 | Prefer {...} over do...end for single-line blocks.
461 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
462 | Enabled: true
463 |
464 | Style/BracesAroundHashParameters:
465 | Description: 'Enforce braces style around hash parameters.'
466 | Enabled: false
467 |
468 | Style/CaseEquality:
469 | Description: 'Avoid explicit use of the case equality operator(===).'
470 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-case-equality'
471 | Enabled: true
472 |
473 | Style/CaseIndentation:
474 | Description: 'Indentation of when in a case/when/[else/]end.'
475 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-when-to-case'
476 | Enabled: true
477 |
478 | Style/CharacterLiteral:
479 | Description: 'Checks for uses of character literals.'
480 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-character-literals'
481 | Enabled: true
482 |
483 | Style/ClassAndModuleCamelCase:
484 | Description: 'Use CamelCase for classes and modules.'
485 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#camelcase-classes'
486 | Enabled: true
487 |
488 | Style/ClassAndModuleChildren:
489 | Description: 'Checks style of children classes and modules.'
490 | Enabled: false
491 |
492 | Style/ClassCheck:
493 | Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.'
494 | Enabled: true
495 |
496 | Style/ClassMethods:
497 | Description: 'Use self when defining module/class methods.'
498 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#def-self-class-methods'
499 | Enabled: true
500 |
501 | Style/ClassVars:
502 | Description: 'Avoid the use of class variables.'
503 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-class-vars'
504 | Enabled: true
505 |
506 | Style/ClosingParenthesisIndentation:
507 | Description: 'Checks the indentation of hanging closing parentheses.'
508 | Enabled: true
509 |
510 | Style/ColonMethodCall:
511 | Description: 'Do not use :: for method call.'
512 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#double-colons'
513 | Enabled: true
514 |
515 | Style/CommandLiteral:
516 | Description: 'Use `` or %x around command literals.'
517 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-x'
518 | Enabled: true
519 |
520 | Style/CommentAnnotation:
521 | Description: 'Checks formatting of annotation comments.'
522 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#annotate-keywords'
523 | Enabled: false
524 |
525 | Style/CommentIndentation:
526 | Description: 'Indentation of comments.'
527 | Enabled: true
528 |
529 | Style/ConstantName:
530 | Description: 'Constants should use SCREAMING_SNAKE_CASE.'
531 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#screaming-snake-case'
532 | Enabled: true
533 |
534 | Style/DefWithParentheses:
535 | Description: 'Use def with parentheses when there are arguments.'
536 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
537 | Enabled: true
538 |
539 | Style/DeprecatedHashMethods:
540 | Description: 'Checks for use of deprecated Hash methods.'
541 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key'
542 | Enabled: true
543 |
544 | Style/Documentation:
545 | Description: 'Document classes and non-namespace modules.'
546 | Enabled: false
547 |
548 | Style/DotPosition:
549 | Description: 'Checks the position of the dot in multi-line method calls.'
550 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains'
551 | Enabled: true
552 |
553 | Style/DoubleNegation:
554 | Description: 'Checks for uses of double negation (!!).'
555 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-bang-bang'
556 | Enabled: true
557 |
558 | Style/EachWithObject:
559 | Description: 'Prefer `each_with_object` over `inject` or `reduce`.'
560 | Enabled: true
561 |
562 | Style/ElseAlignment:
563 | Description: 'Align elses and elsifs correctly.'
564 | Enabled: true
565 |
566 | Style/EmptyElse:
567 | Description: 'Avoid empty else-clauses.'
568 | Enabled: true
569 |
570 | Style/EmptyLineBetweenDefs:
571 | Description: 'Use empty lines between defs.'
572 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods'
573 | Enabled: true
574 |
575 | Style/EmptyLines:
576 | Description: "Don't use several empty lines in a row."
577 | Enabled: true
578 |
579 | Style/EmptyLinesAroundAccessModifier:
580 | Description: "Keep blank lines around access modifiers."
581 | Enabled: true
582 |
583 | Style/EmptyLinesAroundBlockBody:
584 | Description: "Keeps track of empty lines around block bodies."
585 | Enabled: true
586 |
587 | Style/EmptyLinesAroundClassBody:
588 | Description: "Keeps track of empty lines around class bodies."
589 | Enabled: true
590 |
591 | Style/EmptyLinesAroundModuleBody:
592 | Description: "Keeps track of empty lines around module bodies."
593 | Enabled: true
594 |
595 | Style/EmptyLinesAroundMethodBody:
596 | Description: "Keeps track of empty lines around method bodies."
597 | Enabled: true
598 |
599 | Style/EmptyLiteral:
600 | Description: 'Prefer literals to Array.new/Hash.new/String.new.'
601 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#literal-array-hash'
602 | Enabled: true
603 |
604 | Style/EndBlock:
605 | Description: 'Avoid the use of END blocks.'
606 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-END-blocks'
607 | Enabled: true
608 |
609 | Style/EndOfLine:
610 | Description: 'Use Unix-style line endings.'
611 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#crlf'
612 | Enabled: true
613 |
614 | Style/EvenOdd:
615 | Description: 'Favor the use of Fixnum#even? && Fixnum#odd?'
616 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods'
617 | Enabled: true
618 |
619 | Style/ExtraSpacing:
620 | Description: 'Do not use unnecessary spacing.'
621 | Enabled: false
622 |
623 | Style/FileName:
624 | Description: 'Use snake_case for source file names.'
625 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
626 | Enabled: true
627 |
628 | Style/InitialIndentation:
629 | Description: >-
630 | Checks the indentation of the first non-blank non-comment line in a file.
631 | Enabled: true
632 |
633 | Style/FirstParameterIndentation:
634 | Description: 'Checks the indentation of the first parameter in a method call.'
635 | Enabled: true
636 |
637 | Style/FlipFlop:
638 | Description: 'Checks for flip flops'
639 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-flip-flops'
640 | Enabled: true
641 |
642 | Style/For:
643 | Description: 'Checks use of for or each in multiline loops.'
644 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-for-loops'
645 | Enabled: true
646 |
647 | Style/FormatString:
648 | Description: 'Enforce the use of Kernel#sprintf, Kernel#format or String#%.'
649 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#sprintf'
650 | Enabled: true
651 |
652 | Style/GlobalVars:
653 | Description: 'Do not introduce global variables.'
654 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#instance-vars'
655 | Reference: 'http://www.zenspider.com/Languages/Ruby/QuickRef.html'
656 | Enabled: true
657 |
658 | Style/GuardClause:
659 | Description: 'Check for conditionals that can be replaced with guard clauses'
660 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals'
661 | Enabled: true
662 |
663 | Style/HashSyntax:
664 | Description: >-
665 | Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
666 | { :a => 1, :b => 2 }.
667 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-literals'
668 | Enabled: true
669 |
670 | Style/IfUnlessModifier:
671 | Description: >-
672 | Favor modifier if/unless usage when you have a
673 | single-line body.
674 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier'
675 | Enabled: true
676 |
677 | Style/IfWithSemicolon:
678 | Description: 'Do not use if x; .... Use the ternary operator instead.'
679 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon-ifs'
680 | Enabled: true
681 |
682 | Style/IndentationConsistency:
683 | Description: 'Keep indentation straight.'
684 | Enabled: true
685 |
686 | Style/IndentationWidth:
687 | Description: 'Use 2 spaces for indentation.'
688 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation'
689 | Enabled: true
690 |
691 | Style/IndentArray:
692 | Description: >-
693 | Checks the indentation of the first element in an array
694 | literal.
695 | Enabled: true
696 |
697 | Style/IndentHash:
698 | Description: 'Checks the indentation of the first key in a hash literal.'
699 | Enabled: true
700 |
701 | Style/InfiniteLoop:
702 | Description: 'Use Kernel#loop for infinite loops.'
703 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#infinite-loop'
704 | Enabled: true
705 |
706 | Style/Lambda:
707 | Description: 'Use the new lambda literal syntax for single-line blocks.'
708 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#lambda-multi-line'
709 | Enabled: true
710 |
711 | Style/LambdaCall:
712 | Description: 'Use lambda.call(...) instead of lambda.(...).'
713 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc-call'
714 | Enabled: true
715 |
716 | Style/LeadingCommentSpace:
717 | Description: 'Comments should start with a space.'
718 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space'
719 | Enabled: true
720 |
721 | Style/LineEndConcatenation:
722 | Description: >-
723 | Use \ instead of + or << to concatenate two string literals at
724 | line end.
725 | Enabled: true
726 |
727 | Style/MethodCallWithoutArgsParentheses:
728 | Description: 'Do not use parentheses for method calls with no arguments.'
729 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
730 | Enabled: true
731 |
732 | Style/MethodDefParentheses:
733 | Description: >-
734 | Checks if the method definitions have or don't have
735 | parentheses.
736 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
737 | Enabled: true
738 |
739 | Style/MethodName:
740 | Description: 'Use the configured style when naming methods.'
741 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars'
742 | Enabled: true
743 |
744 | Style/ModuleFunction:
745 | Description: 'Checks for usage of `extend self` in modules.'
746 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#module-function'
747 | Enabled: true
748 |
749 | Style/MultilineBlockChain:
750 | Description: 'Avoid multi-line chains of blocks.'
751 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
752 | Enabled: true
753 |
754 | Style/MultilineBlockLayout:
755 | Description: 'Ensures newlines after multiline block do statements.'
756 | Enabled: true
757 |
758 | Style/MultilineIfThen:
759 | Description: 'Do not use then for multi-line if/unless.'
760 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-then'
761 | Enabled: true
762 |
763 | Style/MultilineOperationIndentation:
764 | Description: >-
765 | Checks indentation of binary operations that span more than
766 | one line.
767 | Enabled: true
768 |
769 | Style/MultilineTernaryOperator:
770 | Description: >-
771 | Avoid multi-line ?: (the ternary operator);
772 | use if/unless instead.
773 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-ternary'
774 | Enabled: true
775 |
776 | Style/NegatedIf:
777 | Description: >-
778 | Favor unless over if for negative conditions
779 | (or control flow or).
780 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#unless-for-negatives'
781 | Enabled: true
782 |
783 | Style/NegatedWhile:
784 | Description: 'Favor until over while for negative conditions.'
785 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#until-for-negatives'
786 | Enabled: true
787 |
788 | Style/NestedTernaryOperator:
789 | Description: 'Use one expression per branch in a ternary operator.'
790 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-ternary'
791 | Enabled: true
792 |
793 | Style/Next:
794 | Description: 'Use `next` to skip iteration instead of a condition at the end.'
795 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals'
796 | Enabled: true
797 |
798 | Style/NilComparison:
799 | Description: 'Prefer x.nil? to x == nil.'
800 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods'
801 | Enabled: true
802 |
803 | Style/NonNilCheck:
804 | Description: 'Checks for redundant nil checks.'
805 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-non-nil-checks'
806 | Enabled: true
807 |
808 | Style/Not:
809 | Description: 'Use ! instead of not.'
810 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bang-not-not'
811 | Enabled: true
812 |
813 | Style/NumericLiterals:
814 | Description: >-
815 | Add underscores to large numeric literals to improve their
816 | readability.
817 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics'
818 | Enabled: true
819 |
820 | Style/OneLineConditional:
821 | Description: >-
822 | Favor the ternary operator(?:) over
823 | if/then/else/end constructs.
824 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#ternary-operator'
825 | Enabled: true
826 |
827 | Style/OpMethod:
828 | Description: 'When defining binary operators, name the argument other.'
829 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#other-arg'
830 | Enabled: true
831 |
832 | Style/OptionalArguments:
833 | Description: >-
834 | Checks for optional arguments that do not appear at the end
835 | of the argument list
836 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#optional-arguments'
837 | Enabled: true
838 |
839 | Style/ParallelAssignment:
840 | Description: >-
841 | Check for simple usages of parallel assignment.
842 | It will only warn when the number of variables
843 | matches on both sides of the assignment.
844 | This also provides performance benefits
845 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment'
846 | Enabled: true
847 |
848 | Style/ParenthesesAroundCondition:
849 | Description: >-
850 | Don't use parentheses around the condition of an
851 | if/unless/while.
852 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-parens-if'
853 | Enabled: true
854 |
855 | Style/PercentLiteralDelimiters:
856 | Description: 'Use `%`-literal delimiters consistently'
857 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-literal-braces'
858 | Enabled: true
859 |
860 | Style/PercentQLiterals:
861 | Description: 'Checks if uses of %Q/%q match the configured preference.'
862 | Enabled: true
863 |
864 | Style/PerlBackrefs:
865 | Description: 'Avoid Perl-style regex back references.'
866 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers'
867 | Enabled: true
868 |
869 | Style/PredicateName:
870 | Description: 'Check the names of predicate methods.'
871 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark'
872 | Enabled: true
873 |
874 | Style/Proc:
875 | Description: 'Use proc instead of Proc.new.'
876 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc'
877 | Enabled: true
878 |
879 | Style/RaiseArgs:
880 | Description: 'Checks the arguments passed to raise/fail.'
881 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#exception-class-messages'
882 | Enabled: true
883 |
884 | Style/RedundantBegin:
885 | Description: "Don't use begin blocks when they are not needed."
886 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit'
887 | Enabled: true
888 |
889 | Style/RedundantException:
890 | Description: "Checks for an obsolete RuntimeException argument in raise/fail."
891 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-runtimeerror'
892 | Enabled: true
893 |
894 | Style/RedundantReturn:
895 | Description: "Don't use return where it's not required."
896 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-return'
897 | Enabled: true
898 |
899 | Style/RedundantSelf:
900 | Description: "Don't use self where it's not needed."
901 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-self-unless-required'
902 | Enabled: true
903 |
904 | Style/RegexpLiteral:
905 | Description: 'Use / or %r around regular expressions.'
906 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-r'
907 | Enabled: true
908 |
909 | Style/RescueEnsureAlignment:
910 | Description: 'Align rescues and ensures correctly.'
911 | Enabled: true
912 |
913 | Style/RescueModifier:
914 | Description: 'Avoid using rescue in its modifier form.'
915 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers'
916 | Enabled: true
917 |
918 | Style/SelfAssignment:
919 | Description: >-
920 | Checks for places where self-assignment shorthand should have
921 | been used.
922 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment'
923 | Enabled: true
924 |
925 | Style/Semicolon:
926 | Description: "Don't use semicolons to terminate expressions."
927 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon'
928 | Enabled: true
929 |
930 | Style/SignalException:
931 | Description: 'Checks for proper usage of fail and raise.'
932 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#fail-method'
933 | Enabled: true
934 |
935 | Style/SingleLineBlockParams:
936 | Description: 'Enforces the names of some block params.'
937 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#reduce-blocks'
938 | Enabled: true
939 |
940 | Style/SingleLineMethods:
941 | Description: 'Avoid single-line methods.'
942 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-single-line-methods'
943 | Enabled: true
944 |
945 | Style/SpaceBeforeFirstArg:
946 | Description: >-
947 | Checks that exactly one space is used between a method name
948 | and the first argument for method calls without parentheses.
949 | Enabled: true
950 |
951 | Style/SpaceAfterColon:
952 | Description: 'Use spaces after colons.'
953 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators'
954 | Enabled: true
955 |
956 | Style/SpaceAfterComma:
957 | Description: 'Use spaces after commas.'
958 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators'
959 | Enabled: true
960 |
961 | Style/SpaceAroundKeyword:
962 | Description: 'Use spaces around keywords.'
963 | Enabled: true
964 |
965 | Style/SpaceAfterMethodName:
966 | Description: >-
967 | Do not put a space between a method name and the opening
968 | parenthesis in a method definition.
969 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
970 | Enabled: true
971 |
972 | Style/SpaceAfterNot:
973 | Description: Tracks redundant space after the ! operator.
974 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-bang'
975 | Enabled: true
976 |
977 | Style/SpaceAfterSemicolon:
978 | Description: 'Use spaces after semicolons.'
979 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators'
980 | Enabled: true
981 |
982 | Style/SpaceBeforeBlockBraces:
983 | Description: >-
984 | Checks that the left block brace has or doesn't have space
985 | before it.
986 | Enabled: true
987 |
988 | Style/SpaceBeforeComma:
989 | Description: 'No spaces before commas.'
990 | Enabled: true
991 |
992 | Style/SpaceBeforeComment:
993 | Description: >-
994 | Checks for missing space between code and a comment on the
995 | same line.
996 | Enabled: true
997 |
998 | Style/SpaceBeforeSemicolon:
999 | Description: 'No spaces before semicolons.'
1000 | Enabled: true
1001 |
1002 | Style/SpaceInsideBlockBraces:
1003 | Description: >-
1004 | Checks that block braces have or don't have surrounding space.
1005 | For blocks taking parameters, checks that the left brace has
1006 | or doesn't have trailing space.
1007 | Enabled: true
1008 |
1009 | Style/SpaceAroundBlockParameters:
1010 | Description: 'Checks the spacing inside and after block parameters pipes.'
1011 | Enabled: true
1012 |
1013 | Style/SpaceAroundEqualsInParameterDefault:
1014 | Description: >-
1015 | Checks that the equals signs in parameter default assignments
1016 | have or don't have surrounding space depending on
1017 | configuration.
1018 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-around-equals'
1019 | Enabled: true
1020 |
1021 | Style/SpaceAroundOperators:
1022 | Description: 'Use a single space around operators.'
1023 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators'
1024 | Enabled: true
1025 |
1026 | Style/SpaceInsideBrackets:
1027 | Description: 'No spaces after [ or before ].'
1028 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
1029 | Enabled: true
1030 |
1031 | Style/SpaceInsideHashLiteralBraces:
1032 | Description: "Use spaces inside hash literal braces - or don't."
1033 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators'
1034 | Enabled: true
1035 |
1036 | Style/SpaceInsideParens:
1037 | Description: 'No spaces after ( or before ).'
1038 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
1039 | Enabled: true
1040 |
1041 | Style/SpaceInsideRangeLiteral:
1042 | Description: 'No spaces inside range literals.'
1043 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals'
1044 | Enabled: true
1045 |
1046 | Style/SpaceInsideStringInterpolation:
1047 | Description: 'Checks for padding/surrounding spaces inside string interpolation.'
1048 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#string-interpolation'
1049 | Enabled: true
1050 |
1051 | Style/SpecialGlobalVars:
1052 | Description: 'Avoid Perl-style global variables.'
1053 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms'
1054 | Enabled: true
1055 |
1056 | Style/StringLiterals:
1057 | Description: 'Checks if uses of quotes match the configured preference.'
1058 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-string-literals'
1059 | Enabled: true
1060 |
1061 | Style/StringLiteralsInInterpolation:
1062 | Description: >-
1063 | Checks if uses of quotes inside expressions in interpolated
1064 | strings match the configured preference.
1065 | Enabled: true
1066 |
1067 | Style/StructInheritance:
1068 | Description: 'Checks for inheritance from Struct.new.'
1069 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-extend-struct-new'
1070 | Enabled: true
1071 |
1072 | Style/SymbolLiteral:
1073 | Description: 'Use plain symbols instead of string symbols when possible.'
1074 | Enabled: true
1075 |
1076 | Style/SymbolProc:
1077 | Description: 'Use symbols as procs instead of blocks when possible.'
1078 | Enabled: true
1079 |
1080 | Style/Tab:
1081 | Description: 'No hard tabs.'
1082 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation'
1083 | Enabled: true
1084 |
1085 | Style/TrailingBlankLines:
1086 | Description: 'Checks trailing blank lines and final newline.'
1087 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof'
1088 | Enabled: true
1089 |
1090 | Style/TrailingCommaInArguments:
1091 | Description: 'Checks for trailing comma in parameter lists.'
1092 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma'
1093 | Enabled: true
1094 |
1095 | Style/TrailingCommaInLiteral:
1096 | Description: 'Checks for trailing comma in literals.'
1097 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
1098 | Enabled: true
1099 |
1100 | Style/TrailingWhitespace:
1101 | Description: 'Avoid trailing whitespace.'
1102 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-whitespace'
1103 | Enabled: true
1104 |
1105 | Style/TrivialAccessors:
1106 | Description: 'Prefer attr_* methods to trivial readers/writers.'
1107 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr_family'
1108 | Enabled: true
1109 |
1110 | Style/UnlessElse:
1111 | Description: >-
1112 | Do not use unless with else. Rewrite these with the positive
1113 | case first.
1114 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-else-with-unless'
1115 | Enabled: true
1116 |
1117 | Style/UnneededCapitalW:
1118 | Description: 'Checks for %W when interpolation is not needed.'
1119 | Enabled: true
1120 |
1121 | Style/UnneededPercentQ:
1122 | Description: 'Checks for %q/%Q when single quotes or double quotes would do.'
1123 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q'
1124 | Enabled: true
1125 |
1126 | Style/TrailingUnderscoreVariable:
1127 | Description: >-
1128 | Checks for the usage of unneeded trailing underscores at the
1129 | end of parallel variable assignment.
1130 | Enabled: true
1131 |
1132 | Style/VariableInterpolation:
1133 | Description: >-
1134 | Don't interpolate global, instance and class variables
1135 | directly in strings.
1136 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#curlies-interpolate'
1137 | Enabled: true
1138 |
1139 | Style/VariableName:
1140 | Description: 'Use the configured style when naming variables.'
1141 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars'
1142 | Enabled: true
1143 |
1144 | Style/WhenThen:
1145 | Description: 'Use when x then ... for one-line cases.'
1146 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#one-line-cases'
1147 | Enabled: true
1148 |
1149 | Style/WhileUntilDo:
1150 | Description: 'Checks for redundant do after while or until.'
1151 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-while-do'
1152 | Enabled: true
1153 |
1154 | Style/WhileUntilModifier:
1155 | Description: >-
1156 | Favor modifier while/until usage when you have a
1157 | single-line body.
1158 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#while-as-a-modifier'
1159 | Enabled: true
1160 |
1161 | Style/WordArray:
1162 | Description: 'Use %w or %W for arrays of words.'
1163 | StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w'
1164 | Enabled: false
1165 |
--------------------------------------------------------------------------------