Class: CookbookCreator::Generator::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/cookbook_creator/generator.rb

Overview

This is here to hold attr_accessor data for Generator context variables

Class Method Summary collapse

Class Method Details

.add_attr(name) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/cookbook_creator/generator.rb', line 16

def self.add_attr(name)
  @attributes ||= [ ]

  if !@attributes.include?(name)
    @attributes << name
    attr_accessor(name)
  end
end

.cookbook_full_pathObject



29
30
31
# File 'lib/cookbook_creator/generator.rb', line 29

def self.cookbook_full_path
  File.expand_path(cookbook_name_or_path, Dir.pwd)
end

.cookbook_nameObject



46
47
48
# File 'lib/cookbook_creator/generator.rb', line 46

def self.cookbook_name
  File.basename(cookbook_full_path)
end

.cookbook_name_or_pathObject



33
34
35
36
# File 'lib/cookbook_creator/generator.rb', line 33

def self.cookbook_name_or_path
   name = ARGV[0]
   File.expand_path(name, Dir.pwd)
end

.cookbook_rootObject



25
26
27
# File 'lib/cookbook_creator/generator.rb', line 25

def self.cookbook_root
  File.dirname(cookbook_full_path)
end

.have_git?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/cookbook_creator/generator.rb', line 50

def self.have_git?
  path = ENV["PATH"] || ""
  paths = path.split(File::PATH_SEPARATOR)
  paths.any? {|bin_path| File.exist?(File.join(bin_path, "git#{RbConfig::CONFIG['EXEEXT']}"))}
end

.recipeObject



38
39
40
# File 'lib/cookbook_creator/generator.rb', line 38

def self.recipe
  "cookbook"
end

.recipe_nameObject



42
43
44
# File 'lib/cookbook_creator/generator.rb', line 42

def self.recipe_name
  "default"
end

.resetObject



56
57
58
59
60
61
62
63
64
# File 'lib/cookbook_creator/generator.rb', line 56

def self.reset
  return if @attributes.nil?

  @attributes.each do |attr|
    remove_method(attr)
  end

  @attributes = nil
end