Class: Puppetfile
Constant Summary
collapse
- BUMP_TYPES =
%w{patch minor major}
Instance Attribute Summary collapse
#vcs
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_module(name, metadata) ⇒ Object
-
#bump(mod_name, type = 'patch') ⇒ Object
-
#commit(message, remote = false) ⇒ Object
-
#diff(a, b) ⇒ Object
-
#find_mod(name) ⇒ Object
ControlMod - a ControlMod object.
-
#find_mods(names) ⇒ Object
-
#forge(name, *args) ⇒ Object
-
#initialize(puppetfile = 'Puppetfile') ⇒ Puppetfile
constructor
A new instance of Puppetfile.
-
#mod(name, *args) ⇒ Object
-
#mod_exists?(name) ⇒ Boolean
-
#path ⇒ Object
Returns the value of attribute base_path.
-
#push(remote, branch, force = false, tags = true) ⇒ Object
-
#source ⇒ Object
-
#to_json(pretty = false) ⇒ Object
-
#to_s ⇒ Object
-
#write_source(mod_name, src, branch = nil) ⇒ ControlMod
-
#write_to_file ⇒ Boolean
-
#write_version(mod_name, version) ⇒ Object
adapter_instance, adapter_types, default_instance
#color, #log_level, #logger
#add_all, #add_file, #add_remote, #apply_diff, #apply_patch, #author, #author_email, #author_name, #branch_exist?, #changed_files, #checkout_branch, #cherry_pick, #cli_create_commit, #clone, #create_branch, #create_commit, #create_diff, #create_diff_obj, #create_local_tag, #credentials, #current_branch, #current_branch?, #delete_branch, #fetch, #fetch_cli, #find_or_create_remote, #find_ref, #find_tag, #get_content, #git_command, #git_url?, #push_branch, #push_tags, #rebase_branch, #ref_exists?, #remote_exists?, #remote_from_name, #remote_from_url, #remote_url_matches?, #remove_file, #repo, #tag_exists?, #tags, #transports, #up2date?
Constructor Details
#initialize(puppetfile = 'Puppetfile') ⇒ Puppetfile
Returns a new instance of Puppetfile.
19
20
21
22
|
# File 'lib/release_manager/puppetfile.rb', line 19
def initialize(puppetfile = 'Puppetfile')
@puppetfile = puppetfile
@puppetmodule = PuppetModule.new(base_path)
end
|
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
9
10
11
|
# File 'lib/release_manager/puppetfile.rb', line 9
def base_path
@base_path
end
|
#data ⇒ Object
Returns the value of attribute data.
9
10
11
|
# File 'lib/release_manager/puppetfile.rb', line 9
def data
@data
end
|
Returns - a list of control mod objects.
70
71
72
|
# File 'lib/release_manager/puppetfile.rb', line 70
def modules
@modules
end
|
#puppetfile ⇒ Object
Returns the value of attribute puppetfile.
9
10
11
|
# File 'lib/release_manager/puppetfile.rb', line 9
def puppetfile
@puppetfile
end
|
#puppetmodule ⇒ Object
Returns the value of attribute puppetmodule.
9
10
11
|
# File 'lib/release_manager/puppetfile.rb', line 9
def puppetmodule
@puppetmodule
end
|
Class Method Details
.from_string(s) ⇒ Object
78
79
80
81
82
|
# File 'lib/release_manager/puppetfile.rb', line 78
def self.from_string(s)
instance = new
instance.data = s
instance
end
|
.to_puppetfile(json_data) ⇒ Object
165
166
167
168
169
170
171
172
173
|
# File 'lib/release_manager/puppetfile.rb', line 165
def self.to_puppetfile(json_data)
obj = JSON.parse(json_data)
mods = obj.collect do |name, metadata|
name = "mod '#{name}',"
data = metadata.sort.map { |k, v| ":#{k} => '#{v}'" }.join(",\n\ ")
"#{name}\n #{data}\n"
end.join("\n")
mods
end
|
Instance Method Details
#add_module(name, metadata) ⇒ Object
49
50
51
|
# File 'lib/release_manager/puppetfile.rb', line 49
def add_module(name, metadata)
modules[name] = ControlMod.new(name, metadata)
end
|
#bump(mod_name, type = 'patch') ⇒ Object
133
134
135
136
137
|
# File 'lib/release_manager/puppetfile.rb', line 133
def bump(mod_name, type = 'patch')
raise "Invalid type, must be one of #{BUMP_TYPES}" unless BUMP_TYPES.include?(type)
mod = find_mod(mod_name)
find_mod(mod_name).send("bump_#{type}_version")
end
|
#commit(message, remote = false) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/release_manager/puppetfile.rb', line 32
def commit(message, remote = false)
message = "[ReleaseManager] - #{message}"
if remote
actions = [{
action: 'update',
file_path: puppetfile.split(repo.workdir).last,
content: to_s
}]
obj = vcs_create_commit(source, 'master', message, actions)
obj.id if obj
else
write_to_file
add_file(puppetfile)
create_commit(message)
end
end
|
#diff(a, b) ⇒ Object
147
148
149
|
# File 'lib/release_manager/puppetfile.rb', line 147
def diff(a,b)
FileUtils.compare_stream(a,b)
end
|
#find_mod(name) ⇒ Object
Returns ControlMod - a ControlMod object.
98
99
100
101
102
103
104
105
|
# File 'lib/release_manager/puppetfile.rb', line 98
def find_mod(name)
mod_name = name.strip.downcase
mod = modules[mod_name] || modules.find{ |module_name, mod| mod.repo =~ /#{mod_name}/i }
raise InvalidModuleNameException.new("Invalid module name #{name}, cannot locate in Puppetfile") unless mod
return mod.last if mod.instance_of?(Array)
mod
end
|
#find_mods(names) ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'lib/release_manager/puppetfile.rb', line 86
def find_mods(names)
mods = {}
return mods if names.nil?
names.each do | mod_name |
m = find_mod(mod_name)
mods[m.name] = m
end
mods
end
|
#forge(name, *args) ⇒ Object
179
180
181
|
# File 'lib/release_manager/puppetfile.rb', line 179
def forge(name, *args)
end
|
#mod(name, *args) ⇒ Object
175
176
177
|
# File 'lib/release_manager/puppetfile.rb', line 175
def mod(name, *args)
@modules[name] = ControlMod.new(name, args.flatten.first)
end
|
#mod_exists?(name) ⇒ Boolean
Returns - true if the module is found.
109
110
111
112
113
114
115
|
# File 'lib/release_manager/puppetfile.rb', line 109
def mod_exists?(name)
begin
!!find_mod(name)
rescue InvalidModuleNameException
false
end
end
|
#path ⇒ Object
Returns the value of attribute base_path.
16
17
18
|
# File 'lib/release_manager/puppetfile.rb', line 16
def base_path
@base_path
end
|
#push(remote, branch, force = false, tags = true) ⇒ Object
57
58
59
60
|
# File 'lib/release_manager/puppetfile.rb', line 57
def push(remote, branch, force = false, tags = true)
push_branch(remote, branch, force)
push_tags(remote) if tags
end
|
#source ⇒ Object
24
25
26
|
# File 'lib/release_manager/puppetfile.rb', line 24
def source
puppetmodule.source
end
|
#to_json(pretty = false) ⇒ Object
139
140
141
142
143
144
145
|
# File 'lib/release_manager/puppetfile.rb', line 139
def to_json(pretty = false)
if pretty
JSON.pretty_generate(modules)
else
modules.to_json
end
end
|
#to_s ⇒ Object
161
162
163
|
# File 'lib/release_manager/puppetfile.rb', line 161
def to_s
modules.sort.collect {|n, mod| mod.to_s }.join("\n\n")
end
|
#write_source(mod_name, src, branch = nil) ⇒ ControlMod
126
127
128
129
130
131
|
# File 'lib/release_manager/puppetfile.rb', line 126
def write_source(mod_name, src, branch = nil)
mod = find_mod(mod_name)
mod.pin_url(src)
mod.pin_branch(branch) if branch
mod
end
|
#write_to_file ⇒ Boolean
Returns - true if writing to file occurred, false otherwise.
152
153
154
155
156
157
158
159
|
# File 'lib/release_manager/puppetfile.rb', line 152
def write_to_file
contents = to_s
a = StringIO.new(contents)
b = File.new(puppetfile)
return false if FileUtils.compare_stream(a,b)
File.write(puppetfile, to_s)
end
|
#write_version(mod_name, version) ⇒ Object
117
118
119
120
|
# File 'lib/release_manager/puppetfile.rb', line 117
def write_version(mod_name, version)
mod = find_mod(mod_name)
mod.pin_version(version)
end
|