Fix Style/MultilineTernaryOperator offenses

This commit is contained in:
Paul Padier 2016-04-01 14:42:54 +09:00 committed by Jared Beck
parent 6bc0f91667
commit c5532f1b7b
5 changed files with 23 additions and 19 deletions

View File

@ -40,10 +40,3 @@ Style/ModuleFunction:
Exclude:
- 'lib/paper_trail/serializers/json.rb'
- 'lib/paper_trail/serializers/yaml.rb'
# Offense count: 4
Style/MultilineTernaryOperator:
Exclude:
- 'lib/paper_trail/config.rb'
- 'lib/paper_trail/has_paper_trail.rb'
- 'lib/paper_trail/reifier.rb'

View File

@ -33,9 +33,11 @@ module PaperTrail
end
def track_associations
@track_associations.nil? ?
PaperTrail::VersionAssociation.table_exists? :
if @track_associations.nil?
PaperTrail::VersionAssociation.table_exists?
else
@track_associations
end
end
alias_method :track_associations?, :track_associations

View File

@ -221,10 +221,13 @@ module PaperTrail
# Returns the object (not a Version) as it was most recently.
def previous_version
preceding_version = source_version ?
source_version.previous :
send(self.class.versions_association_name).last
preceding_version.reify if preceding_version
previous =
if source_version
source_version.previous
else
send(self.class.versions_association_name).last
end
previous.try(:reify)
end
# Returns the object (not a Version) as it became next.

View File

@ -17,9 +17,7 @@ module PaperTrail
unversioned_attributes: :nil
)
attrs = version.class.object_col_is_json? ?
version.object :
PaperTrail.serializer.load(version.object)
attrs = version.object_deserialized
# Normally a polymorphic belongs_to relationship allows us to get the
# object we belong to by calling, in this case, `item`. However this
@ -290,9 +288,8 @@ module PaperTrail
#
def version_reification_class(version, attrs)
inheritance_column_name = version.item_type.constantize.inheritance_column
class_name = attrs[inheritance_column_name].blank? ?
version.item_type :
attrs[inheritance_column_name]
inher_col_value = attrs[inheritance_column_name]
class_name = inher_col_value.blank? ? version.item_type : inher_col_value
class_name.constantize
end

View File

@ -176,6 +176,15 @@ module PaperTrail
end
end
# @api private
def object_deserialized
if self.class.object_col_is_json?
object
else
PaperTrail.serializer.load(object)
end
end
# Restore the item from this version.
#
# Optionally this can also restore all :has_one and :has_many (including