Class: Braid::Mirror
Defined Under Namespace
Classes: PathRequired, UnknownType
Constant Summary
collapse
- ATTRIBUTES =
%w(url branch squashed revision lock)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#git, #git_cache
Constructor Details
#initialize(path, attributes = {}) ⇒ Mirror
Returns a new instance of Mirror.
20
21
22
23
|
# File 'lib/braid/mirror.rb', line 20
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
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/braid/mirror.rb', line 96
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.
18
19
20
|
# File 'lib/braid/mirror.rb', line 18
def attributes
@attributes
end
|
#path ⇒ Object
Returns the value of attribute path.
18
19
20
|
# File 'lib/braid/mirror.rb', line 18
def path
@path
end
|
Class Method Details
.new_from_options(url, options = {}) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/braid/mirror.rb', line 25
def self.new_from_options(url, options = {})
url = url.sub(/\/$/, '')
branch = options['branch'] || 'master'
path = (options['path'] || (url)).sub(/\/$/, '')
raise PathRequired unless path
squashed = !options['full']
attributes = {'url' => url, 'branch' => branch, 'squashed' => squashed}
self.new(path, attributes)
end
|
Instance Method Details
#==(comparison) ⇒ Object
39
40
41
|
# File 'lib/braid/mirror.rb', line 39
def ==(comparison)
path == comparison.path && attributes == comparison.attributes
end
|
#base_revision ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/braid/mirror.rb', line 78
def base_revision
if revision
git.rev_parse(revision)
else
inferred_revision
end
end
|
#cached? ⇒ Boolean
74
75
76
|
# File 'lib/braid/mirror.rb', line 74
def cached?
git.remote_url(remote) == cached_url
end
|
#cached_url ⇒ Object
86
87
88
|
# File 'lib/braid/mirror.rb', line 86
def cached_url
git_cache.path(url)
end
|
#diff ⇒ Object
62
63
64
65
66
67
|
# File 'lib/braid/mirror.rb', line 62
def diff
fetch
remote_hash = git.rev_parse("#{base_revision}:")
local_hash = git.tree_hash(path)
remote_hash != local_hash ? git.diff_tree(remote_hash, local_hash) : ''
end
|
#fetch ⇒ Object
69
70
71
72
|
# File 'lib/braid/mirror.rb', line 69
def fetch
git_cache.fetch(url) if cached?
git.fetch(remote)
end
|
#locked? ⇒ Boolean
43
44
45
|
# File 'lib/braid/mirror.rb', line 43
def locked?
!!lock
end
|
#merged?(commit) ⇒ Boolean
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/braid/mirror.rb', line 51
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
|
#remote ⇒ Object
90
91
92
|
# File 'lib/braid/mirror.rb', line 90
def remote
"#{branch}/braid/#{path}"
end
|
#squashed? ⇒ Boolean
47
48
49
|
# File 'lib/braid/mirror.rb', line 47
def squashed?
!!squashed
end
|