Sha256: df598681ebd2da02c78948387f2be881e6a055bf7ed872308a31a84a985ebf68

Contents?: true

Size: 1019 Bytes

Versions: 22

Compression:

Stored size: 1019 Bytes

Contents

module Bourdain
  module Generators

    class AttributeGenerator < Generator
      usage :generator, <<-END
        Generate a new attribute file in the current cookbook
        attribute [<options>] <name>
      END


      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
    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bourdain-1.2.14 lib/bourdain/resources/generators/attribute.rb
bourdain-1.2.13 lib/bourdain/resources/generators/attribute.rb