Class: Berktacular::Cookbook
- Inherits:
-
Object
- Object
- Berktacular::Cookbook
- Defined in:
- lib/berktacular/cookbook.rb
Overview
This class represents a cookbook entry from a Berksfile
Instance Attribute Summary collapse
-
#auto_upgrade ⇒ True, False
readonly
Whether or now this cookbook can autoupgrade.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ String
readonly
The name of the cookbook.
-
#version_number ⇒ String
readonly
The exact version of the cookbook.
Instance Method Summary collapse
-
#check_updates ⇒ Array
A list of available cookbook version newer then we started with, with most recent first.
-
#initialize(name, version_spec, config = nil, opts = {}) ⇒ Cookbook
constructor
Creates a new cookbook entry for a Berksfile.
-
#latest_version ⇒ String
The latest available version number of the cookbook.
-
#line(upgrade = @upgrade) ⇒ String
param upgrade [True,False] (‘@upgrade’) whether or not to force the lastest version when @auto_update is enabled.
-
#to_s ⇒ String
A Berksfile line for this cookbook.
-
#version_specifier ⇒ String
The exact version of the cookbook.
Constructor Details
#initialize(name, version_spec, config = nil, opts = {}) ⇒ Cookbook
Creates a new cookbook entry for a Berksfile.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/berktacular/cookbook.rb', line 28 def initialize( name, version_spec, config = nil, opts = {} ) @name = name || raise( "Missing cookbook name" ) @version_spec = version_spec || raise( "Missing cookbook version" ) @version_number = VERSION_RE.match( version_spec )[0] @version_solved = Semverse::Version.new(@version_number) @auto_upgrade = config && config['auto_upgrade'] || false @versions = config && config['versions'] || {} @location = config ? config.reject{ |k,v| k == 'auto_upgrade' || k == 'versions' } : nil @version_only = opts.has_key?(:versions_only) ? opts[:versions_only] : false @upgrade = opts.has_key?(:upgrade) ? opts[:upgrade] : false @git_client = opts.has_key?(:git_client) ? opts[:git_client].dup : nil @verbose = opts.has_key?(:verbose) ? opts[:verbose] : false @multi_cookbook_dir = opts[:multi_cookbook_dir] check_updates if @auto_upgrade && @upgrade end |
Instance Attribute Details
#auto_upgrade ⇒ True, False (readonly)
18 |
# File 'lib/berktacular/cookbook.rb', line 18 attr_reader :name, :version_number, :auto_upgrade, :config |
#config ⇒ Object (readonly)
Returns the value of attribute config.
18 |
# File 'lib/berktacular/cookbook.rb', line 18 attr_reader :name, :version_number, :auto_upgrade, :config |
#name ⇒ String (readonly)
18 19 20 |
# File 'lib/berktacular/cookbook.rb', line 18 def name @name end |
#version_number ⇒ String (readonly)
18 |
# File 'lib/berktacular/cookbook.rb', line 18 attr_reader :name, :version_number, :auto_upgrade, :config |
Instance Method Details
#check_updates ⇒ Array
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/berktacular/cookbook.rb', line 66 def check_updates tag_re = Regexp.new( "^#{ (@location || {})['tag'] || '%{version}' }$" % { version: "(#{VERSION_RE.source})" } ) @candidates ||= if @location && @location['github'] else [] end.collect do |tag| m = tag_re.match(tag) next unless m v = m[1] begin t = Semverse::Version.new(v) rescue Semverse::InvalidVersionFormat next end next unless t > @version_solved t.to_s end.compact.sort.reverse end |
#latest_version ⇒ String
50 51 52 |
# File 'lib/berktacular/cookbook.rb', line 50 def latest_version check_updates.any? ? check_updates.first : @version_number end |
#line(upgrade = @upgrade) ⇒ String
param upgrade [True,False] (‘@upgrade’) whether or not to force the lastest version when @auto_update is enabled
61 62 63 |
# File 'lib/berktacular/cookbook.rb', line 61 def line(upgrade = @upgrade) "cookbook \"#{@name}\", #{generate_conf_line(upgrade, @location )}" end |
#to_s ⇒ String
55 56 57 |
# File 'lib/berktacular/cookbook.rb', line 55 def to_s line end |
#version_specifier ⇒ String
45 46 47 |
# File 'lib/berktacular/cookbook.rb', line 45 def version_specifier "= #{(@auto_upgrade && @upgrade && check_updates.any?) ? check_updates.first : @version_number }" end |