Class: EventSourceryGenerators::Generators::Command
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- EventSourceryGenerators::Generators::Command
- Includes:
- Thor::Actions
- Defined in:
- lib/event_sourcery_generators/generators/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_command_file ⇒ Object
- #create_event ⇒ Object
- #create_or_inject_into_aggregate_file ⇒ Object
- #inject_command_to_api ⇒ Object
Class Method Details
.source_root ⇒ Object
9 10 11 |
# File 'lib/event_sourcery_generators/generators/command.rb', line 9 def self.source_root File.join(File.dirname(__FILE__), 'templates/command') end |
Instance Method Details
#create_command_file ⇒ Object
27 28 29 |
# File 'lib/event_sourcery_generators/generators/command.rb', line 27 def create_command_file template('command.rb.tt', "app/commands/#{aggregate}/#{command}.rb") end |
#create_event ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/event_sourcery_generators/generators/command.rb', line 31 def create_event event_file = "app/events/#{event_name}.rb" unless File.exist?(event_file) template('event.rb.tt', event_file) end end |
#create_or_inject_into_aggregate_file ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/event_sourcery_generators/generators/command.rb', line 13 def create_or_inject_into_aggregate_file aggregate_file = "app/aggregates/#{aggregate_name}.rb" @command_method = erb_file('aggregate/command_method.rb.tt') @apply_event_method = erb_file('aggregate/apply_event_method.rb.tt') if File.exist?(aggregate_file) insert_into_file(aggregate_file, @command_method, after: "include EventSourcery::AggregateRoot\n") insert_into_file(aggregate_file, @apply_event_method, after: "include EventSourcery::AggregateRoot\n") else template('aggregate.rb.tt', aggregate_file) end end |
#inject_command_to_api ⇒ Object
39 40 41 42 43 |
# File 'lib/event_sourcery_generators/generators/command.rb', line 39 def inject_command_to_api insert_into_file('app/web/server.rb', after: "< Sinatra::Base\n") do erb_file('api_endpoint.rb.tt') end end |