Class: ChefDK::Command::GeneratorCommands::HabiChef

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-dk/command/generator_commands/habichef.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ HabiChef

Returns a new instance of HabiChef.



18
19
20
21
22
23
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 18

def initialize(params)
  @params_valid = true
  @habichef_name = nil
  @verbose = false
  super
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 13

def errors
  @errors
end

#habichef_name_or_pathObject (readonly)

Returns the value of attribute habichef_name_or_path.



14
15
16
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 14

def habichef_name_or_path
  @habichef_name_or_path
end

Instance Method Details

#habichef_full_pathObject



54
55
56
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 54

def habichef_full_path
  File.expand_path habichef_name_or_path, Dir.pwd
end

#habichef_nameObject



46
47
48
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 46

def habichef_name
  File.basename habichef_full_path
end

#habichef_path_in_git_repo?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 73

def habichef_path_in_git_repo?
  Pathname.new(habichef_full_path).ascend do |dir|
    return true if File.directory?(File.join(dir.to_s, ".git"))
  end
  false
end

#habichef_rootObject



50
51
52
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 50

def habichef_root
  File.dirname habichef_full_path
end

#params_valid?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 69

def params_valid?
  @params_valid
end

#read_and_validate_paramsObject



58
59
60
61
62
63
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 58

def read_and_validate_params
  arguments = parse_options(params)
  @habichef_name_or_path = arguments[0]
  @params_valid = false unless @habichef_name_or_path
  true
end

#recipeObject



65
66
67
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 65

def recipe
  'habichef'
end

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 25

def run
  read_and_validate_params
  if params_valid?
    setup_context
    chef_runner.converge
    0
  else
    err(opt_parser)
    1
  end
rescue ChefDK::ChefRunnerError => e
  err "ERROR: #{e}"
end

#setup_contextObject



39
40
41
42
43
44
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 39

def setup_context
  super
  Generator.add_attr_to_context(:habichef_name, habichef_name)
  Generator.add_attr_to_context(:habichef_root, habichef_root)
  Generator.add_attr_to_context(:skip_git_init, habichef_path_in_git_repo?)
end