Skip to content

Revisit concept of FIELDNAME_sync methods #12

@delano

Description

@delano

e.g. Make the value stored at KEY identical to the given list.

def last
at(-1)
end
# TODO: def replace
## Make the value stored at KEY identical to the given list
# define_method :"#{name}_sync" do |*latest|
# latest = latest.flatten.compact
# # Do nothing if we're given an empty Array.
# # Otherwise this would clear all current values
# if latest.empty?
# false
# else
# # Convert to a list of index values if we got the actual objects
# latest = latest.collect { |obj| obj.index } if klass === latest.first
# current = send("#{name_plural}raw")
# added = latest-current
# removed = current-latest
# #Familia.info "#{self.index}: adding: #{added}"
# added.each { |v| self.send("add_#{name_singular}", v) }
# #Familia.info "#{self.index}: removing: #{removed}"
# removed.each { |v| self.send("remove_#{name_singular}", v) }

    # TODO: def replace
    ## Make the value stored at KEY identical to the given list
    # define_method :"#{name}_sync" do |*latest|
    #  latest = latest.flatten.compact
    #  # Do nothing if we're given an empty Array.
    #  # Otherwise this would clear all current values
    #  if latest.empty?
    #    false
    #  else
    #    # Convert to a list of index values if we got the actual objects
    #    latest = latest.collect { |obj| obj.index } if klass === latest.first
    #    current = send("#{name_plural}raw")
    #    added = latest-current
    #    removed = current-latest
    #    #Familia.info "#{self.index}: adding: #{added}"
    #    added.each { |v| self.send("add_#{name_singular}", v) }
    #    #Familia.info "#{self.index}: removing: #{removed}"
    #    removed.each { |v| self.send("remove_#{name_singular}", v) }
    #    true
    #  end
    # end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions