Skip to content

Commit

Permalink
Improve rubocop
Browse files Browse the repository at this point in the history
Update rubocop and add rubocop settings
  • Loading branch information
Gustavo Bazan committed Apr 26, 2016
1 parent 883b295 commit 6e683b9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,8 @@
inherit_from: .rubocop_todo.yml

AllCops:
Include:
- '**/Rakefile'
Exclude:
- 'bin/**/*'
- 'spec/**/*'
18 changes: 18 additions & 0 deletions .rubocop_todo.yml
@@ -0,0 +1,18 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-04-26 11:10:05 -0500 using RuboCop version 0.39.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Lint/HandleExceptions:
Exclude:
- 'lib/fuzzy_where.rb'

# Offense count: 3
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 86
8 changes: 4 additions & 4 deletions lib/fuzzy_where/active_record_model_extension.rb
Expand Up @@ -5,20 +5,20 @@ module FuzzyWhere
# Methods to extend ActiveRecord
module ActiveRecordModelExtension
extend ActiveSupport::Concern

define_method(FuzzyWhere.config.where_method_name) do |conditions|
conditions ||= {}
validate_conditions(conditions)
FuzzyRelationBuilder.new(quoted_table_name, where(nil), conditions)
.build
.build
end

private

def validate_conditions(conditions)
return if conditions.respond_to?(:key)
fail ArgumentError,
"conditions must be a Hash, got #{conditions.inspect}"
raise ArgumentError,
"conditions must be a Hash, got #{conditions.inspect}"
end
end
end
10 changes: 5 additions & 5 deletions lib/fuzzy_where/config.rb
Expand Up @@ -41,7 +41,7 @@ class Configuration #:nodoc:
# @return [Hash] fuzzy predicate definition
def fuzzy_predicate(key)
@fuzzy_predicates = load_yml(predicates_file)
@fuzzy_predicates["#{key}"]
@fuzzy_predicates[key.to_s]
end

private
Expand All @@ -50,14 +50,14 @@ def fuzzy_predicate(key)
# @param path [Object] predicates definition location
# @return [Hash] fuzzy predicate definitions
def load_yml(path)
fail ConfigError, 'The configuration file is not defined.' unless path
raise ConfigError, 'The configuration file is not defined.' unless path
file = path.is_a?(Pathname) ? path : Pathname.new(path)
if !file.exist?
fail ConfigError, "The configuration file #{path} was not found."
raise ConfigError, "The configuration file #{path} was not found."
elsif !file.file?
fail ConfigError, "The configuration file #{path} is not a file."
raise ConfigError, "The configuration file #{path} is not a file."
elsif !file.readable?
fail ConfigError, "The configuration file #{path} is not readable."
raise ConfigError, "The configuration file #{path} is not readable."
end
HashWithIndifferentAccess.new(YAML.load_file(file))
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fuzzy_where/fuzzy_relation_builder.rb
Expand Up @@ -70,13 +70,13 @@ def process_conditions

def load_fuzzy_predicate_definition(predicate)
pred_def = FuzzyWhere.config.fuzzy_predicate(predicate)
fail FuzzyError, "couldn't find fuzzy definition" unless pred_def
raise FuzzyError, "couldn't find fuzzy definition" unless pred_def
pred_def
end

def derivate_condition(column, pred_def)
FuzzyDerivation.new(@relation, @table, column, pred_def)
.derivative_condition
.derivative_condition
end

def membership_degree_function(column, pred_def)
Expand Down

0 comments on commit 6e683b9

Please sign in to comment.