Sha256: a654028cf1b3ac3e59267be5427aa882b7cd42cfe452f84d2f3fa891df145b96

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module PicoApi
  module Generators
    class Generator
      class << self
        def call(project_name)
          new(project_name, loaded_commands).call
        end

        def loaded_commands
          command_files.sort.map do |file_path|
            file_name = camelized_file_name(file_path)
            "PicoApi::Generators::Commands::#{file_name}".constantize
          end.compact
        end

        private

        def command_files
          Dir[File.join(PicoApi.lib_path, '/generators/commands/*.rb')]
        end

        def camelized_file_name(file_path)
          file_path.split('/').last.gsub('.rb', '').camelize
        end
      end

      def initialize(project_name, commands = [])
        raise 'Missing project name' unless project_name

        @project_name = project_name
        @commands = commands
      end

      def call
        commands.each { |command| command.call(project_name) }
      end

      private

      attr_reader :project_name, :commands
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pico_api-0.1.0 lib/pico_api/generators/generator.rb
pico_api-0.0.6 lib/pico_api/generators/generator.rb
pico_api-0.0.5 lib/pico_api/generators/generator.rb