Sha256: 26e95141e4be40985dc617f7ae9aca469b9359e4e7e574495890ef3add0ebb58

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module EventSourceryGenerators
  module Generators
    class Reactor < Thor::Group
      include Thor::Actions

      argument :reactor_name
      argument :event_names, type: :array, default: []

      def self.source_root
        File.join(File.dirname(__FILE__), 'templates/reactor')
      end

      def create_reactor
        template('reactor.rb.tt', "app/reactors/#{reactor_name}.rb")
      end

      def add_reactor_to_rakefile
        insert_into_file('Rakefile', erb_file('reactor_process.tt'), after: "processors = [\n")
      end

      private

      def project_name
        @project_name ||= File.split(Dir.pwd).last
      end

      def project_class_name
        @project_class_name ||= project_name.underscore.camelize
      end

      def reactor_class_name
        @reactor_class_name ||= reactor_name.underscore.camelize
      end

      def erb_file(file)
        path = File.join(self.class.source_root, file)
        ERB.new(::File.binread(path), nil, "-", "@output_buffer").result(binding)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
event_sourcery_generators-0.2.0 lib/event_sourcery_generators/generators/reactor.rb