Skip to content

Commit

Permalink
Refs #3809 - Use parentheses in method definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
dLobatog authored and ohadlevy committed Oct 7, 2014
1 parent 19abc86 commit 5f029ed
Show file tree
Hide file tree
Showing 136 changed files with 417 additions and 423 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Expand Up @@ -308,12 +308,6 @@ Style/LineLength:
Style/MethodCallParentheses:
Enabled: false

# Offense count: 422
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/MethodDefParentheses:
Enabled: false

# Offense count: 283
# Configuration parameters: CountComments.
Style/MethodLength:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/config_templates_controller.rb
Expand Up @@ -89,7 +89,7 @@ def handle_template_upload
params[:config_template][:template] = t.read if t.respond_to?(:read)
end

def default_template_url template, hostgroup
def default_template_url(template, hostgroup)
url_for :only_path => false, :action => :template, :controller => '/unattended',
:id => template.name, :hostgroup => hostgroup.name
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v2/config_templates_controller.rb
Expand Up @@ -88,7 +88,7 @@ def handle_template_upload
params[:config_template][:template] = t.read if t.respond_to?(:read)
end

def default_template_url template, hostgroup
def default_template_url(template, hostgroup)
url_for :only_path => false, :action => :template, :controller => '/unattended',
:id => template.name, :hostgroup => hostgroup.name
end
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/application_controller.rb
Expand Up @@ -152,15 +152,15 @@ def resource_base
model_of_controller.scoped
end

def notice notice
def notice(notice)
flash[:notice] = CGI::escapeHTML(notice)
end

def error error
def error(error)
flash[:error] = CGI::escapeHTML(error)
end

def warning warning
def warning(warning)
flash[:warning] = CGI::escapeHTML(warning)
end

Expand Down Expand Up @@ -240,7 +240,7 @@ def render_error(msg, status)
render_403
end

def process_success hash = {}
def process_success(hash = {})
hash[:object] ||= instance_variable_get("@#{controller_name.singularize}")
hash[:object_name] ||= hash[:object].to_s
unless hash[:success_msg]
Expand All @@ -261,7 +261,7 @@ def process_success hash = {}
redirect_to hash[:success_redirect] and return
end

def process_error hash = {}
def process_error(hash = {})
hash[:object] ||= instance_variable_get("@#{controller_name.singularize}")

case action_name
Expand Down Expand Up @@ -296,7 +296,7 @@ def process_ajax_error(exception, action = nil)
render :text => "Failure: #{message}"
end

def redirect_back_or_to url
def redirect_back_or_to(url)
redirect_to request.referer.empty? ? url : :back
end

Expand Down Expand Up @@ -355,7 +355,7 @@ def included_associations(include = [])
include
end

def errors_hash errors
def errors_hash(errors)
errors.any? ? {:status => N_("Error"), :message => errors.full_messages.join('<br>')} : {:status => N_("OK"), :message =>""}
end

Expand Down
Expand Up @@ -41,7 +41,7 @@ def use_image_selected
end

private
def assign_parameter name, root = ""
def assign_parameter(name, root = "")
taxonomy_scope
Taxonomy.as_taxonomy @organization, @location do
if params["#{name}_id"].to_i > 0 and instance_variable_set("@#{name}",name.classify.constantize.find(params["#{name}_id"]))
Expand Down
Expand Up @@ -27,7 +27,7 @@ def update_multiple_location

private

def update_multiple_taxonomies type
def update_multiple_taxonomies(type)
# simple validations
if (params[type].nil?) or (id=params[type][:id]).blank?
error "No #{type.to_s.classify} selected!"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/config_templates_controller.rb
Expand Up @@ -102,7 +102,7 @@ def load_history
@history = Audit.descending.where(:auditable_id => @config_template.id, :auditable_type => 'ConfigTemplate')
end

def default_template_url template, hostgroup
def default_template_url(template, hostgroup)
url_for :only_path => false, :action => :template, :controller => '/unattended',
:id => template.name, :hostgroup => hostgroup.name
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Expand Up @@ -19,7 +19,7 @@ def status

private
# check for exception - set the result code and duration time
def exception_watch &block
def exception_watch(&block)
start = Time.now
result = {}
begin
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/hosts_controller.rb
Expand Up @@ -683,7 +683,7 @@ def find_multiple
redirect_to hosts_path and return false
end

def toggle_hostmode mode = true
def toggle_hostmode(mode = true)
# keep all the ones that were not disabled for notification.
@hosts.delete_if { |host| host.update_attribute(:enabled, mode) }
action = mode ? "enabled" : "disabled"
Expand All @@ -702,7 +702,7 @@ def forward_url_options(host = @host)
host.url_options = url_options if @host.respond_to?(:url_options)
end

def merge_search_filter filter
def merge_search_filter(filter)
if params[:search].empty?
params[:search] = filter
else
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/unattended_controller.rb
Expand Up @@ -69,7 +69,7 @@ def gPXE; iPXE; end

private

def render_template type
def render_template(type)
if (config = @host.configTemplate({ :kind => type }))
logger.debug "rendering DB template #{config.name} - #{type}"
safe_render config
Expand Down Expand Up @@ -275,7 +275,7 @@ def ip_from_request_env
ip
end

def safe_render template
def safe_render(template)
@template_name = 'Unnamed'
if template.is_a?(String)
@unsafe_template = template
Expand Down
30 changes: 15 additions & 15 deletions app/helpers/application_helper.rb
Expand Up @@ -28,15 +28,15 @@ def link_to(*args, &block)
end

protected
def contract model
def contract(model)
model.to_label
end

def show_habtm associations
def show_habtm(associations)
render :partial => 'common/show_habtm', :collection => associations, :as => :association
end

def edit_habtm klass, association, prefix = nil, options = {}
def edit_habtm(klass, association, prefix = nil, options = {})
render :partial => 'common/edit_habtm', :locals =>{:prefix => prefix, :klass => klass, :options => options,
:associations => association.all.sort.delete_if{|e| e == klass}}
end
Expand All @@ -58,7 +58,7 @@ def link_to_add_fields(name, f, association, partial = nil, options = {})
link_to_function(name, ("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\"); turn_textarea_switch();").html_safe, add_html_classes(options, "btn btn-success") )
end

def link_to_remove_puppetclass klass, host
def link_to_remove_puppetclass(klass, host)
options = klass.name.size > 28 ? {:'data-original-title'=>klass.name, :rel=>'twipsy'} : {}
functions_options = { :klass => klass, :host => host, :css_class => ''}
text = remove_link_to_function(truncate(klass.name, :length => 28), functions_options)
Expand All @@ -76,7 +76,7 @@ def remove_link_to_function(text, options)
:class=>options[:css_class])
end

def link_to_add_puppetclass klass, host, type
def link_to_add_puppetclass(klass, host, type)
options = klass.name.size > 28 ? {:'data-original-title'=>klass.name, :rel=>'twipsy'} : {}
function_options = { :klass => klass, :host => host, :type => type }
text = add_link_to_function(truncate(klass.name, :length => 28), function_options)
Expand All @@ -96,7 +96,7 @@ def add_link_to_function(text, options)
:class => options[:css_class])
end

def add_html_classes options, classes
def add_html_classes(options, classes)
options = options.dup unless options.nil?
options ||= {}
options[:class] = options[:class].dup if options.has_key? :class
Expand Down Expand Up @@ -165,19 +165,19 @@ def display_link_if_authorized(name, options = {}, html_options = {})
end
end

def authorized_edit_habtm klass, association, prefix = nil, options = {}
def authorized_edit_habtm(klass, association, prefix = nil, options = {})
if authorized_for :controller => params[:controller], :action => params[:action]
return edit_habtm(klass, association, prefix, options)
end
show_habtm klass.send(association.name.pluralize.downcase)
end

# renders a style=display based on an attribute properties
def display? attribute = true
def display?(attribute = true)
"style=#{display(attribute)}"
end

def display attribute
def display(attribute)
"display:#{attribute ? 'none' : 'inline'};"
end

Expand All @@ -187,11 +187,11 @@ def type
controller_name.singularize
end

def checked_icon condition
def checked_icon(condition)
image_tag("toggle_check.png") if condition
end

def locked_icon condition, hovertext
def locked_icon(condition, hovertext)
('<span class="glyphicon glyphicon-lock" title="%s"/>' % hovertext).html_safe if condition
end

Expand All @@ -213,7 +213,7 @@ def help_path
link_to _("Help"), :action => "welcome" if File.exist?("#{Rails.root}/app/views/#{controller_name}/welcome.html.erb")
end

def method_path method
def method_path(method)
send("#{method}_#{controller_name}_path")
end

Expand All @@ -229,7 +229,7 @@ def edit_select(object, property, options = {})
edit_inline(object, property, options.merge({:type => "edit_select"}))
end

def flot_pie_chart name, title, data, options = {}
def flot_pie_chart(name, title, data, options = {})
data = data.map { |k,v| {:label=>k.to_s.humanize, :data=>v} } if data.is_a?(Hash)
data.map{|element| element[:label] = truncate(element[:label],:length => 16)}
header = content_tag(:h4,(options[:show_title]) ? title : '', :class=>'ca pie-title', :'data-original-title'=>_("Expand the chart"), :rel=>'twipsy')
Expand All @@ -245,7 +245,7 @@ def flot_pie_chart name, title, data, options = {}
}.merge(options))
end

def flot_chart name, xaxis_label, yaxis_label, data, options = {}
def flot_chart(name, xaxis_label, yaxis_label, data, options = {})
data = data.map { |k,v| {:label=>k.to_s.humanize, :data=>v} } if data.is_a?(Hash)
content_tag(:div, nil,
{ :id => name,
Expand All @@ -259,7 +259,7 @@ def flot_chart name, xaxis_label, yaxis_label, data, options = {}
}.merge(options))
end

def flot_bar_chart name, xaxis_label, yaxis_label, data, options = {}
def flot_bar_chart(name, xaxis_label, yaxis_label, data, options = {})
i=0
ticks = nil
if data.is_a?(Array)
Expand Down
24 changes: 12 additions & 12 deletions app/helpers/audits_helper.rb
Expand Up @@ -4,7 +4,7 @@ module AuditsHelper
Location Organization Domain Subnet SmartProxy AuthSource Image Role Usergroup Bookmark ConfigGroup)

# lookup the Model representing the numerical id and return its label
def id_to_label name, change
def id_to_label(name, change)
return _("N/A") if change.nil?
case name
when "ancestry"
Expand All @@ -20,7 +20,7 @@ def id_to_label name, change
_("N/A")
end

def audit_title audit
def audit_title(audit)
type_name = audited_type audit
case type_name
when 'Puppet Class'
Expand All @@ -34,7 +34,7 @@ def audit_title audit
""
end

def details audit
def details(audit)
if audit.action == 'update'
Array.wrap(audit.audited_changes).map do |name, change|
next if change.nil? or change.to_s.empty?
Expand All @@ -54,17 +54,17 @@ def details audit
end
end

def audit_template? audit
def audit_template?(audit)
audit.auditable_type == "ConfigTemplate" && audit.action == 'update' && audit.audited_changes["template"] &&
audit.audited_changes["template"][0] != audit.audited_changes["template"][1]
end

def audit_login? audit
def audit_login?(audit)
name = audit.audited_changes.keys[0] rescue ''
name == 'last_login_on'
end

def audit_action_name audit
def audit_action_name(audit)
return audit.action == 'destroy' ? 'destroyed' : "#{audit.action}d" if main_object? audit

case audit.action
Expand All @@ -77,18 +77,18 @@ def audit_action_name audit
end
end

def audit_user audit
def audit_user(audit)
return if audit.username.nil?
login = audit.user.login rescue nil # aliasing the user method sometimes yields strings
link_to(icon_text('user', audit.username.gsub(_('User'), '')), hash_for_audits_path(:search => login ? "user = #{login}" : "username = \"#{audit.username}\""))
end

def audit_time audit
def audit_time(audit)
content_tag :span, _("%s ago") % time_ago_in_words(audit.created_at),
{ :'data-original-title' => audit.created_at.to_s(:long), :rel => 'twipsy' }
end

def audited_icon audit
def audited_icon(audit)
style = 'label-info'
style = case audit.action
when 'create'
Expand Down Expand Up @@ -116,7 +116,7 @@ def audited_icon audit
content_tag(:b, icon_text(symbol, type, :class => 'icon-white'), :class => style)
end

def audited_type audit
def audited_type(audit)
type_name = case audit.auditable_type
when 'HostClass'
'Puppet Class'
Expand All @@ -132,15 +132,15 @@ def audited_type audit
type_name.underscore.titleize
end

def audit_remote_address audit
def audit_remote_address(audit)
return if audit.remote_address.empty?
content_tag :span, :style => 'color:#999;' do
"(" + audit.remote_address + ")"
end
end

private
def main_object? audit
def main_object?(audit)
type = audit.auditable_type.split("::").last rescue ''
MainObjects.include?(type)
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/auth_source_ldaps_helper.rb
@@ -1,6 +1,6 @@
module AuthSourceLdapsHelper

def on_the_fly? authsource
def on_the_fly?(authsource)
return false if authsource.new_record?
authsource.onthefly_register?
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/bmc_helper.rb
@@ -1,6 +1,6 @@
module BmcHelper

def power_status s
def power_status(s)
if s.downcase == 'on'
"<span class='label label-success'>#{_('On')}</span>".html_safe
else
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/common_parameters_helper.rb
Expand Up @@ -9,7 +9,7 @@ def parameters_title
_("Parameters that would be associated with hosts in this %s") % (type)
end

def parameter_value_field value
def parameter_value_field(value)
source_name = value[:source_name] ? "(#{value[:source_name]})" : nil
content_tag :div, :class => "form-group condensed" do
text_area_tag("value_#{value[:safe_value]}", value[:safe_value], :rows => (value[:safe_value].to_s.lines.count || 1 rescue 1),
Expand Down

0 comments on commit 5f029ed

Please sign in to comment.