Skip to content

Commit

Permalink
Add changelog and fix some rubocop lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Startouf committed Jun 9, 2019
1 parent 6a93b6e commit 328ba98
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
47 changes: 24 additions & 23 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-08-12 23:34:44 -0700 using RuboCop version 0.48.1.
# on 2019-06-09 13:41:12 +0200 using RuboCop version 0.60.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: 7
# Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/DuplicatedGem:
Exclude:
- 'Gemfile'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect.
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Lint/EndAlignment:
Layout/EndAlignment:
Exclude:
- 'lib/mongoid/history/options.rb'

Expand All @@ -32,12 +32,13 @@ Lint/ParenthesesAsGroupedExpression:
- 'spec/integration/integration_spec.rb'
- 'spec/integration/nested_embedded_polymorphic_documents_spec.rb'

# Offense count: 21
# Offense count: 22
Metrics/AbcSize:
Max: 52

# Offense count: 118
# Offense count: 122
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 837

Expand All @@ -50,26 +51,28 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 13

# Offense count: 392
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 688

# Offense count: 16
# Configuration parameters: CountComments.
# Offense count: 17
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 23

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 182
Max: 191

# Offense count: 6
Metrics/PerceivedComplexity:
Max: 15

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'Dangerfile'
- 'lib/mongoid-history.rb'

# Offense count: 12
Style/Documentation:
Exclude:
Expand All @@ -91,15 +94,13 @@ Style/EachWithObject:
- 'lib/mongoid/history/trackable.rb'
- 'lib/mongoid/history/tracker.rb'

# Offense count: 2
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Style/FileName:
Exclude:
- 'Dangerfile'
- 'lib/mongoid-history.rb'

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'lib/mongoid/history/tracker.rb'

# Offense count: 404
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 688
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.8.2 (Next)

* [#232](https://github.com/mongoid/mongoid-history/pull/232): Bug/187 track changes from embedded documents (not deeply nested) - [@Startouf](https://github.com/Startouf).
* [#227](https://github.com/mongoid/mongoid-history/pull/227): Store options in inheritable class attributes - [@jnfeinstein](https://github.com/jnfeinstein).
* [#229](https://github.com/mongoid/mongoid-history/pull/229), [#225](https://github.com/mongoid/mongoid-history/pull/225): Fixed inheritance of `history_trackable_options` - [@jnfeinstein](https://github.com/jnfeinstein).
* Your contribution here.
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ gem 'mongoid-compatibility'

group :development, :test do
gem 'bundler'
gem 'byebug'
gem 'pry'
gem 'rake', '< 11.0'
end
Expand Down
19 changes: 14 additions & 5 deletions lib/mongoid/history/attributes/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Mongoid
module History
module Attributes
class Update < ::Mongoid::History::Attributes::Base
# @example
# @example when both an attribute `foo` and a child's attribute `nested_bar.baz` are changed
#
# {
# 'foo' => ['foo_before_changes', 'foo_after_changes']
Expand Down Expand Up @@ -38,9 +38,16 @@ def changes_from_children
embeds_one_changes_from_embedded_documents
end

# @example for Parent has_one child's name changed from "todd" to "mario"
# Retrieve the list of changes applied directly to the nested documents
#
# {"child"=>{"name"=>["todd", "mario"]}}
# @example when a child's name is changed from "todd" to "mario"
#
# child = Child.new(name: 'todd')
# Parent.create(child: child)
# child.name = "Mario"
#
# embeds_one_changes_from_embedded_documents # when called from "Parent"
# # => { "child.name"=>["todd", "mario"] }
#
# @return [Hash<String, Array<(?,?)>] changes of embeds_ones from embedded documents
def embeds_one_changes_from_embedded_documents
Expand All @@ -52,7 +59,8 @@ def embeds_one_changes_from_embedded_documents
rel = aliased_fields.key(rel) || rel
obj = trackable.send(rel)
next if !obj || (obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present?)
embedded_doc_field_changes = obj.changes.each do |k,v|

obj.changes.each do |k, v|
embedded_doc_changes["#{rel}.#{k}"] = [v.first, v.last]
end
end
Expand All @@ -70,7 +78,7 @@ def embeds_one_changes_from_parent(relation, value)
original_value = value[0][paranoia_field].present? ? {} : format_embeds_one_relation(relation, value[0])
modified_value = value[1][paranoia_field].present? ? {} : format_embeds_one_relation(relation, value[1])
return if original_value == modified_value
[original_value, modified_value]

{ relation => [original_value, modified_value] }
end

Expand All @@ -87,6 +95,7 @@ def embeds_many_changes_from_parent(relation, value)
modified_value = value[1].reject { |rel| rel[paranoia_field].present? }
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
return if original_value == modified_value

{ relation => [original_value, modified_value] }
end
end
Expand Down

0 comments on commit 328ba98

Please sign in to comment.