Class: Kitchen::MetadataChopper

Inherits:
Hash
  • Object
show all
Defined in:
lib/kitchen/metadata_chopper.rb

Overview

A rather insane and questionable class to quickly consume a metadata.rb file and return the cookbook name and version attributes.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashRecursiveMerge

#rmerge, #rmerge!

Constructor Details

#initialize(metadata_file) ⇒ MetadataChopper

Creates a new instance and loads in the contents of the metadata.rb file. If you value your life, you may want to avoid reading the implementation.

Parameters:

  • metadata_file (String)

    path to a metadata.rb file



41
42
43
# File 'lib/kitchen/metadata_chopper.rb', line 41

def initialize()
  instance_eval(File.read(), )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &_block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Captures any attribute call made while evaluating the metadata file, storing its first argument under the attribute name.

Parameters:

  • meth (Symbol)

    the attribute name being set

  • args (Array)

    the attribute's arguments; the first becomes the value

Returns:

  • (Object)

    the stored value



52
53
54
# File 'lib/kitchen/metadata_chopper.rb', line 52

def method_missing(meth, *args, &_block)
  self[meth] = args.first
end

Class Method Details

.extract(metadata_file) ⇒ Array<String>

Return an Array containing the cookbook name and version attributes, or nil values if they could not be parsed.

Parameters:

  • metadata_file (String)

    path to a metadata.rb file

Returns:

  • (Array<String>)

    array containing the cookbook name and version attributes or nil values if they could not be determined



31
32
33
34
# File 'lib/kitchen/metadata_chopper.rb', line 31

def self.extract()
  mc = new(File.expand_path())
  [mc[:name], mc[:version]]
end