Skip to content

Commit

Permalink
Merge pull request #642 from johnnyshields/array-brackets-rubocop
Browse files Browse the repository at this point in the history
Cleanup: Use Ruby style guide syntax for arrays (extracted from Rubocop PR)
  • Loading branch information
CloCkWeRX committed Dec 14, 2017
2 parents a648788 + 128c810 commit 59d9567
Show file tree
Hide file tree
Showing 91 changed files with 173 additions and 173 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/fields_controller.rb
Expand Up @@ -6,7 +6,7 @@
class Admin::FieldsController < Admin::ApplicationController
before_action "set_current_tab('admin/fields')", only: [:index]

load_resource except: [:create, :subform]
load_resource except: %i[create subform]

# GET /fields
# GET /fields.xml HTML
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/groups_controller.rb
Expand Up @@ -4,7 +4,7 @@
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class Admin::GroupsController < Admin::ApplicationController
before_action :setup_current_tab, only: [:index, :show]
before_action :setup_current_tab, only: %i[index show]

load_resource

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/tags_controller.rb
Expand Up @@ -4,7 +4,7 @@
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class Admin::TagsController < Admin::ApplicationController
before_action "set_current_tab('admin/tags')", only: [:index, :show]
before_action "set_current_tab('admin/tags')", only: %i[index show]

load_resource

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Expand Up @@ -4,7 +4,7 @@
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class Admin::UsersController < Admin::ApplicationController
before_action :setup_current_tab, only: [:index, :show]
before_action :setup_current_tab, only: %i[index show]

load_resource except: [:create]

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -19,7 +19,7 @@ class ApplicationController < ActionController::Base
helper_method :called_from_index_page?, :called_from_landing_page?
helper_method :klass

respond_to :html, only: [:index, :show, :auto_complete]
respond_to :html, only: %i[index show auto_complete]
respond_to :js
respond_to :json, :xml, except: :edit
respond_to :atom, :csv, :rss, :xls, only: :index
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/authentications_controller.rb
Expand Up @@ -4,7 +4,7 @@
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class AuthenticationsController < ApplicationController
before_action :require_no_user, only: [:new, :create, :show]
before_action :require_no_user, only: %i[new create show]
before_action :require_user, only: :destroy

#----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/entities/contacts_controller.rb
Expand Up @@ -4,7 +4,7 @@
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class ContactsController < EntitiesController
before_action :get_accounts, only: [:new, :create, :edit, :update]
before_action :get_accounts, only: %i[new create edit update]

# GET /contacts
#----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/entities/opportunities_controller.rb
Expand Up @@ -6,7 +6,7 @@
class OpportunitiesController < EntitiesController
before_action :load_settings
before_action :get_data_for_sidebar, only: :index
before_action :set_params, only: [:index, :redraw, :filter]
before_action :set_params, only: %i[index redraw filter]

# GET /opportunities
#----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/entities_controller.rb
Expand Up @@ -5,8 +5,8 @@
#------------------------------------------------------------------------------
class EntitiesController < ApplicationController
before_action :require_user
before_action :set_current_tab, only: [:index, :show]
before_action :set_view, only: [:index, :show, :redraw]
before_action :set_current_tab, only: %i[index show]
before_action :set_view, only: %i[index show redraw]

before_action :set_options, only: :index
before_action :load_ransack_search, only: :index
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/home_controller.rb
Expand Up @@ -4,7 +4,7 @@
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class HomeController < ApplicationController
before_action :require_user, except: [:toggle, :timezone]
before_action :require_user, except: %i[toggle timezone]
before_action :set_current_tab, only: :index

#----------------------------------------------------------------------------
Expand Down Expand Up @@ -57,9 +57,9 @@ def toggle
#----------------------------------------------------------------------------
def timeline
state = params[:state].to_s
if %w(Collapsed Expanded).include?(state)
if %w[Collapsed Expanded].include?(state)
if (model_type = params[:type].to_s).present?
if %w(comment email).include?(model_type)
if %w[comment email].include?(model_type)
model = model_type.camelize.constantize
item = model.find(params[:id])
item.update_attribute(:state, state)
Expand Down Expand Up @@ -115,7 +115,7 @@ def activity_asset
def activity_event
event = current_user.pref[:activity_event]
if event == "all_events"
%w(create update destroy)
%w[create update destroy]
else
event
end
Expand Down Expand Up @@ -155,8 +155,8 @@ def activity_duration
duration = current_user.pref[:activity_duration]
if duration
words = duration.split("_") # "two_weeks" => 2.weeks
if %w(one two).include?(words.first) && %w(hour day days week weeks month).include?(words.last)
%w(zero one two).index(words.first).send(words.last)
if %w[one two].include?(words.first) && %w[hour day days week weeks month].include?(words.last)
%w[zero one two].index(words.first).send(words.last)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/passwords_controller.rb
Expand Up @@ -4,7 +4,7 @@
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class PasswordsController < ApplicationController
before_action :load_user_using_perishable_token, only: [:edit, :update]
before_action :load_user_using_perishable_token, only: %i[edit update]
before_action :require_no_user

#----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Expand Up @@ -5,7 +5,7 @@
#------------------------------------------------------------------------------
class TasksController < ApplicationController
before_action :require_user
before_action :set_current_tab, only: [:index, :show]
before_action :set_current_tab, only: %i[index show]
before_action :update_sidebar, only: :index

# GET /tasks
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Expand Up @@ -4,12 +4,12 @@
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class UsersController < ApplicationController
before_action :set_current_tab, only: [:show, :opportunities_overview] # Don't hightlight any tabs.
before_action :set_current_tab, only: %i[show opportunities_overview] # Don't hightlight any tabs.

check_authorization
load_and_authorize_resource # handles all security

respond_to :html, only: [:show, :new]
respond_to :html, only: %i[show new]

# GET /users/1
# GET /users/1.js
Expand Down
16 changes: 8 additions & 8 deletions app/helpers/application_helper.rb
Expand Up @@ -16,14 +16,14 @@ def tabs(tabs = nil)

#----------------------------------------------------------------------------
def tabless_layout?
%w(authentications passwords).include?(controller.controller_name) ||
((controller.controller_name == "users") && %w(create new).include?(controller.action_name))
%w[authentications passwords].include?(controller.controller_name) ||
((controller.controller_name == "users") && %w[create new].include?(controller.action_name))
end

# Show existing flash or embed hidden paragraph ready for flash[:notice]
#----------------------------------------------------------------------------
def show_flash(options = { sticky: false })
[:error, :warning, :info, :notice].each do |type|
%i[error warning info notice].each do |type|
if flash[type]
html = content_tag(:div, h(flash[type]), id: "flash")
flash[type] = nil
Expand Down Expand Up @@ -175,7 +175,7 @@ def link_to_email(email, length = nil, &_block)

#----------------------------------------------------------------------------
def jumpbox(current)
tabs = [:campaigns, :accounts, :leads, :contacts, :opportunities]
tabs = %i[campaigns accounts leads contacts opportunities]
current = tabs.first unless tabs.include?(current)
tabs.map do |tab|
link_to_function(t("tab_#{tab}"), "crm.jumper('#{tab}')", "html-data" => tab, class: (tab == current ? 'selected' : ''))
Expand Down Expand Up @@ -252,7 +252,7 @@ def refresh_sidebar_for(view, action = nil, shake = nil)
# Display web presence mini-icons for Contact or Lead.
#----------------------------------------------------------------------------
def web_presence_icons(person)
[:blog, :linkedin, :facebook, :twitter, :skype].map do |site|
%i[blog linkedin facebook twitter skype].map do |site|
url = person.send(site)
unless url.blank?
if site == :skype
Expand Down Expand Up @@ -368,15 +368,15 @@ def links_to_export(action = :index)
url_params[:view] = @view unless @view.blank? # tasks
url_params[:id] = params[:id] unless params[:id].blank?

exports = %w(xls csv).map do |format|
exports = %w[xls csv].map do |format|
link_to(format.upcase, url_params.merge(format: format), title: I18n.t(:"to_#{format}")) unless action.to_s == "show"
end

feeds = %w(rss atom).map do |format|
feeds = %w[rss atom].map do |format|
link_to(format.upcase, url_params.merge(format: format, authentication_credentials: token), title: I18n.t(:"to_#{format}"))
end

links = %w(perm).map do |format|
links = ['perm'].map do |format|
link_to(format.upcase, url_params, title: I18n.t(:"to_#{format}"))
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/opportunities_helper.rb
Expand Up @@ -17,7 +17,7 @@ def opportunity_summary(opportunity)
amount = []
summary << (opportunity.stage ? t(opportunity.stage) : t(:other))
summary << number_to_currency(opportunity.weighted_amount, precision: 0)
unless %w(won lost).include?(opportunity.stage)
unless %w[won lost].include?(opportunity.stage)
amount << number_to_currency(opportunity.amount || 0, precision: 0)
amount << (opportunity.discount ? t(:discount_number, number_to_currency(opportunity.discount, precision: 0)) : t(:no_discount))
amount << t(:probability_number, (opportunity.probability || 0).to_s + '%')
Expand Down
2 changes: 1 addition & 1 deletion app/inputs/date_pair_input.rb
Expand Up @@ -15,7 +15,7 @@ def input(wrapper_options)
[field1, field2].compact.each do |field|
out << '<div>'.html_safe
label = field == field1 ? I18n.t('pair.start') : I18n.t('pair.end')
[:required, :disabled].each { |k| input_html_options.delete(k) } # ensure these come from field not default options
%i[required disabled].each { |k| input_html_options.delete(k) } # ensure these come from field not default options
input_html_options.merge!(field.input_options)
input_html_options[:value] = value(field)
out << "<label#{' class="req"' if input_html_options[:required]}>#{label}</label>".html_safe
Expand Down
2 changes: 1 addition & 1 deletion app/models/entities/account.rb
Expand Up @@ -67,7 +67,7 @@ class Account < ActiveRecord::Base
exportable
sortable by: ["name ASC", "rating DESC", "created_at DESC", "updated_at DESC"], default: "created_at DESC"

has_ransackable_associations %w(contacts opportunities tags activities emails addresses comments tasks)
has_ransackable_associations %w[contacts opportunities tags activities emails addresses comments tasks]
ransack_can_autocomplete

validates_presence_of :name, message: :missing_account_name
Expand Down
2 changes: 1 addition & 1 deletion app/models/entities/account_contact.rb
Expand Up @@ -20,7 +20,7 @@ class AccountContact < ActiveRecord::Base
belongs_to :contact

has_paper_trail class_name: 'Version', meta: { related: :contact },
ignore: [:id, :created_at, :updated_at, :contact_id]
ignore: %i[id created_at updated_at contact_id]

validates_presence_of :account_id

Expand Down
4 changes: 2 additions & 2 deletions app/models/entities/campaign.rb
Expand Up @@ -56,11 +56,11 @@ class Campaign < ActiveRecord::Base
exportable
sortable by: ["name ASC", "target_leads DESC", "target_revenue DESC", "leads_count DESC", "revenue DESC", "starts_on DESC", "ends_on DESC", "created_at DESC", "updated_at DESC"], default: "created_at DESC"

has_ransackable_associations %w(leads opportunities tags activities emails comments tasks)
has_ransackable_associations %w[leads opportunities tags activities emails comments tasks]
ransack_can_autocomplete

validates_presence_of :name, message: :missing_campaign_name
validates_uniqueness_of :name, scope: [:user_id, :deleted_at]
validates_uniqueness_of :name, scope: %i[user_id deleted_at]
validate :start_and_end_dates
validate :users_for_shared_access
validates :status, inclusion: { in: proc { Setting.unroll(:campaign_status).map { |s| s.last.to_s } } }, allow_blank: true
Expand Down
4 changes: 2 additions & 2 deletions app/models/entities/contact.rb
Expand Up @@ -52,7 +52,7 @@ class Contact < ActiveRecord::Base

delegate :campaign, to: :lead, allow_nil: true

has_ransackable_associations %w(account opportunities tags activities emails addresses comments tasks)
has_ransackable_associations %w[account opportunities tags activities emails addresses comments tasks]
ransack_can_autocomplete

serialize :subscribed_users, Set
Expand Down Expand Up @@ -162,7 +162,7 @@ def self.create_for(model, account, opportunity, params)
assigned_to: params[:account][:assigned_to],
access: params[:access]
}
%w(first_name last_name title source email alt_email phone mobile blog linkedin facebook twitter skype do_not_call background_info).each do |name|
%w[first_name last_name title source email alt_email phone mobile blog linkedin facebook twitter skype do_not_call background_info].each do |name|
attributes[name] = model.send(name.intern)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/entities/lead.rb
Expand Up @@ -69,7 +69,7 @@ class Lead < ActiveRecord::Base
exportable
sortable by: ["first_name ASC", "last_name ASC", "company ASC", "rating DESC", "created_at DESC", "updated_at DESC"], default: "created_at DESC"

has_ransackable_associations %w(contact campaign tasks tags activities emails addresses comments)
has_ransackable_associations %w[contact campaign tasks tags activities emails addresses comments]
ransack_can_autocomplete

validates_presence_of :first_name, message: :missing_first_name, if: -> { Setting.require_first_names }
Expand Down
4 changes: 2 additions & 2 deletions app/models/entities/opportunity.rb
Expand Up @@ -75,11 +75,11 @@ class Opportunity < ActiveRecord::Base
exportable
sortable by: ["name ASC", "amount DESC", "amount*probability DESC", "probability DESC", "closes_on ASC", "created_at DESC", "updated_at DESC"], default: "created_at DESC"

has_ransackable_associations %w(account contacts tags campaign activities emails comments)
has_ransackable_associations %w[account contacts tags campaign activities emails comments]
ransack_can_autocomplete

validates_presence_of :name, message: :missing_opportunity_name
validates_numericality_of [:probability, :amount, :discount], allow_nil: true
validates_numericality_of %i[probability amount discount], allow_nil: true
validate :users_for_shared_access
validates :stage, inclusion: { in: proc { Setting.unroll(:opportunity_stage).map { |s| s.last.to_s } } }, allow_blank: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/fields/custom_field.rb
Expand Up @@ -54,7 +54,7 @@ class CustomField < Field
after_create :add_ransack_translation

SAFE_DB_TRANSITIONS = {
any: [%w(date time timestamp), %w(integer float)],
any: [%w[date time timestamp], %w[integer float]],
one: { 'string' => 'text' }
}

Expand Down
4 changes: 2 additions & 2 deletions app/models/fields/custom_field_pair.rb
Expand Up @@ -12,7 +12,7 @@ def self.create_pair(params)
fields = params['field']
as = params['field']['as']
pair = params.delete('pair')
base_params = fields.delete_if { |k, _v| !%w(field_group_id label as).include?(k) }
base_params = fields.delete_if { |k, _v| !%w[field_group_id label as].include?(k) }
klass = ("custom_field_" + as.gsub('pair', '_pair')).classify.constantize
field1 = klass.create(base_params.merge(pair['0']))
field2 = klass.create(base_params.merge(pair['1']).merge('pair_id' => field1.id, 'required' => field1.required, 'disabled' => field1.disabled))
Expand All @@ -24,7 +24,7 @@ def self.create_pair(params)
def self.update_pair(params)
fields = params['field']
pair = params.delete('pair')
base_params = fields.delete_if { |k, _v| !%w(field_group_id label as).include?(k) }
base_params = fields.delete_if { |k, _v| !%w[field_group_id label as].include?(k) }
field1 = CustomFieldPair.find(params['id'])
field1.update_attributes(base_params.merge(pair['0']))
field2 = field1.paired_with
Expand Down
2 changes: 1 addition & 1 deletion app/models/fields/field.rb
Expand Up @@ -69,7 +69,7 @@ def column_type(field_type = as)
def input_options
input_html = {}
attributes.reject do |k, v|
!%w(as collection disabled label placeholder required maxlength).include?(k) || v.blank?
!%w[as collection disabled label placeholder required maxlength].include?(k) || v.blank?
end.symbolize_keys.merge(input_html)
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/polymorphic/address.rb
Expand Up @@ -36,7 +36,7 @@ class Address < ActiveRecord::Base
#----------------------------------------------------------------------------
def blank?
if Setting.compound_address
%w(street1 street2 city state zipcode country).all? { |attr| send(attr).blank? }
%w[street1 street2 city state zipcode country].all? { |attr| send(attr).blank? }
else
full_address.blank?
end
Expand All @@ -50,7 +50,7 @@ def blank?
# accepts_nested_attributes_for :business_address, :allow_destroy => true, :reject_if => proc {|attributes| Address.reject_address(attributes)}
def self.reject_address(attributes)
exists = attributes['id'].present?
empty = %w(street1 street2 city state zipcode country full_address).map { |name| attributes[name].blank? }.all?
empty = %w[street1 street2 city state zipcode country full_address].map { |name| attributes[name].blank? }.all?
attributes[:_destroy] = 1 if exists && empty
(!exists && empty)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/polymorphic/avatar.rb
Expand Up @@ -36,15 +36,15 @@ def entity_type(attachment, _style_name = nil)
end
has_attached_file :image, styles: STYLES.dup, url: "/avatars/:entity_type/:id/:style_:filename", default_url: "/assets/avatar.jpg"
validates_attachment :image, presence: true,
content_type: { content_type: %w(image/jpeg image/jpg image/png image/gif) }
content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] }

# Convert STYLE symbols to 'w x h' format for Gravatar and Rails
# e.g. Avatar.size_from_style(:size => :large) -> '75x75'
# Allow options to contain :width and :height override keys
#----------------------------------------------------------------------------
def self.size_from_style!(options)
if options[:width] && options[:height]
options[:size] = [:width, :height].map { |d| options[d] }.join("x")
options[:size] = %i[width height].map { |d| options[d] }.join("x")
options.delete(:width)
options.delete(:height)
elsif Avatar::STYLES.keys.include?(options[:size])
Expand Down
2 changes: 1 addition & 1 deletion app/models/polymorphic/task.rb
Expand Up @@ -29,7 +29,7 @@ class Task < ActiveRecord::Base
include ActiveModel::Serializers::Xml

attr_accessor :calendar
ALLOWED_VIEWS = %w(pending assigned completed)
ALLOWED_VIEWS = %w[pending assigned completed]

belongs_to :user
belongs_to :assignee, class_name: "User", foreign_key: :assigned_to
Expand Down
6 changes: 3 additions & 3 deletions app/models/polymorphic/version.rb
Expand Up @@ -6,9 +6,9 @@
require 'paper_trail'

class Version < PaperTrail::Version
ASSETS = %w(all tasks campaigns leads accounts contacts opportunities comments emails)
EVENTS = %w(all_events create view update destroy)
DURATION = %w(one_hour one_day two_days one_week two_weeks one_month)
ASSETS = %w[all tasks campaigns leads accounts contacts opportunities comments emails]
EVENTS = %w[all_events create view update destroy]
DURATION = %w[one_hour one_day two_days one_week two_weeks one_month]

belongs_to :related, polymorphic: true
belongs_to :user, foreign_key: :whodunnit
Expand Down

0 comments on commit 59d9567

Please sign in to comment.