Class: Braid::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/braid/config.rb,
lib/braid/exceptions.rb
Defined Under Namespace
Classes: BranchIsRequired, CannotGuessMirrorType, MirrorDoesNotExist, MirrorNameAlreadyInUse, MirrorNameIsRequired, MirrorTypeIsRequired, RemoteIsRequired, UnknownMirrorType
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config_file = nil) ⇒ Config
Returns a new instance of Config.
8
9
10
11
|
# File 'lib/braid/config.rb', line 8
def initialize(config_file = nil)
config_file ||= CONFIG_FILE
@db = YAML::Store.new(config_file)
end
|
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
6
7
8
|
# File 'lib/braid/config.rb', line 6
def db
@db
end
|
Class Method Details
.options_to_mirror(remote, options = {}) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/braid/config.rb', line 89
def self.options_to_mirror(remote, options = {})
remote = remove_trailing_slash(remote)
branch = options["branch"] || "master"
if options["type"]
type = options["type"]
else
type = (remote)
raise Braid::Config::CannotGuessMirrorType unless type
end
mirror = options["mirror"] || (remote)
if options["rails_plugin"]
mirror = "vendor/plugins/#{mirror}"
end
squash = !options["full"]
[remove_trailing_slash(mirror), { "type" => type, "remote" => remote, "branch" => branch, "squash" => squash }]
end
|
Instance Method Details
#add(mirror, params) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/braid/config.rb', line 34
def add(mirror, params)
mirror = remove_trailing_slash(mirror)
@db.transaction do
raise Braid::Config::MirrorNameAlreadyInUse if @db[mirror]
@db[mirror] = params.merge("remote" => remove_trailing_slash(params["remote"]))
end
end
|
#add_from_options(remote, options) ⇒ Object
#get(mirror) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/braid/config.rb', line 42
def get(mirror)
mirror = remove_trailing_slash(mirror)
@db.transaction(true) do
@db[mirror]
end
end
|
#get!(mirror) ⇒ Object
49
50
51
52
53
|
# File 'lib/braid/config.rb', line 49
def get!(mirror)
params = get(mirror)
raise Braid::Config::MirrorDoesNotExist unless params
params
end
|
#get_by_remote(remote) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/braid/config.rb', line 55
def get_by_remote(remote)
remote = remove_trailing_slash(remote)
mirror = nil
@db.transaction(true) do
mirror = @db.roots.detect { |mirror| @db[mirror]["remote"] == remote }
end
[mirror, get(mirror)]
end
|
#mirrors ⇒ Object
28
29
30
31
32
|
# File 'lib/braid/config.rb', line 28
def mirrors
@db.transaction(true) do
@db.roots
end
end
|
#remove(mirror) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/braid/config.rb', line 64
def remove(mirror)
mirror = remove_trailing_slash(mirror)
@db.transaction do
@db.delete(mirror)
end
end
|
#replace(mirror, params) ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/braid/config.rb', line 80
def replace(mirror, params)
mirror = remove_trailing_slash(mirror)
@db.transaction do
raise Braid::Config::MirrorDoesNotExist unless @db[mirror]
params["remote"] = remove_trailing_slash(params["remote"]) if params["remote"]
@db[mirror] = params
end
end
|
#update(mirror, params) ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/braid/config.rb', line 71
def update(mirror, params)
mirror = remove_trailing_slash(mirror)
@db.transaction do
raise Braid::Config::MirrorDoesNotExist unless @db[mirror]
tmp = @db[mirror].merge(params)
@db[mirror] = tmp.merge("remote" => remove_trailing_slash(tmp["remote"]))
end
end
|