Class: Drails::Generators::ScaffoldGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Drails::Generators::ScaffoldGenerator
- Includes:
- Domain, ProcessorName
- Defined in:
- lib/generators/drails/scaffold/scaffold_generator.rb
Instance Method Summary collapse
- #add_event_stream_client_to_views ⇒ Object
- #add_routes ⇒ Object
- #add_to_command_processor ⇒ Object
- #copy_event_stream_client ⇒ Object
- #create_commands ⇒ Object
- #create_controller ⇒ Object
- #create_models ⇒ Object
Methods included from Domain
Methods included from ProcessorName
Instance Method Details
#add_event_stream_client_to_views ⇒ Object
54 55 56 57 58 |
# File 'lib/generators/drails/scaffold/scaffold_generator.rb', line 54 def add_event_stream_client_to_views include_text = '<%= javascript_tag render partial: \'eventstream\', formats: [:js], locals: {event_id: @event_id} %>' prepend_to_file File.join('app/views', class_path, plural_file_name, 'index.html.erb'), include_text prepend_to_file File.join('app/views', class_path, plural_file_name, 'show.html.erb'), include_text end |
#add_routes ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/drails/scaffold/scaffold_generator.rb', line 34 def add_routes routing_code = "" class_path.each_with_index do |ns, i| add_line_with_indent routing_code, (i + 1), "namespace :#{ns} do" end add_line_with_indent routing_code, (class_path.length + 1), "resources :#{plural_name}" class_path.each_with_index do |ns, i| add_line_with_indent routing_code, (class_path.length - i), "end" end route routing_code[2..-1] end |
#add_to_command_processor ⇒ Object
28 29 30 31 32 |
# File 'lib/generators/drails/scaffold/scaffold_generator.rb', line 28 def add_to_command_processor content = " command.id = ActiveDomain::UniqueCommandIdRepository.new_for command.class.name" inject_into_file File.join('domain/command_processors', domain_class_path, "#{processor_file_name}_processor.rb"), content, after: /(\s)*process(\s)*(.)*CreateCommand(.)*/ end |
#copy_event_stream_client ⇒ Object
50 51 52 |
# File 'lib/generators/drails/scaffold/scaffold_generator.rb', line 50 def copy_event_stream_client copy_file '_eventstream.js.erb', File.join('app', 'views', 'application', '_eventstream.js.erb') end |
#create_commands ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/generators/drails/scaffold/scaffold_generator.rb', line 16 def create_commands %w(create update delete).each do |action| attr_arg = attributes_names.join(' ') unless action == 'delete' command = (class_path + ["#{action}_#{file_name}"]) * '/' event_arg = "--event=" + (class_path + ["#{action}d_#{file_name}"]) * '/' processor_arg = "--processor=#{processor_name}" processor_arg = "--skip-processor" if skip_processor? generate 'drails:command', command, attr_arg, processor_arg, event_arg add_to_projections(action) end end |
#create_controller ⇒ Object
46 47 48 |
# File 'lib/generators/drails/scaffold/scaffold_generator.rb', line 46 def create_controller generate 'drails:controller', name, attr_string end |
#create_models ⇒ Object
12 13 14 |
# File 'lib/generators/drails/scaffold/scaffold_generator.rb', line 12 def create_models generate 'drails:model', name, attr_string end |