Skip to content

Commit

Permalink
Make code compliant to rubocop 0.73
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jul 27, 2019
1 parent c49ad66 commit 3ac27f7
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# alphabetically
inherit_from:
- https://raw.githubusercontent.com/hanami/devtools/master/.rubocop.yml
Naming/RescuedExceptionsVariableName:
PreferredName: "exception"
Style/RescueStandardError:
Enabled: false
Style/DateTime:
Expand Down
8 changes: 4 additions & 4 deletions lib/hanami/entity/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ def initialize(type = nil, &blk)
# @api private
def call(attributes)
schema.call(attributes)
rescue Dry::Types::SchemaError => e
raise TypeError.new(e.message)
rescue Dry::Types::MissingKeyError, Dry::Types::UnknownKeysError => e
raise ArgumentError.new(e.message)
rescue Dry::Types::SchemaError => exception
raise TypeError.new(exception.message)
rescue Dry::Types::MissingKeyError, Dry::Types::UnknownKeysError => exception
raise ArgumentError.new(exception.message)
end

# Check if the attribute is known
Expand Down
8 changes: 4 additions & 4 deletions lib/hanami/model/associations/has_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ def initialize(repository, source, target, subject, scope = nil)
def create(data)
entity.new(command(:create, aggregate(target), mapper: nil, use: [:timestamps])
.call(serialize(data)))
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

# @since 0.7.0
# @api private
def add(data)
command(:create, relation(target), use: [:timestamps])
.call(associate(serialize(data)))
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

# @since 0.7.0
Expand Down
12 changes: 6 additions & 6 deletions lib/hanami/model/associations/has_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ def create(data)
entity.new(
command(:create, aggregate(target), mapper: nil).call(serialize(data))
)
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

def add(data)
command(:create, relation(target), mapper: nil).call(associate(serialize(data)))
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

def update(data)
command(:update, relation(target), mapper: nil)
.by_pk(
one.public_send(relation(target).primary_key)
).call(serialize(data))
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

def delete
Expand Down
4 changes: 2 additions & 2 deletions lib/hanami/model/associations/many_to_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def where(condition)
def add(*data)
command(:create, relation(through), use: [:timestamps])
.call(associate(serialize(data)))
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

# @since 1.1.0
Expand Down
10 changes: 5 additions & 5 deletions lib/hanami/model/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def logger=(value)
# @api private
def rom
@rom ||= ROM::Configuration.new(@backend, @url, infer_relations: false)
rescue => e
raise UnknownDatabaseAdapterError.new(@url) if e.message =~ /adapters/
rescue => exception
raise UnknownDatabaseAdapterError.new(@url) if exception.message =~ /adapters/

raise e
raise exception
end

# @raise [Hanami::Model::UnknownDatabaseAdapterError] if `url` is blank,
Expand All @@ -157,8 +157,8 @@ def load!(repositories, &blk) # rubocop:disable Metrics/AbcSize
container = ROM.container(rom)
define_entities_mappings(container, repositories)
container
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

# @since 1.0.0
Expand Down
4 changes: 2 additions & 2 deletions lib/hanami/model/mapped_relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def initialize(relation)
# end
def [](attribute)
@relation[attribute]
rescue KeyError => e
raise UnknownAttributeError.new(e.message)
rescue KeyError => exception
raise UnknownAttributeError.new(exception.message)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/hanami/model/migrator/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def migrate(migrations, version)
version = Integer(version) unless version.nil?

Sequel::Migrator.run(connection.raw, migrations, target: version, allow_missing_migration_files: true)
rescue Sequel::Migrator::Error => e
raise MigrationError.new(e.message)
rescue Sequel::Migrator::Error => exception
raise MigrationError.new(exception.message)
end

# @since 1.1.0
Expand All @@ -91,8 +91,8 @@ def rollback(migrations, steps)
version = version_to_rollback(table, steps)

Sequel::Migrator.run(connection.raw, migrations, target: version, allow_missing_migration_files: true)
rescue Sequel::Migrator::Error => e
raise MigrationError.new(e.message)
rescue Sequel::Migrator::Error => exception
raise MigrationError.new(exception.message)
end

# Load database schema.
Expand Down
12 changes: 6 additions & 6 deletions lib/hanami/model/migrator/mysql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class MySQLAdapter < Adapter
# @api private
def create
new_connection(global: true).run %(CREATE DATABASE `#{database}`;)
rescue Sequel::DatabaseError => e
message = if e.message.match(/database exists/) # rubocop:disable Performance/RedundantMatch
rescue Sequel::DatabaseError => exception
message = if exception.message.match(/database exists/)
DB_CREATION_ERROR
else
e.message
exception.message
end

raise MigrationError.new(message)
Expand All @@ -34,11 +34,11 @@ def create
# @api private
def drop
new_connection(global: true).run %(DROP DATABASE `#{database}`;)
rescue Sequel::DatabaseError => e
message = if e.message.match(/doesn\'t exist/) # rubocop:disable Performance/RedundantMatch
rescue Sequel::DatabaseError => exception
message = if exception.message.match(/doesn\'t exist/)
"Cannot find database: #{database}"
else
e.message
exception.message
end

raise MigrationError.new(message)
Expand Down
4 changes: 2 additions & 2 deletions lib/hanami/model/migrator/postgres_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def call_db_command(command)
Open3.popen3(*command_with_credentials(command)) do |_stdin, _stdout, stderr, wait_thr|
raise MigrationError.new(modified_message(stderr.read)) unless wait_thr.value.success? # wait_thr.value is the exit status
end
rescue SystemCallError => e
raise MigrationError.new(modified_message(e.message))
rescue SystemCallError => exception
raise MigrationError.new(modified_message(exception.message))
end
end

Expand Down
16 changes: 8 additions & 8 deletions lib/hanami/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ module Commands
# entity.id # => nil - It doesn't mutate original entity
def create(*args)
super
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

# Update a record
Expand Down Expand Up @@ -386,8 +386,8 @@ def create(*args)
# entity.id # => nil - It doesn't mutate original entity
def update(*args)
super
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

# Delete a record
Expand All @@ -405,8 +405,8 @@ def update(*args)
# user = repository.delete(user.id)
def delete(*args)
super
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end
end

Expand Down Expand Up @@ -435,8 +435,8 @@ def initialize
# user = repository.find(user.id)
def find(id)
root.by_pk(id).as(:entity).one
rescue => e
raise Hanami::Model::Error.for(e)
rescue => exception
raise Hanami::Model::Error.for(exception)
end

# Return all the records for the relation
Expand Down
2 changes: 1 addition & 1 deletion spec/support/platform/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Platform
class Matcher
class Nope < Hanami::Utils::BasicObject
def or(other, &blk)
blk.nil? ? other : blk.call # rubocop:disable Performance/RedundantBlockCall
blk.nil? ? other : blk.call
end

# rubocop:disable Style/MethodMissingSuper
Expand Down

0 comments on commit 3ac27f7

Please sign in to comment.