mockversion 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,17 +1,21 @@
1
- mockversion
1
+ MockVersion
2
2
  ===========
3
+ A mock for the svn command line, created to help tool development
3
4
 
4
5
  Installation
5
6
  ------------
6
-
7
- tbd
7
+ gem install mockversion
8
8
 
9
9
  Usage
10
10
  -----
11
+ require 'mockversion'
12
+
13
+ `svn help`
14
+ => Mockversion - A mock for the svn command line, created to help tool development"
11
15
 
12
- tbd
16
+ `svnadmin help`
17
+ => Mockversion - A mock for the svn command line, created to help tool development"
13
18
 
14
19
  Copyright
15
20
  ---------
16
-
17
21
  Copyright (c) 2010 Bryan Ash. See LICENSE for details.
data/bin/svn CHANGED
@@ -1,3 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- puts "mockversion"
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
+
5
+ require 'mockversion'
6
+ require 'svn'
7
+
8
+ args = ARGV.dup
9
+ command = args.shift.strip rescue 'help'
10
+
11
+ case command
12
+ when "--version"
13
+ puts "MockVersion #{MockVersion::VERSION}"
14
+ when "help"
15
+ puts "MockVersion - A mock for the svn command line, created to help tool development"
16
+ puts ""
17
+ puts " Usage:"
18
+ puts " require 'mockversion'"
19
+ puts " `svn help`"
20
+ puts " => Mockversion - A mock for the svn command line, created to help tool development"
21
+ puts ""
22
+ when "checkout"
23
+ repo = MockVersion::Repository.load_from_path(args[0])
24
+ repo.checkout_to(args[1])
25
+ when "export"
26
+ SVN::Command::Export.execute(args)
27
+ when "add"
28
+ working_copy = MockVersion::WorkingCopy.load
29
+ working_copy.add(args.first)
30
+ when "commit"
31
+ working_copy = MockVersion::WorkingCopy.load
32
+ working_copy.commit(args[1])
33
+ end
34
+
data/bin/svnadmin ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
+
5
+ require 'mockversion'
6
+
7
+ args = ARGV
8
+ command = args.shift.strip rescue 'help'
9
+
10
+ case command
11
+ when "--version"
12
+ puts "MockVersion #{MockVersion::VERSION}"
13
+ when "help"
14
+ puts "MockVersion - A mock for the svn command line, created to help tool development"
15
+ puts ""
16
+ puts " Usage:"
17
+ puts " require 'mockversion'"
18
+ puts " `#{__FILE__} help`"
19
+ puts " => Mockversion - A mock for the svn command line, created to help tool development"
20
+ puts ""
21
+ when "create"
22
+ MockVersion::Repository.create(args.first)
23
+ when "verify"
24
+ MockVersion::Repository.verify(args.first)
25
+ end
data/lib/mockversion.rb CHANGED
@@ -1,3 +1,4 @@
1
- APP_PATH = File.expand_path(File.dirname(__FILE__) + '/../bin/')
2
-
3
- ENV['PATH'] = APP_PATH + File::PATH_SEPARATOR + ENV['PATH']
1
+ require 'mockversion/environment'
2
+ require 'mockversion/repository'
3
+ require 'mockversion/revision'
4
+ require 'mockversion/working_copy'
@@ -0,0 +1,7 @@
1
+ module MockVersion
2
+ APP_PATH = File.expand_path(File.dirname(__FILE__) + '/../../bin/')
3
+ VERSION = "0.0.3"
4
+
5
+ ENV['PATH'] = MockVersion::APP_PATH + File::PATH_SEPARATOR + ENV['PATH']
6
+ end
7
+
@@ -0,0 +1,81 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+
4
+ module MockVersion
5
+ class Repository
6
+
7
+ def self.create(path)
8
+ new(path).save
9
+ end
10
+
11
+ def self.verify(path)
12
+ load_from_path(path).verify
13
+ end
14
+
15
+ def self.load_from_path(path)
16
+ begin
17
+ repo = new(path)
18
+ YAML.load_file(repo.repo_file)
19
+ rescue
20
+ puts "Can't open"
21
+ exit 1
22
+ end
23
+ end
24
+
25
+ def initialize(path)
26
+ @repo_path = path
27
+ @revisions = [Revision.new]
28
+ end
29
+
30
+ def verify
31
+ puts @revisions.map { |revision| "* Verified revision #{revision.number}.\n" }
32
+ end
33
+
34
+ def checkout_to(path)
35
+ WorkingCopy.create(@repo_path, path)
36
+ @revisions.last.export_to(path)
37
+ end
38
+
39
+ def export_revision_to_path(revision_id, path)
40
+ if revision_id == "HEAD"
41
+ revision = @revisions.last
42
+ else
43
+ revision = @revisions.find { |revision| revision.number == revision_id }
44
+ end
45
+
46
+ revision.export_to(path)
47
+ end
48
+
49
+ def add_revision(revision)
50
+ @revisions << revision
51
+ save
52
+ end
53
+
54
+ def create_new_revision(number = '1')
55
+ last_lower_revision = last_revision_lower_than(number)
56
+ new_revision = last_lower_revision.dup
57
+ new_revision.files = last_lower_revision.files.dup
58
+ new_revision.number = number
59
+ add_revision(new_revision)
60
+ new_revision
61
+ end
62
+
63
+ def last_revision_lower_than(number)
64
+ @revisions.find_all { |revision| revision.number < number }.last
65
+ end
66
+
67
+ def save
68
+ FileUtils.makedirs(full_repo_path)
69
+ File.open(repo_file, "w") { |file| file.puts to_yaml }
70
+ end
71
+
72
+ def full_repo_path
73
+ ".mockversion/#{@repo_path}"
74
+ end
75
+
76
+ def repo_file
77
+ "#{full_repo_path}/repo.yml"
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,26 @@
1
+ module MockVersion
2
+ class Revision
3
+
4
+ attr_accessor :number
5
+ attr_accessor :files
6
+
7
+ def initialize(number = '0')
8
+ @number = number
9
+ end
10
+
11
+ def export_to(path)
12
+ files.each do |filename|
13
+ File.open("#{path}/#{filename}", "w") { |file| file.puts @number }
14
+ end
15
+ end
16
+
17
+ def add_file(filename)
18
+ files << filename
19
+ end
20
+
21
+ def files
22
+ @files ||= []
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ require 'fileutils'
2
+
3
+ module MockVersion
4
+ class WorkingCopy
5
+
6
+ def self.create(repo_path, path)
7
+ new(repo_path, path).save
8
+ end
9
+
10
+ def self.load
11
+ YAML.load_file(".svn/working_copy.yml")
12
+ end
13
+
14
+ def initialize(repo_path, path)
15
+ @repo_path = repo_path
16
+ @path = path
17
+ end
18
+
19
+ def add(path)
20
+ staged_files << path
21
+ save
22
+ end
23
+
24
+ def commit(message)
25
+ puts "committing to: #{@repo_path}"
26
+ repo = Repository.load_from_path(@repo_path)
27
+ repo.create_new_revision
28
+ end
29
+
30
+ def staged_files
31
+ @staged_files ||= []
32
+ end
33
+
34
+ def save
35
+ FileUtils.makedirs("#{@path}/.svn")
36
+ File.open("#{@path}/.svn/working_copy.yml", "w") { |file| file.puts to_yaml }
37
+ end
38
+
39
+ end
40
+ end
data/lib/svn.rb ADDED
@@ -0,0 +1 @@
1
+ require 'svn/command'
@@ -0,0 +1 @@
1
+ require 'svn/command/export'
@@ -0,0 +1,38 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module SVN
5
+ module Command
6
+ class Export < ::OptionParser
7
+
8
+ def self.execute(args)
9
+ command = new
10
+ command.parse!(args)
11
+ command.execute(args)
12
+ end
13
+
14
+ OPTIONS = {
15
+ :revision => ["-r", "--revision arg",
16
+ "A revision argument can be one of:",
17
+ " NUMBER revision number",
18
+ " HEAD latest in repository"]
19
+ }
20
+
21
+ def initialize
22
+ super
23
+ @options = OpenStruct.new
24
+ @options.revision = "HEAD"
25
+
26
+ self.banner = "Usage: svn export [options] [URL] [path]"
27
+ self.separator ""
28
+ on(*OPTIONS[:revision]) { |revision| @options.revision = revision.upcase }
29
+ end
30
+
31
+ def execute(args)
32
+ repo = MockVersion::Repository.load_from_path(args[0])
33
+ repo.export_revision_to_path(@options.revision, args[1])
34
+ end
35
+
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bryan Ash
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-07 00:00:00 -04:00
17
+ date: 2010-07-20 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -28,8 +28,16 @@ extra_rdoc_files:
28
28
  - LICENSE
29
29
  - README.markdown
30
30
  files:
31
+ - lib/mockversion/environment.rb
32
+ - lib/mockversion/repository.rb
33
+ - lib/mockversion/revision.rb
34
+ - lib/mockversion/working_copy.rb
31
35
  - lib/mockversion.rb
36
+ - lib/svn/command/export.rb
37
+ - lib/svn/command.rb
38
+ - lib/svn.rb
32
39
  - bin/svn
40
+ - bin/svnadmin
33
41
  - LICENSE
34
42
  - README.markdown
35
43
  has_rdoc: true