Class: VCLog::Adapters::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/vclog/adapters/abstract.rb

Overview

Abstract base class for all version control system adapters.

Direct Known Subclasses

Darcs, Git, Hg, Svn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Abstract

Returns a new instance of Abstract.



31
32
33
34
35
36
37
# File 'lib/vclog/adapters/abstract.rb', line 31

def initialize(repo)
  @repo       = repo
  @root       = repo.root  
  @heuristics = repo.heuristics

  initialize_framework
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/vclog/adapters/abstract.rb', line 22

def config
  @config
end

#heuristicsObject (readonly)

Heuristics object.



28
29
30
# File 'lib/vclog/adapters/abstract.rb', line 28

def heuristics
  @heuristics
end

#rootObject (readonly)

Root location.



25
26
27
# File 'lib/vclog/adapters/abstract.rb', line 25

def root
  @root
end

Instance Method Details

#change_by_date(date) ⇒ Object

Return the latest commit as of a given date.



88
89
90
91
# File 'lib/vclog/adapters/abstract.rb', line 88

def change_by_date(date)
  list = changes.select{ |c| c.date <= date }
  list.sort_by{ |c| c.date }.last
end

#change_pointsObject



65
66
67
68
69
# File 'lib/vclog/adapters/abstract.rb', line 65

def change_points
  @change_points ||= (
    changes.inject([]){ |list, change| list.concat(change.points); list }
  )
end

#changesObject



60
61
62
# File 'lib/vclog/adapters/abstract.rb', line 60

def changes
  @changes ||= extract_changes
end

#emailObject

Fallback for email address is ‘ENV`.



99
100
101
# File 'lib/vclog/adapters/abstract.rb', line 99

def email
  ENV['EMAIL']
end

#extract_changesObject



50
51
52
# File 'lib/vclog/adapters/abstract.rb', line 50

def extract_changes
  raise "Not Implemented"
end

#extract_tagsObject



45
46
47
# File 'lib/vclog/adapters/abstract.rb', line 45

def extract_tags
  raise "Not Implemented"
end

#initialize_frameworkObject

This is used if the adapter is using an external library to interface with the repository.



41
42
# File 'lib/vclog/adapters/abstract.rb', line 41

def initialize_framework
end

#repositoryObject



104
105
106
# File 'lib/vclog/adapters/abstract.rb', line 104

def repository
  nil
end

#tag?(name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/vclog/adapters/abstract.rb', line 72

def tag?(name)
  tags.find{ |t| t.name == name }
end

#tagsObject



55
56
57
# File 'lib/vclog/adapters/abstract.rb', line 55

def tags
  @tags ||= extract_tags
end

#tempfile(name, content) ⇒ Object (private)



121
122
123
124
125
# File 'lib/vclog/adapters/abstract.rb', line 121

def tempfile(name, content)
  mfile = Tempfile.new(name)
  File.open(mfile.path, 'w'){ |f| f << content }
  mfile.path
end

#userObject

Fallback for user is ‘ENV`.



94
95
96
# File 'lib/vclog/adapters/abstract.rb', line 94

def user
  ENV['USER']
end

#uuidObject



109
110
111
# File 'lib/vclog/adapters/abstract.rb', line 109

def uuid
  nil
end

#versionObject

Returns the current verion string.



77
78
79
80
81
82
83
84
85
# File 'lib/vclog/adapters/abstract.rb', line 77

def version
  if tags.last
    v = tags[-1].name # TODO: ensure the latest version
    v = tags[-2].name if v == 'HEAD'
  else
    v = '0.0.0'
  end
  return v
end

#version_tag?(tag_name) ⇒ Boolean (private)

Returns:

  • (Boolean)


116
117
118
# File 'lib/vclog/adapters/abstract.rb', line 116

def version_tag?(tag_name)
  /(v|\d)/i =~ tag_name
end