Class: DmSvn::Svn::Sync

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-svn/svn/sync.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_row) ⇒ Sync

Returns a new instance of Sync.



7
8
9
10
11
# File 'lib/dm-svn/svn/sync.rb', line 7

def initialize(model_row)
  @model_row = model_row
  @model = Object.const_get(@model_row.name)
  @config = @model_row.config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/dm-svn/svn/sync.rb', line 5

def config
  @config
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/dm-svn/svn/sync.rb', line 5

def model
  @model
end

#reposObject (readonly)

Returns the value of attribute repos.



5
6
7
# File 'lib/dm-svn/svn/sync.rb', line 5

def repos
  @repos
end

Instance Method Details

#changesetsObject

Get changesets



14
15
16
17
18
19
20
21
22
23
# File 'lib/dm-svn/svn/sync.rb', line 14

def changesets
  sets = []
  
  @repos.log('', @model_row.revision, @repos.latest_revnum, 0, true, false
      ) do |changes, rev, author, date, msg|
    sets << Changeset.new(changes, rev, author, date, self)
  end
  
  sets.sort
end

#runObject

There is the possibility for uneccessary updates, as a database row may be modified several times (if modified in multiple revisions) in a single call. This is inefficient, but–for now–not enough to justify more complex code.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dm-svn/svn/sync.rb', line 29

def run
  connect(@config.uri)
  return false if @repos.latest_revnum <= @model_row.revision
  
  changesets.each do |c| # Sorted by revision, ascending
    c.process
    # Update model_row.revision
    row_update = @model_row.class.get(@model_row.id)
    row_update.update(:revision => c.revision)
  end
  
  # Ensure that @model_row.revision is now set to the latest (even if there
  # weren't applicable changes in the latest revision).
  row_update = @model_row.class.get(@model_row.id)
  row_update.update(:revision => @repos.latest_revnum)
  return true
end