Skip to content

Upgraded Rubocop to 0.43.0. #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-10-22 08:27:54 -0400 using RuboCop version 0.33.0.
# on 2016-09-27 11:32:40 -0700 using RuboCop version 0.43.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: 6
Metrics/AbcSize:
Max: 70
Max: 67

# Offense count: 6
Metrics/CyclomaticComplexity:
Max: 11

# Offense count: 107
# Configuration parameters: AllowURI, URISchemes.
# Offense count: 114
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 170

# Offense count: 5
# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 25
@@ -28,9 +29,11 @@ Metrics/MethodLength:
Metrics/PerceivedComplexity:
Max: 11

# Offense count: 13
# Offense count: 10
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'examples/mongoid_scroll_feed.rb'
- 'lib/mongo/scrollable.rb'
- 'lib/mongoid/criterion/scrollable.rb'
@@ -40,18 +43,30 @@ Style/Documentation:
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'
- 'lib/mongoid/scroll/errors/no_such_field_error.rb'
- 'lib/mongoid/scroll/errors/unsupported_field_type_error.rb'
- 'lib/mongoid/scroll/version.rb'
- 'lib/moped/scrollable.rb'
- 'spec/support/feed/embedded_item.rb'
- 'spec/support/feed/item.rb'

# Offense count: 1
# Configuration parameters: Exclude.
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
Style/FileName:
Exclude:
- 'lib/mongoid-scroll.rb'

# Offense count: 2
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/mongoid/criterion/scrollable.rb'
- 'lib/moped/scrollable.rb'

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
EnforcedStyle: compact

# Offense count: 1
# Configuration parameters: SupportedStyles.
# SupportedStyles: snake_case, normalcase, non_integer
Style/VariableNumber:
EnforcedStyle: normalcase
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -23,6 +23,6 @@ group :development, :test do
gem 'rspec', '~> 3.0'
gem 'rspec-its'
gem 'faker'
gem 'rubocop', '0.33.0'
gem 'rubocop', '0.43.0'
gem 'mongoid-danger', '~> 0.1.0', require: false
end
2 changes: 1 addition & 1 deletion examples/mongo_ruby_driver_scroll_feed.rb
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
require 'mongoid-scroll'
require 'faker'

fail 'No Mongo Ruby Driver' unless Object.const_defined?(:Mongo)
raise 'No Mongo Ruby Driver' unless Object.const_defined?(:Mongo)

Mongo::Logger.logger = Logger.new($stdout)
Mongo::Logger.logger.level = Logger::INFO
2 changes: 1 addition & 1 deletion examples/moped_scroll_feed.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
Mongoid.connect_to 'mongoid_scroll_demo'
Mongoid.purge!

fail 'No Moped' unless Object.const_defined?(:Moped)
raise 'No Moped' unless Object.const_defined?(:Moped)

# total items to insert
total_items = 20
5 changes: 3 additions & 2 deletions lib/mongo/scrollable.rb
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ module Scrollable
def scroll(cursor = nil, options = nil, &_block)
view = self
# we don't support scrolling over a view with multiple fields
fail Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: view.sort) if view.sort && view.sort.keys.size != 1
raise Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: view.sort) if view.sort && view.sort.keys.size != 1
# scroll field and direction
scroll_field = view.sort ? view.sort.keys.first : :_id
scroll_direction = view.sort ? view.sort.values.first.to_i : 1
@@ -17,7 +17,8 @@ def scroll(cursor = nil, options = nil, &_block)
view.selector.merge(cursor.criteria),
sort: (view.sort || {}).merge(_id: scroll_direction),
skip: skip,
limit: limit)
limit: limit
)
# scroll
if block_given?
view.each do |record|
2 changes: 1 addition & 1 deletion lib/mongoid/criterion/scrollable.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ def scroll(cursor = nil, &_block)
criteria = self
# we don't support scrolling over a criteria with multiple fields
if criteria.options[:sort] && criteria.options[:sort].keys.size != 1
fail Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: criteria.options[:sort])
raise Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: criteria.options[:sort])
elsif !criteria.options.key?(:sort) || criteria.options[:sort].empty?
# introduce a default sort order if there's none
criteria = criteria.asc(:_id)
20 changes: 10 additions & 10 deletions lib/mongoid/scroll/cursor.rb
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ def criteria
else
Origin::Selector.new
end
cursor_selector.merge!('$or' => [cursor_criteria, tiebreak_criteria].compact) if cursor_criteria || tiebreak_criteria
cursor_selector['$or'] = [cursor_criteria, tiebreak_criteria].compact if cursor_criteria || tiebreak_criteria
cursor_selector.__evolve_object_id__
end

@@ -43,16 +43,16 @@ def parse(value)
return unless value
parts = value.split(':')
unless parts.length >= 2
fail Mongoid::Scroll::Errors::InvalidCursorError.new(cursor: value)
raise Mongoid::Scroll::Errors::InvalidCursorError.new(cursor: value)
end
id = parts[-1]
value = parts[0...-1].join(':')
@value = Mongoid::Scroll::Cursor.parse_field_value(field_type, field_name, value)
if Mongoid::Compatibility::Version.mongoid3?
@tiebreak_id = Moped::BSON::ObjectId(id)
else
@tiebreak_id = BSON::ObjectId.from_string(id)
end
@tiebreak_id = if Mongoid::Compatibility::Version.mongoid3?
Moped::BSON::ObjectId(id)
else
BSON::ObjectId.from_string(id)
end
end

class << self
@@ -62,7 +62,7 @@ def extract_field_options(options)
elsif options && (field = options[:field])
[field.type.to_s, field.name.to_s]
else
fail ArgumentError.new 'Missing options[:field_name] and/or options[:field_type].'
raise ArgumentError.new 'Missing options[:field_name] and/or options[:field_type].'
end
end

@@ -76,7 +76,7 @@ def parse_field_value(field_type, field_name, value)
when 'Float' then value.to_f
when 'Integer' then value.to_i
else
fail Mongoid::Scroll::Errors::UnsupportedFieldTypeError.new(field: field_name, type: field_type)
raise Mongoid::Scroll::Errors::UnsupportedFieldTypeError.new(field: field_name, type: field_type)
end
end

@@ -89,7 +89,7 @@ def transform_field_value(field_type, field_name, value)
when 'Float' then value.to_f
when 'Integer' then value.to_i
else
fail Mongoid::Scroll::Errors::UnsupportedFieldTypeError.new(field: field_name, type: field_type)
raise Mongoid::Scroll::Errors::UnsupportedFieldTypeError.new(field: field_name, type: field_type)
end
end
end
2 changes: 1 addition & 1 deletion lib/mongoid/scroll/errors/base.rb
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ def compose_message(key, attributes = {})

private

BASE_KEY = 'mongoid.scroll.errors.messages' #:nodoc:
BASE_KEY = 'mongoid.scroll.errors.messages'.freeze #:nodoc:

# Given the key of the specific error and the options hash, translate the
# message.
2 changes: 1 addition & 1 deletion lib/mongoid/scroll/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Mongoid
module Scroll
VERSION = '0.3.5'
VERSION = '0.3.5'.freeze
end
end
2 changes: 1 addition & 1 deletion lib/moped/scrollable.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ def scroll(cursor = nil, options = nil, &_block)
query.operation.limit = operation.limit
# we don't support scrolling over a criteria with multiple fields
if query.operation.selector['$orderby'] && query.operation.selector['$orderby'].keys.size != 1
fail Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: query.operation.selector['$orderby'])
raise Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: query.operation.selector['$orderby'])
elsif !query.operation.selector.key?('$orderby') || query.operation.selector['$orderby'].empty?
# introduce a default sort order if there's none
query.sort(_id: 1)
4 changes: 2 additions & 2 deletions spec/mongoid/criteria_spec.rb
Original file line number Diff line number Diff line change
@@ -132,8 +132,8 @@
end
it 'merges cursor criteria when no sort field is given' do
criteria = Feed::Item.where(:a_time.gt => Time.new(2013, 7, 22, 1, 2, 3))
feed_item_1 = Feed::Item.where(name: 'Feed Item 1').first
cursor_input = "#{feed_item_1.id}:#{feed_item_1.id}"
feed_item = Feed::Item.where(name: 'Feed Item 1').first
cursor_input = "#{feed_item.id}:#{feed_item.id}"
field_type = Mongoid::Compatibility::Version.mongoid3? ? Moped::BSON::ObjectId : BSON::ObjectId
cursor_options = { field_type: field_type, field_name: '_id', direction: 1 }
cursor = Mongoid::Scroll::Cursor.new(cursor_input, cursor_options)
44 changes: 22 additions & 22 deletions spec/mongoid/scroll_cursor_spec.rb
Original file line number Diff line number Diff line change
@@ -26,12 +26,12 @@
its(:criteria) do
if Mongoid::Compatibility::Version.mongoid3?
should eq('$or' => [
{ '_id' => { '$gt' => Moped::BSON::ObjectId("#{feed_item.id}") } }
])
{ '_id' => { '$gt' => Moped::BSON::ObjectId(feed_item.id.to_s) } }
])
else
should eq('$or' => [
{ '_id' => { '$gt' => BSON::ObjectId("#{feed_item.id}") } }
])
{ '_id' => { '$gt' => BSON::ObjectId(feed_item.id.to_s) } }
])
end
end
end
@@ -44,9 +44,9 @@
its(:tiebreak_id) { should eq feed_item.id }
its(:criteria) do
should eq('$or' => [
{ 'a_string' => { '$gt' => feed_item.a_string } },
{ 'a_string' => feed_item.a_string, '_id' => { '$gt' => feed_item.id } }
])
{ 'a_string' => { '$gt' => feed_item.a_string } },
{ 'a_string' => feed_item.a_string, '_id' => { '$gt' => feed_item.id } }
])
end
end
context 'an integer field cursor' do
@@ -58,9 +58,9 @@
its(:tiebreak_id) { should eq feed_item.id }
its(:criteria) do
should eq('$or' => [
{ 'a_integer' => { '$gt' => feed_item.a_integer } },
{ 'a_integer' => feed_item.a_integer, '_id' => { '$gt' => feed_item.id } }
])
{ 'a_integer' => { '$gt' => feed_item.a_integer } },
{ 'a_integer' => feed_item.a_integer, '_id' => { '$gt' => feed_item.id } }
])
end
end
context 'a date/time field cursor' do
@@ -73,9 +73,9 @@
its(:to_s) { should eq "#{feed_item.a_datetime.utc.to_i}:#{feed_item.id}" }
its(:criteria) do
should eq('$or' => [
{ 'a_datetime' => { '$gt' => feed_item.a_datetime } },
{ 'a_datetime' => feed_item.a_datetime, '_id' => { '$gt' => feed_item.id } }
])
{ 'a_datetime' => { '$gt' => feed_item.a_datetime } },
{ 'a_datetime' => feed_item.a_datetime, '_id' => { '$gt' => feed_item.id } }
])
end
end
context 'a date field cursor' do
@@ -88,9 +88,9 @@
its(:to_s) { should eq "#{feed_item.a_date.to_datetime.to_i}:#{feed_item.id}" }
its(:criteria) do
should eq('$or' => [
{ 'a_date' => { '$gt' => feed_item.a_date.to_datetime } },
{ 'a_date' => feed_item.a_date.to_datetime, '_id' => { '$gt' => feed_item.id } }
])
{ 'a_date' => { '$gt' => feed_item.a_date.to_datetime } },
{ 'a_date' => feed_item.a_date.to_datetime, '_id' => { '$gt' => feed_item.id } }
])
end
end
context 'a time field cursor' do
@@ -103,9 +103,9 @@
its(:to_s) { should eq "#{feed_item.a_time.to_i}:#{feed_item.id}" }
its(:criteria) do
should eq('$or' => [
{ 'a_time' => { '$gt' => feed_item.a_time } },
{ 'a_time' => feed_item.a_time, '_id' => { '$gt' => feed_item.id } }
])
{ 'a_time' => { '$gt' => feed_item.a_time } },
{ 'a_time' => feed_item.a_time, '_id' => { '$gt' => feed_item.id } }
])
end
end
context 'a time field cursor with a field option' do
@@ -118,9 +118,9 @@
its(:to_s) { should eq "#{feed_item.a_time.to_i}:#{feed_item.id}" }
its(:criteria) do
should eq('$or' => [
{ 'a_time' => { '$gt' => feed_item.a_time } },
{ 'a_time' => feed_item.a_time, '_id' => { '$gt' => feed_item.id } }
])
{ 'a_time' => { '$gt' => feed_item.a_time } },
{ 'a_time' => feed_item.a_time, '_id' => { '$gt' => feed_item.id } }
])
end
end
context 'an array field cursor' do