Class: ChefDK::Command::GeneratorCommands::App

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

Overview

## App chef generate app path/to/basename –generator-cookbook=path/to/generator

Generates a full “application” directory structure.

Instance Attribute Summary collapse

Attributes inherited from Base

#params

Instance Method Summary collapse

Methods inherited from Base

#chef_runner, #generator_context, #generator_cookbook_path, #have_git?

Methods inherited from Base

#needs_help?, #needs_version?, #run_with_default_options

Methods included from Helpers

#err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_root, #stderr, #stdout, #system_command

Constructor Details

#initialize(params) ⇒ App

Returns a new instance of App.



120
121
122
123
124
# File 'lib/chef-dk/command/generator_commands.rb', line 120

def initialize(params)
  @params_valid = true
  @app_name = nil
  super
end

Instance Attribute Details

#app_name_or_pathObject (readonly)

Returns the value of attribute app_name_or_path.



116
117
118
# File 'lib/chef-dk/command/generator_commands.rb', line 116

def app_name_or_path
  @app_name_or_path
end

#errorsObject (readonly)

Returns the value of attribute errors.



115
116
117
# File 'lib/chef-dk/command/generator_commands.rb', line 115

def errors
  @errors
end

Instance Method Details

#app_full_pathObject



165
166
167
# File 'lib/chef-dk/command/generator_commands.rb', line 165

def app_full_path
  File.expand_path(app_name_or_path, Dir.pwd)
end

#app_nameObject



149
150
151
# File 'lib/chef-dk/command/generator_commands.rb', line 149

def app_name
  File.basename(app_full_path)
end

#app_rootObject



153
154
155
# File 'lib/chef-dk/command/generator_commands.rb', line 153

def app_root
  File.dirname(app_full_path)
end

#cookbook_nameObject



161
162
163
# File 'lib/chef-dk/command/generator_commands.rb', line 161

def cookbook_name
  app_name
end

#cookbook_rootObject



157
158
159
# File 'lib/chef-dk/command/generator_commands.rb', line 157

def cookbook_root
  File.join(app_full_path, 'cookbooks')
end

#params_valid?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/chef-dk/command/generator_commands.rb', line 175

def params_valid?
  @params_valid
end

#read_and_validate_paramsObject



169
170
171
172
173
# File 'lib/chef-dk/command/generator_commands.rb', line 169

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

#recipeObject



145
146
147
# File 'lib/chef-dk/command/generator_commands.rb', line 145

def recipe
  "app"
end

#runObject



126
127
128
129
130
131
132
133
134
135
# File 'lib/chef-dk/command/generator_commands.rb', line 126

def run
  read_and_validate_params
  if params_valid?
    setup_context
    chef_runner.converge
  else
    msg(banner)
    1
  end
end

#setup_contextObject



137
138
139
140
141
142
143
# File 'lib/chef-dk/command/generator_commands.rb', line 137

def setup_context
  super
  generator_context.app_root = app_root
  generator_context.app_name = app_name
  generator_context.cookbook_root ||= cookbook_root
  generator_context.cookbook_name ||= cookbook_name
end