Class: EventSourcedRecord::EventSourcedRecordGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/event_sourced_record/event_sourced_record_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_calculator_classObject



9
10
11
# File 'lib/generators/event_sourced_record/event_sourced_record_generator.rb', line 9

def create_calculator_class
  generate "event_sourced_record:calculator", "#{file_name}_calculator"
end

#create_eventObject



13
14
15
16
17
18
19
# File 'lib/generators/event_sourced_record/event_sourced_record_generator.rb', line 13

def create_event
  arguments = [
    "#{file_name}_uuid:string:index", "event_type:string", 
    "data:text", "created_at:datetime", "occurred_at:datetime"
  ].join(' ')
  generate "event_sourced_record:event", "#{file_name}_event #{arguments}"
end

#create_observerObject



21
22
23
# File 'lib/generators/event_sourced_record/event_sourced_record_generator.rb', line 21

def create_observer
  generate "event_sourced_record:observer", "#{file_name}_event_observer"
end

#create_projectionObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/event_sourced_record/event_sourced_record_generator.rb', line 25

def create_projection
  attr_strings = attributes.map { |attr|
    attr_string = attr.name
    attr_string << ":#{attr.type}" if attr.type
    attr_string << ':index' if attr.has_index?
    attr_string
  }
  projection_attributes = attr_strings.join(' ')
  generate "event_sourced_record:projection", "#{file_name} #{projection_attributes}"
end

#create_rake_fileObject



36
37
38
39
40
41
# File 'lib/generators/event_sourced_record/event_sourced_record_generator.rb', line 36

def create_rake_file
  template(
    "event_sourced_record.rake", 
    File.join("lib/tasks", class_path, "#{file_name}.rake")
  )
end