Skip to content

Commit

Permalink
Reduce AbcSize for StoryOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobrgs committed Aug 31, 2017
1 parent bf8acf6 commit df12e29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ Metrics/MethodLength:
Metrics/AbcSize:
Enabled: true
Exclude:
- 'app/operations/story_operations.rb'
- 'app/operations/story_operations/state_change_notification.rb'
- 'app/operations/note_operations.rb'
- 'app/serializers/project_serializer.rb'
Expand Down
27 changes: 18 additions & 9 deletions app/operations/story_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@ def before_save
end

def after_save
new_documents = model.documents_attributes
if new_documents != model.documents_attributes_was
create_changesets
apply_fixes
notify_state_changed
notify_users
end

private

def documents_changed?
model.documents_attributes != model.documents_attributes_was
end

def create_changesets
if documents_changed?
model.instance_variable_set(
'@changed_attributes',
model.instance_variable_get('@changed_attributes')
.merge(documents_attributes: model.documents_attributes_was)
model.instance_variable_get('@changed_attributes').merge(
documents_attributes: model.documents_attributes_was
)
)
end
model.changesets.create!

apply_fixes

notify_state_changed
notify_users
model.changesets.create!
end
end

Expand Down

0 comments on commit df12e29

Please sign in to comment.