Sha256: 9c195df720009d5ba59e4bed1d9df95364ec32d3e063ccb542cf747474dca74f

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

module Playmo
  module Recipe
    class Dsl < Playmo::Recipe::Recipe
      attr_accessor :description, :name, :options, :after

      def initialize(name, options, &block)
        super()

        raise 'Recipe name not specified!' unless name

        @name    = name
        @options = options

        instance_eval &block
      end

      def description(description = nil)
        @description = description if description.present?
        @description
      end

      # Если блок с агрументами - то поддерживается ввод данных пользователем
      def question(question, &block)
        actions << lambda { Playmo::Question.new(self, question, :type => :question, &block).to_s }
      end

      def ask(question, &block)
        actions << lambda { Playmo::Question.new(self, question, :type => :ask, &block).to_s }
      end

      def silently(&block)
        actions << lambda { Playmo::Silent.new(self, &block) }
      end

      # TODO: Сделать автолоадинг для зависимых рецептов
      def after(after)
        @after = after
        after_recipe = Playmo::Cookbook.instance.find_recipe(@after)

        if after_recipe.nil? && @after.present?
          #$:.each {|path| puts "!#{path}!"}
          #raise "FUCK!!!"

          #require "#{Playmo::ROOT}/recipes/#{@after}_recipe.rb"
          begin
            require "#{@after}_recipe.rb"
          rescue LoadError => e
            puts "Cannot load recipe '#{@after}_recipe.rb'!"
            puts "LOAD PATHS:\n#{$:.join("\n")}"
            exit!
          end
        end

        if after_recipe.nil?
          Playmo::Cookbook.instance.use(self)
        else
          Playmo::Cookbook.instance.insert_after(after_recipe, self)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
playmo-0.1.10 lib/playmo/recipe/dsl.rb
playmo-0.1.9 lib/playmo/recipe/dsl.rb
playmo-0.1.8 lib/playmo/recipe/dsl.rb