Merge pull request #768 from airblade/rubocop_multiline_ternary2
Fix multiline ternaries
This commit is contained in:
commit
31496972bb
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
@ -279,14 +277,19 @@ module PaperTrail
|
|||
end
|
||||
|
||||
# Given a `version`, return the class to reify. This method supports
|
||||
# Single Table Inheritance (STI). For example, given a `version` whose
|
||||
# `item_type` is "Banana", where `Banana` is an STI model in the `fruits`
|
||||
# table, this method would return the constant `Fruit`.
|
||||
# Single Table Inheritance (STI) with custom inheritance columns.
|
||||
#
|
||||
# For example, imagine a `version` whose `item_type` is "Animal". The
|
||||
# `animals` table is an STI table (it has cats and dogs) and it has a
|
||||
# custom inheritance column, `species`. If `attrs["species"]` is "Dog",
|
||||
# this method returns the constant `Dog`. If `attrs["species"]` is blank,
|
||||
# this method returns the constant `Animal`. You can see this particular
|
||||
# example in action in `spec/models/animal_spec.rb`.
|
||||
#
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue