Class: Stove::Cookbook

Inherits:
Object
  • Object
show all
Includes:
Logify
Defined in:
lib/stove/cookbook.rb,
lib/stove/cookbook/metadata.rb

Defined Under Namespace

Classes: Metadata

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Cookbook

Create a new wrapper around the cookbook object.

Parameters:

  • path (String)

    the relative or absolute path to the cookbook on disk



63
64
65
66
# File 'lib/stove/cookbook.rb', line 63

def initialize(path)
  @path = Pathname.new(path).expand_path
  load_metadata!
end

Instance Attribute Details

#categoryString

The category for this cookbook on the community site.

Returns:

  • (String)


73
74
75
76
77
78
# File 'lib/stove/cookbook.rb', line 73

def category
  @category ||= Community.cookbook(name)['category']
rescue Faraday::Error::ResourceNotFound
  log.warn("Cookbook `#{name}' not found on the Chef community site")
  nil
end

#changesetString?

The changeset for this cookbook. This is written by the changelog generator and read by various plugins.

Returns:

  • (String, nil)

    the changeset for this cookbook



55
56
57
# File 'lib/stove/cookbook.rb', line 55

def changeset
  @changeset
end

#metadataStove::Cookbook::Metadata (readonly)

The metadata for this cookbook.



38
39
40
# File 'lib/stove/cookbook.rb', line 38

def 
  @metadata
end

#nameString (readonly)

The name of the cookbook (must correspond to the name of the cookbook on the community site).

Returns:

  • (String)


24
25
26
# File 'lib/stove/cookbook.rb', line 24

def name
  @name
end

#pathPathname (readonly)

The path to this cookbook on disk.

Returns:

  • (Pathname)


16
17
18
# File 'lib/stove/cookbook.rb', line 16

def path
  @path
end

#versionString (readonly)

The version of this cookbook (originally).

Returns:

  • (String)


31
32
33
# File 'lib/stove/cookbook.rb', line 31

def version
  @version
end

Instance Method Details

#bump(new_version) ⇒ String

Bump the version in the metdata.rb to the specified parameter.

Parameters:

  • new_version (String)

    the version to bump to

Returns:

  • (String)

    the new version string



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/stove/cookbook.rb', line 153

def bump(new_version)
  return true if new_version.to_s == version.to_s

   = path.join('metadata.rb')
  contents      = File.read()

  contents.sub!(/^version(\s+)('|")#{version}('|")/, "version\\1\\2#{new_version}\\3")

  File.open(, 'w') { |f| f.write(contents) }
  reload_metadata!
end

#release!Object



121
122
123
124
125
126
# File 'lib/stove/cookbook.rb', line 121

def release!
  if options[:changelog]
    log.info('Updating changelog')
    update_changelog
  end
end

#released?Boolean

Deterine if this cookbook version is released on the community site

Returns:

  • (Boolean)

    true if this cookbook at the current version exists on the community site, false otherwise



113
114
115
116
117
118
# File 'lib/stove/cookbook.rb', line 113

def released?
  Community.cookbook(name, version)
  true
rescue Faraday::Error::ResourceNotFound
  false
end

#tag_versionString

The tag version. This is just the current version prefixed with the letter “v”.

Examples:

Tag version for 1.0.0

cookbook.tag_version #=> "v1.0.0"

Returns:

  • (String)


98
99
100
# File 'lib/stove/cookbook.rb', line 98

def tag_version
  "v#{version}"
end

#tarballFile

So there’s this really really crazy bug that the tmp directory could be deleted mid-request…

Returns:

  • (File)


134
135
136
137
138
139
140
141
# File 'lib/stove/cookbook.rb', line 134

def tarball
  return @tarball if @tarball && File.exists?(@tarball)

  begin
    @tarball = Stove::Packager.new(self).package_path
  end until File.exists?(@tarball)
  @tarball
end

#urlString

The URL for the cookbook on the Community Site.

Returns:

  • (String)


85
86
87
# File 'lib/stove/cookbook.rb', line 85

def url
  URI.join(Community.base_url, 'cookbooks', name)
end