Sha256: 1a5d2e507e2baea556fd9bb5722eec880f3261235b42b792527b35b253473b7a

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

module Bourdain
  module Generators

    class RecipeGenerator < Generator
      usage :generator, <<-END
        Generate a new recipe in the current cookbook
        recipe [<options>] <name>
          --minitest :: Generate a minitest file (default: true)
      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 'recipes'
        path = File.join('recipes', name + '.rb')

        if File::exists? path
          log.warn 'Recipe already exists. Doing nothing.'
          return
        end

        cookbook_name = File.basename Dir.pwd

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

        if opts[:minitest]
          minitest_path = File.join('files', 'default', 'test', "#{name}_test.rb")
          FileUtils.mkdir_p File.dirname(minitest_path)
          apply_template minitest_path, \
            template: %w[ cookbook busser_minitest.rb ], locals: {
              cookbook_name: cookbook_name, recipe_name: name
            }
          log.info "Generated test for recipe at #{minitest_path}."
        end

        log.info "Generated recipe at #{path}"
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bourdain-1.6.3 lib/bourdain/resources/generators/recipe.rb
bourdain-1.6.2 lib/bourdain/resources/generators/recipe.rb
bourdain-1.6.1 lib/bourdain/resources/generators/recipe.rb
bourdain-1.6.0 lib/bourdain/resources/generators/recipe.rb
bourdain-1.5.1 lib/bourdain/resources/generators/recipe.rb
bourdain-1.5.0 lib/bourdain/resources/generators/recipe.rb
bourdain-1.4.1 lib/bourdain/resources/generators/recipe.rb
bourdain-1.4.0 lib/bourdain/resources/generators/recipe.rb
bourdain-1.3.3 lib/bourdain/resources/generators/recipe.rb