Class: VcsApp

Inherits:
Object
  • Object
show all
Defined in:
lib/vcs/app.rb

Overview

vcs: The version control system wrapper.

Vcs is a wrapper over any version control system.

Constant Summary collapse

@@parser =
Vcs::OptParse.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(__file__, vcs_type = nil) ⇒ VcsApp

Returns a new instance of VcsApp.



61
62
63
64
# File 'lib/vcs/app.rb', line 61

def initialize ( __file__, vcs_type=nil )
  @@path = __file__.to_path
  Vcs.default ||= vcs_type
end

Class Method Details

.all_vcsObject



51
52
53
# File 'lib/vcs/app.rb', line 51

def all_vcs
  @@all_vcs.keys
end

.grab_all_vcsObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vcs/app.rb', line 38

def grab_all_vcs
  @@all_vcs ||= {}

  if @@all_vcs.empty?
    ObjectSpace.each_object(Class) do |aClass|
      if aClass != Vcs and aClass.ancestors.include? Vcs
        name = aClass.to_s.demodulize.underscore.to_sym
        @@all_vcs[name] = aClass
      end
    end
  end
end

.requirementsObject



30
31
32
33
34
35
36
# File 'lib/vcs/app.rb', line 30

def requirements
  Pathname.glob("{#{vcs_dir},#{extension_dirs.join(',')}}/*.rb") do |file|
    next if file.to_s =~ /\/(app|opt_parse|vcs|svn|version)\.rb$/
    logger.debug { file.basename.to_s } if require file.to_s
  end
  grab_all_vcs()
end

Instance Method Details

#grab_dirs(basename, dir = Pathname.pwd) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vcs/app.rb', line 66

def grab_dirs ( basename, dir=Pathname.pwd )
  results = []
  while not dir.root?
    path = dir + basename
    results << path if path.exist?
    dir = dir.parent
  end
  path = ENV['HOME'].to_path/basename
  results << path if path.exist? and not results.include? path
  results
end

#runObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/vcs/app.rb', line 93

def run
  vcs = nil
  begin
    user_configuration_setup()
    Vcs.logger.color = Vcs.color? { STDERR.tty? }
    Vcs::Logger.enable_xmas_tree_colors if Vcs.xmas_tree_colors?
    vcs_extensions_setup()
    @@parser.parse! ARGV if Vcs.default.nil?
    if Vcs.default.nil?
      STDERR.puts @@parser
      STDERR.puts "
        |
        |Specify at least a Vcs type, or use a wrapped command
        |like svn, cvs, prcs in the vcs bin directory.
      ".head_cut!
      exit
    end
    vcs = @@all_vcs[Vcs.default.to_s.downcase.to_sym].new
    vcs.run_argv(ARGV)

  rescue SystemExit => ex
    raise ex
  rescue Exception => ex
    if vcs.nil?
      logger.error { "No Vcs instanciated" }
    else
      vcs.call_handlers
    end
    err = ex.to_s.sub(/\.$/, '')
    logger.debug { err = ex.long_pp ; "Backtrace enabled:" }
    err = ex.inspect if err.empty?
    logger.error { err }
    exit 1
  end
end

#user_configuration_setupObject



87
88
89
90
91
# File 'lib/vcs/app.rb', line 87

def user_configuration_setup
  grab_dirs('.vcs').reverse_each do |vcs_user_conf|
    Vcs.merge_user_conf(vcs_user_conf)
  end
end

#vcs_extensions_setupObject



78
79
80
81
82
83
84
85
# File 'lib/vcs/app.rb', line 78

def vcs_extensions_setup
  grab_dirs('vcs').each do |vcs_dir|
    vcs_dir = vcs_dir.expand_path
    vcs_dir.load_path!
    extension_dirs << vcs_dir
  end
  VcsApp.requirements()
end