class Mhc::Sync::Strategy::Base

Our Sync mechanism is very simple, because we can assume every article is independent with eath other. It will work well with iCalendar basis articles.

We simply follow the rule on the table below:

                 Side 2
|---+---------+------------+------------+-------|

S | | M | U | N | D | i |—---------————------------——-| d | M | CNF | OW 1->2 | CP 1->2 | CNF | e | U | OW 2->1 | - | ?? CP 1->2 | DEL 1 | 1 | N | CP 2->1 | ?? CP 2->1 | - | - |

| D | CNF     | DEL 2      | -          | -     |
|---+---------+------------+------------+-------|

M, U, N, and D indicate status changes on each article after
the last sync:

+ M :: Modified (or Created)
+ U :: Unchanged
+ N :: No Record
+ D :: Deleted

Each entry in the table means:
+ -- :: No operation (ignore)
+ ?? :: Not occurred in normal cases
+ OW :: Overwrite
+ CP :: Copy
+ DEL :: Delete
+ CNF :: Conflict

Before applying the rule to our repository, we have to set the marks (M, U, N or D) to all articles in each side.

strategy = Mhc::Sync::Strategy.create(strategy_name) strategy name is one of:

and strategy.whatnow(side1, side2) returns a symbol one of:

side1 and side2 have to respond to:

#nil?, # #modified?, #unmodified?, #norecord?, #deleted?

Public Instance Methods

whatnow(side1, side2) click to toggle source
# File lib/mhc/sync/strategy.rb, line 77
def whatnow(side1, side2)
  # do nothing
  actions = {
    "MM" => :ignore,
    "MU" => :ignore,
    "MN" => :ignore,
    "MD" => :ignore,

    "UM" => :ignore,
    "UU" => :ignore,
    "UN" => :ignore,
    "UD" => :ignore,

    "NM" => :ignore,
    "NU" => :ignore,
    "NN" => :ignore,
    "ND" => :ignore,

    "DM" => :ignore,
    "DU" => :ignore,
    "DN" => :ignore,
    "DD" => :ignore,
  }
  return actions[status_pair(side1, side2)]
end

Private Instance Methods

status_pair(side1, side2) click to toggle source
# File lib/mhc/sync/strategy.rb, line 123
def status_pair(side1, side2)
  return status_signature(side1) + status_signature(side2)
end
status_signature(info) click to toggle source
  • Char (M,U,N,D) indicates status change on each article after the last sync:

    + M

    Modified

    + U

    Unchanged

    + N

    No Record

    + D

    Deleted

# File lib/mhc/sync/strategy.rb, line 112
def status_signature(info)
  return "N" if info.nil?

  return "M" if info.modified? || info.created?
  return "U" if info.unmodified?
  return "N" if info.norecord?
  return "D" if info.deleted?

  return "?" # NOTREACHED I hope
end