Class: Braid::Mirror
Defined Under Namespace
Classes: CannotGuessType, PathRequired, UnknownType
Constant Summary
collapse
- TYPES =
%w(git svn)
- ATTRIBUTES =
%w(url remote type branch squashed revision lock)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#git, #git_cache, #git_svn, #svn
Constructor Details
#initialize(path, attributes = {}) ⇒ Mirror
Returns a new instance of Mirror.
26
27
28
29
|
# File 'lib/braid/mirror.rb', line 26
def initialize(path, attributes = {})
@path = path.sub(/\/$/, '')
@attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/braid/mirror.rb', line 118
def method_missing(name, *args)
if ATTRIBUTES.find { |attribute| name.to_s =~ /^(#{attribute})(=)?$/ }
unless $2
attributes[$1]
else
attributes[$1] = args[0]
end
else
raise NameError, "unknown attribute `#{name}'"
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
24
25
26
|
# File 'lib/braid/mirror.rb', line 24
def attributes
@attributes
end
|
#path ⇒ Object
Returns the value of attribute path.
24
25
26
|
# File 'lib/braid/mirror.rb', line 24
def path
@path
end
|
Class Method Details
.new_from_options(url, options = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/braid/mirror.rb', line 31
def self.new_from_options(url, options = {})
url = url.sub(/\/$/, '')
branch = options["branch"] || "master"
if type = options["type"] || (url)
raise UnknownType, type unless TYPES.include?(type)
else
raise CannotGuessType, url
end
unless path = options["path"] || (url)
raise PathRequired
end
if options["rails_plugin"]
path = "vendor/plugins/#{path}"
end
remote = "braid/#{path}".gsub("_", '-') squashed = !options["full"]
branch = nil if type == "svn"
attributes = { "url" => url, "remote" => remote, "type" => type, "branch" => branch, "squashed" => squashed }
self.new(path, attributes)
end
|
Instance Method Details
#==(comparison) ⇒ Object
58
59
60
|
# File 'lib/braid/mirror.rb', line 58
def ==(comparison)
path == comparison.path && attributes == comparison.attributes
end
|
#base_revision ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/braid/mirror.rb', line 105
def base_revision
if revision
unless type == "svn"
git.rev_parse(revision)
else
git_svn.commit_hash(remote, revision)
end
else
inferred_revision
end
end
|
#cached? ⇒ Boolean
101
102
103
|
# File 'lib/braid/mirror.rb', line 101
def cached?
git.remote_url(remote) == git_cache.path(url)
end
|
#diff ⇒ Object
86
87
88
89
90
|
# File 'lib/braid/mirror.rb', line 86
def diff
remote_hash = git.rev_parse("#{base_revision}:")
local_hash = git.tree_hash(path)
remote_hash != local_hash ? git.diff_tree(remote_hash, local_hash, path) : ""
end
|
#fetch ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/braid/mirror.rb', line 92
def fetch
unless type == "svn"
git_cache.fetch(url) if cached?
git.fetch(remote)
else
git_svn.fetch(remote)
end
end
|
#locked? ⇒ Boolean
67
68
69
|
# File 'lib/braid/mirror.rb', line 67
def locked?
!!lock
end
|
#merged?(commit) ⇒ Boolean
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/braid/mirror.rb', line 75
def merged?(commit)
commit = git.rev_parse(commit)
if squashed?
!!base_revision && git.merge_base(commit, base_revision) == commit
else
git.merge_base(commit, "HEAD") == commit
end
end
|
#squashed? ⇒ Boolean
71
72
73
|
# File 'lib/braid/mirror.rb', line 71
def squashed?
!!squashed
end
|
#type ⇒ Object
62
63
64
65
|
# File 'lib/braid/mirror.rb', line 62
def type
attributes["type"]
end
|