Class: Bourdain::Generators::AttributeGenerator

Inherits:
Generator show all
Defined in:
lib/bourdain/resources/generators/attribute.rb

Instance Attribute Summary

Attributes inherited from Resource

#opts, #raw_usage, #resource_name, #spec, #status

Instance Method Summary collapse

Methods inherited from Resource

log=, raw_usage, resource_name, usage

Constructor Details

#initialize(argv) ⇒ AttributeGenerator

Returns a new instance of AttributeGenerator.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bourdain/resources/generators/attribute.rb', line 11

def initialize argv
  super

  name = argv.shift
  Trollop::die 'No <name> provided' if name.nil?
  Trollop::die 'Invalid <name> provided' unless valid? name
  name = normalized(name)

  return unless require_cookbook!

  FileUtils.mkdir_p 'attributes'
  path = File.join('attributes', name + '.rb')

  if File::exists? path
    log.warn "Attribute file already exists. Doing nothing."
    return
  end

  cookbook_name = File.basename Dir.pwd

  apply_template path, \
    template: %w[ cookbook attributes example.rb ],
    locals: {
      cookbook_name: cookbook_name,
      name: name
    }

  log.info "Generated attribute file at #{path}"
end