Class: MotherBrain::CookbookMetadata

Inherits:
Ridley::Chef::Cookbook::Metadata
  • Object
show all
Defined in:
lib/mb/cookbook_metadata.rb

Constant Summary collapse

RUBY_FILENAME =
'metadata.rb'.freeze
JSON_FILENAME =
'metadata.json'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ CookbookMetadata

Returns a new instance of CookbookMetadata.

Parameters:

  • (Cookbook::Metadata)


51
52
53
54
55
56
57
58
59
# File 'lib/mb/cookbook_metadata.rb', line 51

def initialize(&block)
  super
  
  begin
    self.instance_eval(&block) if block_given?
  rescue => e
    raise MotherBrain::InvalidCookbookMetadata, e
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object (private)



70
# File 'lib/mb/cookbook_metadata.rb', line 70

def method_missing(*args); nil end

Class Method Details

.from_file(filepath) ⇒ Cookbook::Metadata

Parameters:

  • filepath (#to_s)

Returns:

  • (Cookbook::Metadata)


18
19
20
21
22
23
24
25
26
# File 'lib/mb/cookbook_metadata.rb', line 18

def from_file(filepath)
  filepath = filepath.to_s

  if File.extname(filepath) =~ /\.json/
    from_json_file(filepath)
  else
    from_ruby_file(filepath)
  end
end

.from_path(path) ⇒ Cookbook::Metadata

Parameters:

  • path (#to_s)

Returns:

  • (Cookbook::Metadata)


31
32
33
34
35
36
37
# File 'lib/mb/cookbook_metadata.rb', line 31

def from_path(path)
  ruby_file     = File.join(path, RUBY_FILENAME)
  json_file     = File.join(path, JSON_FILENAME)
   = File.exists?(json_file) ? json_file : ruby_file

  from_file()
end

.load(&block) ⇒ Cookbook::Metadata

Returns:

  • (Cookbook::Metadata)


9
10
11
12
13
# File 'lib/mb/cookbook_metadata.rb', line 9

def load(&block)
  klass = new()
  klass.instance_eval(&block) if block_given?
  klass
end

Instance Method Details

#version(data = nil) ⇒ Semverse::Version

Override the default version with [Semverse::Version]

Returns:

  • (Semverse::Version)


64
65
66
# File 'lib/mb/cookbook_metadata.rb', line 64

def version(data = nil)
  @version = data.nil? ? @version : Semverse::Version.new(data)
end