Skip to content

Commit

Permalink
refactor reify method
Browse files Browse the repository at this point in the history
  • Loading branch information
theRealNG committed Mar 14, 2016
1 parent 39df4e3 commit 11c23f0
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions lib/paper_trail/reifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,10 @@ def reify(version, options)
reify_attributes(model, version, attrs)
model.send "#{model.class.version_association_name}=", version
reify_associations(model, options, version)
model
end

private

def reify_associations(model, options, version)
if options[:has_one]
reify_has_ones version.transaction_id, model, options
end
if options[:has_many]
reify_has_manys version.transaction_id, model, options
end
end

# Set all the attributes in this version on the model.
def reify_attributes(model, version, attrs)
enums = model.class.respond_to?(:defined_enums) ? model.class.defined_enums : {}
Expand All @@ -92,25 +82,6 @@ def reify_attributes(model, version, attrs)
)
end
end
<<<<<<< HEAD
=======

model.send "#{model.class.version_association_name}=", version

unless options[:has_one] == false
reify_has_ones version.transaction_id, model, options
end

unless options[:belongs_to] == false
reify_belongs_tos version.transaction_id, model, options
end

unless options[:has_many] == false
reify_has_manys version.transaction_id, model, options
end

model
>>>>>>> support for reify of only belongs_to relationships
end

# Replaces each record in `array` with its reified version, if present
Expand Down Expand Up @@ -152,6 +123,16 @@ def prepare_array_for_has_many(array, options, versions)
nil
end

def reify_associations model, options, version
reify_has_ones version.transaction_id, model, options if options[:has_one]

reify_belongs_tos version.transaction_id, model, options if options[:belongs_to]

reify_has_manys version.transaction_id, model, options if options[:has_many]

model
end

# Restore the `model`'s has_one associations as they were when this
# version was superseded by the next (because that's what the user was
# looking at when they made the change).
Expand Down

0 comments on commit 11c23f0

Please sign in to comment.