Sha256: 43142c06aab51806c98814cd71ee5f44dbfbd98e808964af0f9eabecc8373477

Contents?: true

Size: 1.05 KB

Versions: 44

Compression:

Stored size: 1.05 KB

Contents

module Picky
  
  module Generators

    # Selects the right generator.
    #
    class Selector
  
      attr_reader :types

      def initialize
        @types = {
          :sinatra_client       => [Client::Sinatra, :sinatra_client_name],
          :unicorn_server       => [Server::Unicorn, :unicorn_server_name],
          :empty_unicorn_server => [Server::EmptyUnicorn, :empty_unicorn_server_name] 
        }
      end

      # Run the generators with this command.
      #
      # This will "route" the commands to the right specific generator.
      #
      def generate *args
        generator = generator_for *args
        generator.generate
      end

      #
      #
      def generator_for identifier = nil, *args
        generator_info = types[identifier.to_sym]
        generator_class = generator_info.first
        generator_for_class generator_class, identifier, *args
      rescue
        raise NotFoundException.new(self)
      end

      #
      #
      def generator_for_class klass, *args
        klass.new *args
      end
    end
    
  end
  
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
picky-generators-1.1.5 lib/picky-generators/generators/selector.rb
picky-generators-1.1.4 lib/picky-generators/generators/selector.rb
picky-generators-1.1.3 lib/picky-generators/generators/selector.rb
picky-generators-1.1.2 lib/picky-generators/generators/selector.rb