LuizCarvalho-esvien 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2007 Brian Donovan, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ Esvien
2
+ ======
3
+ Esvien is a simple Ruby interface to Subversion.
4
+
5
+ http://github.com/eventualbuddha/esvien
6
+
7
+ Example
8
+ -------
9
+
10
+ >> head = Esvien::Repo.new("http://svn.collab.net/repos/svn/trunk/").head
11
+ => #<Esvien::Commit id=36632, repo=#<Esvien::Repo uri="http://svn.collab.net/repos/svn/trunk/", uuid="612f8ebc-c883-4be0-9ee0-a4e9ef946e3a">>
12
+ >> head.author
13
+ => "gstein"
14
+ >> head.date
15
+ => Tue Mar 17 17:37:56 UTC 2009
16
+ >> head.msg
17
+ => "Changed layout"
18
+
19
+ Install
20
+ -------
21
+
22
+ sudo gem install esvien
23
+
24
+ Requirements
25
+ ------------
26
+
27
+ Depends on Hpricot.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'rubygems'
3
+ require 'thor'
4
+
5
+ $stderr.puts "Robot Army uses thor, not rake. Here are the available tasks:"
6
+ exec "thor -T"
7
+ rescue LoadError
8
+ $stderr.puts "Robot Army uses thor, not rake. Please install thor."
9
+ end
data/lib/esvien.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'hpricot'
2
+ require 'time'
3
+
4
+ $LOAD_PATH.push File.dirname(__FILE__)
5
+
6
+ module Esvien
7
+ VERSION = "0.0.1"
8
+ end
9
+
10
+ require 'esvien/repo'
11
+ require 'esvien/commit'
12
+ require 'esvien/errors'
@@ -0,0 +1,42 @@
1
+ module Esvien
2
+ class Commit
3
+ attr_reader :id
4
+ attr_reader :repo
5
+ attr_accessor :author
6
+ attr_accessor :date
7
+ attr_accessor :msg
8
+
9
+ include Comparable
10
+
11
+ def initialize(id, repo)
12
+ @id = id
13
+ @repo = repo
14
+ @msg = ''
15
+ end
16
+
17
+ def <=>(other)
18
+ if other.is_a?(Commit)
19
+ if self.repo == other.repo
20
+ return id <=> other.id
21
+ else
22
+ raise Esvien::RepositoryMismatch
23
+ end
24
+ else
25
+ raise ArgumentError, "Cannot compare #{self.class} with #{other.class}"
26
+ end
27
+ end
28
+
29
+ def pretty_print(pp)
30
+ pp.group(1, %{#<#{self.class}}, %{>}) do
31
+ pp.breakable
32
+ pp.seplist(%w[id repo], lambda { pp.comma_breakable }) do |attr|
33
+ pp.text(attr)
34
+ pp.text("=")
35
+ pp.pp(send(attr))
36
+ end
37
+ end
38
+ end
39
+
40
+ alias_method :inspect, :pretty_print_inspect
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ module Esvien
2
+ class Error < RuntimeError
3
+ end
4
+
5
+ class BadRepository < Error
6
+ attr_reader :repo
7
+
8
+ def initialize(repo)
9
+ @repo = repo
10
+ end
11
+
12
+ def message
13
+ "No repository found at #{repo.uri}"
14
+ end
15
+ end
16
+
17
+ class CLIError < Error
18
+ def initialize(command, output)
19
+ @command, @output = command, output
20
+ end
21
+
22
+ def message
23
+ "Error while executing Subversion command:\n\n #{@command}\n\nOutput:\n\n#{@output.to_a.map{|line|" #{line}"}}"
24
+ end
25
+ end
26
+
27
+ class RepositoryMismatch < Error
28
+ end
29
+ end
@@ -0,0 +1,85 @@
1
+ module Esvien
2
+ class Repo
3
+ attr_reader :uri
4
+ attr_reader :uuid
5
+
6
+ def initialize(uri)
7
+ @uri = uri
8
+ get_repository_info
9
+ end
10
+
11
+ def commits(range=nil)
12
+ return [] if @revision == 0
13
+
14
+ doc = svnxml(:log, '-r', svn_range_string(range) || '1:HEAD', uri)
15
+ elems = doc.search('/log/logentry')
16
+ elems.map do |elem|
17
+ commit = Commit.new(elem.attributes['revision'].to_i, self)
18
+ commit.author = elem.children_of_type('author').first.inner_text
19
+ commit.date = Time.parse(elem.children_of_type('date').first.inner_text)
20
+ commit.msg = elem.children_of_type('msg').first.inner_text
21
+ commit
22
+ end
23
+ end
24
+
25
+ def head
26
+ commits('HEAD').first
27
+ end
28
+
29
+ def ==(other)
30
+ uuid == other.uuid
31
+ end
32
+
33
+ def pretty_print(pp)
34
+ pp.group(1, %{#<#{self.class}}, %{>}) do
35
+ pp.breakable
36
+ pp.seplist(%w[uri uuid], lambda { pp.comma_breakable }) do |attr|
37
+ pp.text(attr)
38
+ pp.text("=")
39
+ pp.pp(send(attr))
40
+ end
41
+ end
42
+ end
43
+
44
+ alias_method :inspect, :pretty_print_inspect
45
+
46
+ private
47
+
48
+ def get_repository_info
49
+ begin
50
+ doc = svnxml(:info, uri)
51
+ entry = doc.at('/info/entry')
52
+ @revision = entry.attributes['revision'].to_i
53
+ repo = entry.children_of_type('repository').first
54
+ @uuid = repo.children_of_type('uuid').first.inner_text
55
+ rescue Esvien::CLIError
56
+ raise Esvien::BadRepository, self
57
+ end
58
+ end
59
+
60
+ def svn_range_string(range)
61
+ case range
62
+ when nil
63
+ return nil
64
+ when Range
65
+ "#{range.first}:#{range.last}"
66
+ else
67
+ range.to_s
68
+ end
69
+ end
70
+
71
+ def svnxml(operation, *args)
72
+ Hpricot.XML(svn(operation, '--xml', *args))
73
+ end
74
+
75
+ def svn(operation, *args)
76
+ command = %{svn #{operation} #{args.map{|arg| %{"#{arg.to_s.gsub('"', '\"')}"}}.join(' ')} 2>&1}
77
+ output = %x{#{command}}
78
+ if $?.exitstatus == 0
79
+ return output
80
+ else
81
+ raise Esvien::CLIError.new(command, output)
82
+ end
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: LuizCarvalho-esvien
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Brian Donovan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-17 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.6"
24
+ version:
25
+ description: A simple Subversion client for Ruby
26
+ email: brian.donovan@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.md
33
+ - LICENSE
34
+ files:
35
+ - README.md
36
+ - LICENSE
37
+ - Rakefile
38
+ - lib/esvien
39
+ - lib/esvien/commit.rb
40
+ - lib/esvien/errors.rb
41
+ - lib/esvien/repo.rb
42
+ - lib/esvien.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/eventualbuddha/esvien
45
+ licenses:
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: esvien
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: A simple Subversion client for Ruby
70
+ test_files: []
71
+