Skip to content
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

style(Style/MultilineBlockChain): manual #97

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -815,14 +815,6 @@ Style/ArgumentsForwarding:
- 'lib/mongoid/association/referenced/has_many/enumerable.rb'
- 'lib/mongoid/association/referenced/has_many/proxy.rb'

# Offense count: 5
Style/MultilineBlockChain:
Exclude:
- 'lib/mongoid/association/eager.rb'
- 'lib/mongoid/contextual/memory.rb'
- 'spec/mongoid/changeable_spec.rb'
- 'spec/mongoid/document_spec.rb'

# Offense count: 4
Style/OpenStructUse:
Exclude:
Expand Down
8 changes: 6 additions & 2 deletions lib/mongoid/association/eager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ def set_on_parent(id, element)
#
# @return [ Hash ] hash with grouped documents.
def grouped_docs
@grouped_docs[@association.name] ||= @docs.group_by do |doc|
return @grouped_docs[@association.name] if @grouped_docs.key?(@association.name)

docs_regroup = @docs.group_by do |doc|
doc.send(group_by_key) if doc.respond_to?(group_by_key)
end.reject { |k, _| k.nil? }
end

@grouped_docs[@association.name] = docs_regroup.reject { |k, _| k.nil? }
end

# Group the documents and return the keys.
Expand Down
13 changes: 11 additions & 2 deletions lib/mongoid/association/referenced/has_many/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ def build(attributes = {}, type = nil)
# @return [ Mongoid::Document ] The matching document.
def delete(document)
execute_callbacks_around(:remove, document) do
result = _target.delete(document) do |doc|
deleted_doc = _target.delete(document) do |doc|
if doc
unbind_one(doc)
cascade!(doc) unless _assigning?
end
end

reset_unloaded
result
deleted_doc
end
end

Expand Down Expand Up @@ -377,6 +377,15 @@ def append(document)
end
end

def delete_document_from_target(document)
_target.delete(document) do |doc|
if doc
unbind_one(doc)
cascade!(doc) unless _assigning?
end
end
end

# Execute before/after add callbacks around the block unless the objects
# already have a persisted association.
#
Expand Down
14 changes: 4 additions & 10 deletions spec/mongoid/changeable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2042,11 +2042,8 @@

after do
callback_kinds = %i[before after].freeze
Acolyte._save_callbacks.select do |callback|
callback_kinds.include?(callback.kind)
end.each do |callback|
Acolyte._save_callbacks.delete(callback)
end
callbacks_to_delete = Acolyte._save_callbacks.select { |callback| callback_kinds.include?(callback.kind) }
callbacks_to_delete.each { |callback| Acolyte._save_callbacks.delete(callback) }
end

it 'does not retain the changes until after all callbacks' do
Expand Down Expand Up @@ -2074,11 +2071,8 @@

after do
callback_kinds = %i[before after].freeze
Acolyte._save_callbacks.select do |callback|
callback_kinds.include?(callback.kind)
end.each do |callback|
Acolyte._save_callbacks.delete(callback)
end
callbacks_to_delete = Acolyte._save_callbacks.select { |callback| callback_kinds.include?(callback.kind) }
callbacks_to_delete.each { |callback| Acolyte._save_callbacks.delete(callback) }
end

it 'does not retain the changes until after all callbacks' do
Expand Down
16 changes: 8 additions & 8 deletions spec/mongoid/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@
end

let(:new_klass) do
Class.new do
new_klass = Class.new do
class << self; attr_accessor :name; end
end.tap { |new_klass| new_klass.name = new_klass_name }
end
new_klass.name = new_klass_name
new_klass
end

let(:new_model) do
new_klass.tap do
new_klass.send(:include, described_class)
end
new_klass.send(:include, described_class)
new_klass
end

let(:twice_a_new_model) do
new_klass.tap do
2.times { new_klass.send(:include, described_class) }
end
2.times { new_klass.send(:include, described_class) }
new_klass
end

context 'when Document has been included in a model' do
Expand Down
Loading