Sha256: a6b32e3634e9a2ce57c72065327e70156e7134ad71a9fda1947b5f4ea0b6ad7d

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

require 'rails/generators'

module Playmo
  # Base class for all recipes
  class Recipe < Rails::Generators::Base
    attr_accessor :question_instance, :silents, :application_name

    # Приготовление рецепта
    def cook!(application_name)
      self.destination_root = application_name
      self.application_name = application_name
      setup

      unless question_instance.nil?
        question_instance.set_caller(self)

        # Ask question
        question_instance.ask_question!

        # Ask for choice and make choice
        question_instance.choice.make_choice!
      end

      # Execute all silents
      unless silents.nil?
        silents.each do |silent|
          silent.set_caller(self)
          silent.execute!
        end
      end
    end

    def question(arg, &block)
      @question_instance = Playmo::Question.new(arg, &block)
    end

    def silently(&block)
      @silents ||= []
      @silents << Playmo::Silent.new(&block)
    end

    def store(*args)
      Options.instance.set(*args)
    end

    def retrieve(*args)
      Options.instance.get(*args)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
playmo-0.0.18 lib/playmo/recipe.rb
playmo-0.0.17 lib/playmo/recipe.rb
playmo-0.0.14 lib/playmo/recipe.rb
playmo-0.0.13 lib/playmo/recipe.rb
playmo-0.0.12 lib/playmo/recipe.rb
playmo-0.0.11 lib/playmo/recipe.rb
playmo-0.0.10 lib/playmo/recipe.rb