Sha256: 7e0181750bd99e235dc67d75736c03b4d5cc16d879b655bd9be65c51a3902c4a

Contents?: true

Size: 1.46 KB

Versions: 13

Compression:

Stored size: 1.46 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('test', 'integration', 'default', 'minitest', "test_#{name}.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

13 entries across 13 versions & 1 rubygems

Version Path
bourdain-1.3.2 lib/bourdain/resources/generators/recipe.rb
bourdain-1.3.1 lib/bourdain/resources/generators/recipe.rb
bourdain-1.3.0 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.22 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.21 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.20 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.19 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.18 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.17 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.16 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.15 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.14 lib/bourdain/resources/generators/recipe.rb
bourdain-1.2.13 lib/bourdain/resources/generators/recipe.rb