Class: CookbookBumper::Metadata
- Inherits:
-
Object
- Object
- CookbookBumper::Metadata
show all
- Defined in:
- lib/cookbook_bumper/metadata.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path) ⇒ Metadata
Returns a new instance of Metadata.
9
10
11
12
13
14
|
# File 'lib/cookbook_bumper/metadata.rb', line 9
def initialize(path)
@path = path
@aliases = []
@metadata = parse(path)
@version = CookbookBumper::Version.new(@metadata.version)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *args, &block) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/cookbook_bumper/metadata.rb', line 43
def method_missing(method_sym, *args, &block)
if respond_to?(method_sym)
@metadata.send(method_sym, *args, &block)
else
puts "Couldn't find method #{method_sym}"
super
end
end
|
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
7
8
9
|
# File 'lib/cookbook_bumper/metadata.rb', line 7
def aliases
@aliases
end
|
#path ⇒ Object
Returns the value of attribute path.
7
8
9
|
# File 'lib/cookbook_bumper/metadata.rb', line 7
def path
@path
end
|
#version ⇒ Object
Returns the value of attribute version.
7
8
9
|
# File 'lib/cookbook_bumper/metadata.rb', line 7
def version
@version
end
|
Instance Method Details
#bump ⇒ Object
28
29
30
31
|
# File 'lib/cookbook_bumper/metadata.rb', line 28
def bump
version.bump
save
end
|
#bumped? ⇒ Boolean
24
25
26
|
# File 'lib/cookbook_bumper/metadata.rb', line 24
def bumped?
@version != @metadata.version
end
|
#parse(path) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/cookbook_bumper/metadata.rb', line 16
def parse(path)
metadata = Chef::Cookbook::Metadata.new.tap { |m| m.from_file(path); m } path.match(%r{/(?<cookbook_dir>[^/]+)/metadata\.rb$}) do |m|
@aliases |= [m[:cookbook_dir]] if metadata.name != m[:cookbook_dir]
end
metadata
end
|
#respond_to_missing?(method_sym, include_private = false) ⇒ Boolean
52
53
54
|
# File 'lib/cookbook_bumper/metadata.rb', line 52
def respond_to_missing?(method_sym, include_private = false)
@metadata.respond_to?(method_sym) || super
end
|
#save ⇒ Object
39
40
41
|
# File 'lib/cookbook_bumper/metadata.rb', line 39
def save
File.write(path, updated_contents)
end
|
#updated_contents ⇒ Object
33
34
35
36
37
|
# File 'lib/cookbook_bumper/metadata.rb', line 33
def updated_contents
File.read(path).sub(/^\s*version.*/) do |version_line|
version_line.sub(/[\d\.]+/, @metadata.version => @version)
end
end
|