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
-
#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) ⇒ Object
-
#source ⇒ Object
-
#to_json(pretty = false) ⇒ Object
-
#to_s ⇒ Object
-
#write_source(mod_name, src, branch = nil) ⇒ ControlMod
-
#write_to_file ⇒ Object
-
#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, #find_or_create_remote, #find_ref, #get_content, #git_command, #git_url?, #push_branch, #push_tags, #rebase_branch, #remote_exists?, #remote_from_name, #remote_from_url, #remote_url_matches?, #remove_file, #repo, #transports, #up2date?, #update_cli_index
Constructor Details
#initialize(puppetfile = 'Puppetfile') ⇒ Puppetfile
Returns a new instance of Puppetfile.
18
19
20
21
|
# File 'lib/release_manager/puppetfile.rb', line 18
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.
8
9
10
|
# File 'lib/release_manager/puppetfile.rb', line 8
def base_path
@base_path
end
|
#data ⇒ Object
Returns the value of attribute data.
8
9
10
|
# File 'lib/release_manager/puppetfile.rb', line 8
def data
@data
end
|
Returns - a list of control mod objects.
65
66
67
|
# File 'lib/release_manager/puppetfile.rb', line 65
def modules
@modules
end
|
#puppetfile ⇒ Object
Returns the value of attribute puppetfile.
8
9
10
|
# File 'lib/release_manager/puppetfile.rb', line 8
def puppetfile
@puppetfile
end
|
#puppetmodule ⇒ Object
Returns the value of attribute puppetmodule.
8
9
10
|
# File 'lib/release_manager/puppetfile.rb', line 8
def puppetmodule
@puppetmodule
end
|
Class Method Details
.from_string(s) ⇒ Object
73
74
75
76
77
|
# File 'lib/release_manager/puppetfile.rb', line 73
def self.from_string(s)
instance = new
instance.data = s
instance
end
|
.to_puppetfile(json_data) ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/release_manager/puppetfile.rb', line 150
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
48
49
50
|
# File 'lib/release_manager/puppetfile.rb', line 48
def add_module(name, metadata)
modules[name] = ControlMod.new(name, metadata)
end
|
#bump(mod_name, type = 'patch') ⇒ Object
128
129
130
131
132
|
# File 'lib/release_manager/puppetfile.rb', line 128
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/release_manager/puppetfile.rb', line 31
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
|
#find_mod(name) ⇒ Object
Returns ControlMod - a ControlMod object.
93
94
95
96
97
98
99
100
|
# File 'lib/release_manager/puppetfile.rb', line 93
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
81
82
83
84
85
86
87
88
89
|
# File 'lib/release_manager/puppetfile.rb', line 81
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
164
165
166
|
# File 'lib/release_manager/puppetfile.rb', line 164
def forge(name, *args)
end
|
#mod(name, *args) ⇒ Object
160
161
162
|
# File 'lib/release_manager/puppetfile.rb', line 160
def mod(name, *args)
@modules[name] = ControlMod.new(name, args.flatten.first)
end
|
#mod_exists?(name) ⇒ Boolean
Returns - true if the module is found.
104
105
106
107
108
109
110
|
# File 'lib/release_manager/puppetfile.rb', line 104
def mod_exists?(name)
begin
!!find_mod(name)
rescue InvalidModuleNameException
false
end
end
|
#path ⇒ Object
Returns the value of attribute base_path.
15
16
17
|
# File 'lib/release_manager/puppetfile.rb', line 15
def base_path
@base_path
end
|
#push(remote, branch, force = false) ⇒ Object
52
53
54
55
|
# File 'lib/release_manager/puppetfile.rb', line 52
def push(remote, branch, force = false)
push_branch(remote, branch, force)
push_tags(remote)
end
|
#source ⇒ Object
23
24
25
|
# File 'lib/release_manager/puppetfile.rb', line 23
def source
puppetmodule.source
end
|
#to_json(pretty = false) ⇒ Object
134
135
136
137
138
139
140
|
# File 'lib/release_manager/puppetfile.rb', line 134
def to_json(pretty = false)
if pretty
JSON.pretty_generate(modules)
else
modules.to_json
end
end
|
#to_s ⇒ Object
146
147
148
|
# File 'lib/release_manager/puppetfile.rb', line 146
def to_s
modules.sort.collect {|n, mod| mod.to_s }.join("\n\n")
end
|
#write_source(mod_name, src, branch = nil) ⇒ ControlMod
121
122
123
124
125
126
|
# File 'lib/release_manager/puppetfile.rb', line 121
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 ⇒ Object
142
143
144
|
# File 'lib/release_manager/puppetfile.rb', line 142
def write_to_file
File.write(puppetfile, to_s)
end
|
#write_version(mod_name, version) ⇒ Object
112
113
114
115
|
# File 'lib/release_manager/puppetfile.rb', line 112
def write_version(mod_name, version)
mod = find_mod(mod_name)
mod.pin_version(version)
end
|