Skip to content

Commit

Permalink
Upgrade to new rubocop.
Browse files Browse the repository at this point in the history
  • Loading branch information
martini committed Mar 1, 2016
1 parent 8df44fd commit ba3f868
Show file tree
Hide file tree
Showing 64 changed files with 221 additions and 219 deletions.
2 changes: 1 addition & 1 deletion app/controllers/tickets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def selector
def stats

if !params[:user_id] && !params[:organization_id]
fail 'Need user_id or organization_id as param'
raise 'Need user_id or organization_id as param'
end

# permission check
Expand Down
2 changes: 1 addition & 1 deletion app/models/activity_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def self.add(data)
if data[:role]
role = Role.lookup(name: data[:role])
if !role
fail "No such Role #{data[:role]}"
raise "No such Role #{data[:role]}"
end
role_id = role.id
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/application_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def check_attributes_protected
def self.param_cleanup(params, newObject = false)

if params.nil?
fail "No params for #{self}!"
raise "No params for #{self}!"
end

# ignore id for new objects
Expand Down Expand Up @@ -377,7 +377,7 @@ def self.lookup(data)
return
end

fail 'Need name, id, login or email for lookup()'
raise 'Need name, id, login or email for lookup()'
end

=begin
Expand Down Expand Up @@ -535,7 +535,7 @@ def self.create_or_update(data)
record.save
return record
else
fail 'Need name, login, email or locale for create_or_update()'
raise 'Need name, login, email or locale for create_or_update()'
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def self.parse(location)
if location =~ /^http/i
result = UserAgent.get(location)
if !result.success?
fail result.error
raise result.error
end
cal_file = result.body
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/channel/driver/facebook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def send(options, fb_object_id, article, _notification = false)
access_token = page['access_token']
}
if !access_token
fail "No access_token found for fb_object_id: #{fb_object_id}"
raise "No access_token found for fb_object_id: #{fb_object_id}"
end
client = Facebook.new(access_token)
client.from_article(article)
Expand Down
4 changes: 2 additions & 2 deletions app/models/channel/driver/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def stream_instance(channel)

def stream
sync = @channel.options['sync']
fail 'Need channel.options[\'sync\'] for account, but no params found' if !sync
raise 'Need channel.options[\'sync\'] for account, but no params found' if !sync

filter = {}
if sync['search']
Expand Down Expand Up @@ -315,7 +315,7 @@ def fetch_direct_messages
def check_external_credential(options)
if options[:auth] && options[:auth][:external_credential_id]
external_credential = ExternalCredential.find_by(id: options[:auth][:external_credential_id])
fail "No such ExternalCredential.find(#{options[:auth][:external_credential_id]})" if !external_credential
raise "No such ExternalCredential.find(#{options[:auth][:external_credential_id]})" if !external_credential
options[:auth][:consumer_key] = external_credential.credentials['consumer_key']
options[:auth][:consumer_secret] = external_credential.credentials['consumer_secret']
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def self.load
}
)

fail "Can't load locales from #{url}" if !result
fail "Can't load locales from #{url}: #{result.error}" if !result.success?
raise "Can't load locales from #{url}" if !result
raise "Can't load locales from #{url}: #{result.error}" if !result.success?

ActiveRecord::Base.transaction do
result.data.each {|locale|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def perform

# send email
if !ticket.group.email_address_id
fail "Can't send email, no email address definde for group id '#{ticket.group.id}'"
raise "Can't send email, no email address definde for group id '#{ticket.group.id}'"
elsif !ticket.group.email_address.channel_id
fail "Can't send email, no channel definde for email_address id '#{ticket.group.email_address_id}'"
raise "Can't send email, no channel definde for email_address id '#{ticket.group.email_address_id}'"
end

channel = ticket.group.email_address.channel
Expand Down
8 changes: 4 additions & 4 deletions app/models/observer/ticket/article/communicate_facebook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def after_create(record)
return if type['name'] !~ /\Afacebook/

ticket = Ticket.lookup(id: record.ticket_id)
fail "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences
fail "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id']
raise "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences
raise "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id']
channel = Channel.lookup(id: ticket.preferences['channel_id'])
fail "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Afacebook/i
raise "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Afacebook/i

# check source object id
ticket = record.ticket
if !ticket.preferences['channel_fb_object_id']
fail "fb object id is missing in ticket.preferences['channel_fb_object_id'] for Ticket.find(#{ticket.id})"
raise "fb object id is missing in ticket.preferences['channel_fb_object_id'] for Ticket.find(#{ticket.id})"
end

# fill in_reply_to
Expand Down
10 changes: 5 additions & 5 deletions app/models/observer/ticket/article/communicate_twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def after_create(record)
return if type['name'] !~ /\Atwitter/i

ticket = Ticket.lookup(id: record.ticket_id)
fail "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences
fail "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id']
raise "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences
raise "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id']
channel = Channel.lookup(id: ticket.preferences['channel_id'])
fail "No such channel id #{ticket.preferences['channel_id']}" if !channel
fail "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Atwitter/i
raise "No such channel id #{ticket.preferences['channel_id']}" if !channel
raise "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Atwitter/i
tweet = channel.deliver(
type: type['name'],
to: record.to,
Expand Down Expand Up @@ -54,7 +54,7 @@ def after_create(record)
record.preferences[:twitter_mention_ids] = twitter_mention_ids
end
else
fail "Unknown tweet type '#{tweet.class}'"
raise "Unknown tweet type '#{tweet.class}'"
end

record.message_id = tweet.id
Expand Down
2 changes: 1 addition & 1 deletion app/models/observer/ticket/article/fillup_from_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def before_create(record)
# set sender
email_address = ticket.group.email_address
if !email_address
fail "No email address found for group '#{ticket.group.name}'"
raise "No email address found for group '#{ticket.group.name}'"
end
system_sender = "#{email_address.realname} <#{email_address.email}>"
if Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName'
Expand Down
2 changes: 1 addition & 1 deletion app/models/observer/ticket/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def self.get_uniq_changes(events)
end
end
else
fail "unknown object for notification #{event[:name]}"
raise "unknown object for notification #{event[:name]}"
end
}
list_objects
Expand Down
2 changes: 1 addition & 1 deletion app/models/observer/ticket/notification/background_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def perform
elsif @p[:type] == 'escalation_warning'
template = 'ticket_escalation_warning'
else
fail "unknown type for notification #{@p[:type]}"
raise "unknown type for notification #{@p[:type]}"
end

NotificationFactory.notification(
Expand Down
18 changes: 9 additions & 9 deletions app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def self._package_base_dir?(package_base_dir)
package = entry.sub(%r{^.*/(.+?)\.szpm$}, '\1')
end
if package == false
fail "Can't link package, '#{package_base_dir}' is no package source directory!"
raise "Can't link package, '#{package_base_dir}' is no package source directory!"
end
logger.debug package.inspect
package
Expand Down Expand Up @@ -184,7 +184,7 @@ def self.link(package_base_dir)
if File.file?(entry.to_s) && (File.file?(dest.to_s) && !File.symlink?(dest.to_s))
backup_file = dest.to_s + '.link_backup'
if File.exist?(backup_file)
fail "Can't link #{entry} -> #{dest}, destination and .link_backup already exists!"
raise "Can't link #{entry} -> #{dest}, destination and .link_backup already exists!"
else
logger.info "Create backup file of #{dest} -> #{backup_file}."
File.rename(dest.to_s, backup_file)
Expand Down Expand Up @@ -243,10 +243,10 @@ def self.install(data)
if package_db
if !data[:reinstall]
if Gem::Version.new(package_db.version) == Gem::Version.new(meta[:version])
fail "Package '#{meta[:name]}-#{meta[:version]}' already installed!"
raise "Package '#{meta[:name]}-#{meta[:version]}' already installed!"
end
if Gem::Version.new(package_db.version) > Gem::Version.new(meta[:version])
fail "Newer version (#{package_db.version}) of package '#{meta[:name]}-#{meta[:version]}' already installed!"
raise "Newer version (#{package_db.version}) of package '#{meta[:name]}-#{meta[:version]}' already installed!"
end
end

Expand Down Expand Up @@ -306,7 +306,7 @@ def self.install(data)
def self.reinstall(package_name)
package = Package.find_by(name: package_name)
if !package
fail "No such package '#{package_name}'"
raise "No such package '#{package_name}'"
end
file = _get_bin(package.name, package.version)
install(string: file, reinstall: true)
Expand Down Expand Up @@ -367,7 +367,7 @@ def self._get_bin(name, version)
version: version,
)
if !package
fail "No such package '#{name}' version '#{version}'"
raise "No such package '#{name}' version '#{version}'"
end
list = Store.list(
object: 'Package',
Expand All @@ -376,10 +376,10 @@ def self._get_bin(name, version)

# find file
if !list || !list.first
fail "No such file in storage list #{name} #{version}"
raise "No such file in storage list #{name} #{version}"
end
if !list.first.content
fail "No such file in storage #{name} #{version}"
raise "No such file in storage #{name} #{version}"
end
list.first.content
end
Expand Down Expand Up @@ -497,7 +497,7 @@ def self.migrate(package, direction = 'normal')
name = $2
end
if !version || !name
fail "Invalid package migration '#{migration}'"
raise "Invalid package migration '#{migration}'"
end

# down
Expand Down
4 changes: 2 additions & 2 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Setting < ApplicationModel
def self.set(name, value)
setting = Setting.find_by( name: name )
if !setting
fail "Can't find config setting '#{name}'"
raise "Can't find config setting '#{name}'"
end
setting.state_current = { value: value }
setting.save
Expand Down Expand Up @@ -68,7 +68,7 @@ def self.get(name)
def self.reset(name)
setting = Setting.find_by( name: name )
if !setting
fail "Can't find config setting '#{name}'"
raise "Can't find config setting '#{name}'"
end
setting.state_current = setting.state_initial
setting.save
Expand Down
4 changes: 2 additions & 2 deletions app/models/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def self.remove_item(store_id)
def content
file = Store::File.find_by(id: store_file_id)
if !file
fail "No such file #{store_file_id}!"
raise "No such file #{store_file_id}!"
end
file.content
end

def provider
file = Store::File.find_by(id: store_file_id)
if !file
fail "No such file #{store_file_id}!"
raise "No such file #{store_file_id}!"
end
file.provider
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/store/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.add(data, verify = true)
# load backend based on config
adapter_name = Setting.get('storage_provider') || 'DB'
if !adapter_name
fail 'Missing storage_provider setting option'
raise 'Missing storage_provider setting option'
end
adapter = load_adapter("Store::Provider::#{adapter_name}")
adapter.add(data, sha)
Expand All @@ -40,7 +40,7 @@ def self.add(data, verify = true)
read_data = adapter.get(sha)
read_sha = Digest::SHA256.hexdigest(read_data)
if sha != read_sha
fail "Content not written correctly (provider #{adapter_name})."
raise "Content not written correctly (provider #{adapter_name})."
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/store/provider/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.add(data, sha)
# check sha
local_sha = Digest::SHA256.hexdigest(get(sha))
if sha != local_sha
fail "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}"
raise "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}"
end

true
Expand All @@ -29,15 +29,15 @@ def self.get(sha)
location = get_location(sha)
Rails.logger.debug "read from fs #{location}"
if !File.exist?(location)
fail "ERROR: No such file #{location}"
raise "ERROR: No such file #{location}"
end
data = File.open(location, 'rb')
content = data.read

# check sha
local_sha = Digest::SHA256.hexdigest(content)
if local_sha != sha
fail "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}"
raise "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}"
end
content
end
Expand Down
Loading

0 comments on commit ba3f868

Please sign in to comment.