app/models/item.rb
# Returns current and previous versions of the Item based on changes to
#   non-transient attributes (basically everything but current_location)
Returns current and previous versions of the Item based on changes to
non-transient attributes (basically everything but current_location)
Returns current and previous versions of the Item based on changes to non - transient attributes ( basically everything but current_location )
def modification_history
    history = []
    location_attributes = lambda do |location_id|
      location = Location.find_by(id: location_id)
      return location ? { title: location.title, uri: location.uri } : nil
    end
    user_attributes = lambda do |user_id|
      user = User.find_by(id: user_id)
      return user ? { email: user.email, display_name: user.display_name } : nil
    end
    gather_attributes = lambda do |item_version|
      atts = item_version.attributes
      atts['source'] = source
      location_id = item_version.permanent_location_id
      user_id = item_version.paper_trail.originator.to_i
      atts['permanent_location'] = location_attributes.(location_id)
      atts['user'] = user_attributes.(user_id)
      if item_catalog_record
        atts['item_catalog_record'] = item_catalog_record.attributes
      end
      return atts
    end
    add_to_history = Proc.new do |item|
      history << gather_attributes.(item)
      previous = item.paper_trail.previous_version
      if previous
        add_to_history.(previous)
      end
    end
    add_to_history.(self)
    history
  end
def modification_history history = [ ] location_attributes = lambda do | location_id | location = Location . find_by ( id : location_id ) return location ? { title : location . title , uri : location . uri } : nil end user_attributes = lambda do | user_id | user = User . find_by ( id : user_id ) return user ? { email : user . email , display_name : user . display_name } : nil end gather_attributes = lambda do | item_version | atts = item_version . attributes atts [ 'source' ] = source location_id = item_version . permanent_location_id user_id = item_version . paper_trail . originator . to_i atts [ 'permanent_location' ] = location_attributes . ( location_id ) atts [ 'user' ] = user_attributes . ( user_id ) if item_catalog_record atts [ 'item_catalog_record' ] = item_catalog_record . attributes end return atts end add_to_history = Proc . new do | item | history << gather_attributes . ( item ) previous = item . paper_trail . previous_version if previous add_to_history . ( previous ) end end add_to_history . ( self ) history end
Returns current and previous versions of the Item based on changes to
non-transient attributes (basically everything but current_location)
Returns current and previous versions of the Item based on changes to non - transient attributes ( basically everything but current_location )