drailties 0.4.3 → 0.5.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +6 -14
  2. data/bin/drails +4 -42
  3. data/lib/drails/app_drails_loader.rb +62 -0
  4. data/lib/drails/cli.rb +11 -0
  5. data/lib/drails/commands/application.rb +43 -0
  6. data/lib/drails/commands/destroy.rb +12 -0
  7. data/lib/drails/commands/domainserver.rb +6 -0
  8. data/lib/drails/commands/generate.rb +12 -0
  9. data/lib/drails/commands/projectionserver.rb +9 -0
  10. data/lib/drails/commands/server.rb +22 -0
  11. data/lib/drails/commands.rb +70 -0
  12. data/lib/drails/generators.rb +48 -0
  13. data/lib/drails/server/domain_server.rb +4 -1
  14. data/lib/drails/server/projection_servers.rb +5 -2
  15. data/lib/generators/drails/app/USAGE +12 -12
  16. data/lib/generators/drails/app/app_generator.rb +134 -52
  17. data/lib/generators/drails/app/templates/{event_source_controller.rb → app/controllers/event_source_controller.rb} +15 -15
  18. data/lib/generators/drails/app/templates/bin/drails +3 -0
  19. data/lib/generators/drails/app/templates/config/disco.yml +27 -0
  20. data/lib/generators/drails/app/templates/{build_validations_registry.rb → config/initializers/build_validations_registry.rb} +18 -18
  21. data/lib/generators/drails/app/templates/{create_domain.rb → config/initializers/create_domain.rb} +4 -4
  22. data/lib/generators/drails/app/templates/db/seeds.rb +14 -0
  23. data/lib/generators/drails/command/USAGE +11 -11
  24. data/lib/generators/drails/command/command_generator.rb +68 -40
  25. data/lib/generators/drails/command/templates/command.rb +24 -6
  26. data/lib/generators/drails/command/templates/event.rb +11 -10
  27. data/lib/generators/drails/command_processor/USAGE +1 -1
  28. data/lib/generators/drails/command_processor/command_processor_generator.rb +22 -15
  29. data/lib/generators/drails/command_processor/templates/command_processor.rb +5 -5
  30. data/lib/generators/drails/domain.rb +18 -18
  31. data/lib/generators/drails/event_name.rb +51 -51
  32. data/lib/generators/drails/migration/USAGE +41 -1
  33. data/lib/generators/drails/migration/migration_generator.rb +27 -28
  34. data/lib/generators/drails/migration/templates/create_table_migration.rb +19 -19
  35. data/lib/generators/drails/model/USAGE +17 -17
  36. data/lib/generators/drails/model/model_generator.rb +29 -23
  37. data/lib/generators/drails/model/templates/domain_model.rb +5 -5
  38. data/lib/generators/drails/model/templates/model.rb +4 -4
  39. data/lib/generators/drails/processor_name.rb +47 -47
  40. data/lib/generators/drails/projection/projection_generator.rb +3 -3
  41. data/lib/generators/drails/projection/templates/domain_projection.rb +9 -9
  42. data/lib/generators/drails/projection/templates/domain_projection_test.rb +6 -6
  43. data/lib/generators/drails/projection/templates/projection.rb +9 -9
  44. data/lib/generators/drails/projection/templates/projection_test.rb +6 -6
  45. data/lib/generators/drails/scaffold/USAGE +26 -26
  46. data/lib/generators/drails/scaffold/scaffold_generator.rb +91 -89
  47. data/lib/generators/drails/scaffold/templates/_eventstream.js.erb +15 -15
  48. data/lib/generators/drails/{controller → scaffold_controller}/USAGE +1 -1
  49. data/lib/generators/drails/{controller/controller_generator.rb → scaffold_controller/scaffold_controller_generator.rb} +27 -26
  50. data/lib/generators/drails/scaffold_controller/templates/controller.rb +68 -0
  51. data/lib/generators/drails/{controller → scaffold_controller}/templates/controller_test.rb +45 -45
  52. data/lib/generators/drails/use_domain_option.rb +53 -53
  53. data/lib/rails-disco/version.rb +3 -3
  54. data/lib/tasks/db.rake +187 -88
  55. metadata +33 -27
  56. data/lib/drails/application.rb +0 -8
  57. data/lib/drails/domainserver.rb +0 -5
  58. data/lib/drails/generate.rb +0 -21
  59. data/lib/drails/projectionserver.rb +0 -8
  60. data/lib/drails/server.rb +0 -18
  61. data/lib/generators/drails/app/templates/disco.yml +0 -54
  62. data/lib/generators/drails/controller/templates/controller.rb +0 -67
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDk3ZTlkMTU5ZGIwMjhjYjVlYmFiMTA2NTQzYjM3Mjg3NmM4YWZjMQ==
5
- data.tar.gz: !binary |-
6
- OGMyZTI3N2FkMTdlMTY0MTUxMTcwMGQyODMwZTk5ZjZiNGVkNjA4ZQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDlkNzcxMmMyY2E3Mjk1MDJlY2NjZWRlNTYzZmM0YjM0YWVhMjExMzI0YTlk
10
- MzBmNmRmY2Y5YjI4ZWNjOTNkMWE3ZTg5YmM5MDhlYmVmYWYxZmI0MzIzNDNi
11
- ZmZmOGYwYjc0NDg1ZTdjNzhjNjAxZGIxYTU2YjAzMzE3NzJhYjg=
12
- data.tar.gz: !binary |-
13
- ZGYyNzVjZDE3MTI3MWU1NWE2YjQ1NDdhYTIzZWE4YzA4MDA5ODMwY2RmNjdj
14
- MTc0ZGNkNzYyMDA1MGQ4Y2U4YTljMDFhYjJhYmMxOWJjZGU1YzY3ZjdhNWEy
15
- ZTNhMDQ5NjVlOWIzN2I1YzExNDI0YjNlMTM4ZGU3ZjA4YWZkMjU=
2
+ SHA1:
3
+ metadata.gz: 2a7dd88b03bbf2263cdce75dfcd41bba3278efba
4
+ data.tar.gz: 4b41195f65faa47954dd2fe06cbdbffec857c5a0
5
+ SHA512:
6
+ metadata.gz: ad80208ff69c00f671b652a2ddc7f4eece1c2ca4ef60440b62aa09679b2f14e94923a9d90b439101902a9d888e19ba8d5d6514d48f349f757a4331917a7a0473
7
+ data.tar.gz: cfebcb2e8d70a8ea7aed32b21338e89445498108ce0777c441bed0602af03c23f060f4d9b2424adf3f2f0b15a56785dc53affa83e29088dbae2febad8f64da76
data/bin/drails CHANGED
@@ -1,45 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- unless Gem::Specification.find_by_name('drailties').gem_dir == File.expand_path("../..", __FILE__)
3
- $:.push File.expand_path("../../lib", __FILE__)
2
+
3
+ unless Gem::Specification.find_by_name('drailties').gem_dir == File.expand_path('../..', __FILE__)
4
+ $:.push File.expand_path('../../lib', __FILE__)
4
5
  $:.delete "#{Gem::Specification.find_by_name('drailties').gem_dir}/lib"
5
6
  end
6
-
7
- ARGV << '--help' if ARGV.empty?
8
-
9
- aliases = {
10
- 'ds' => 'domainserver',
11
- 's' => 'server',
12
- 'ps' => 'projectionserver',
13
- 'g' => 'generate'
14
- }
15
-
16
-
17
- help_message = <<-EOT
18
-
19
- Usage: drails COMMAND
20
-
21
- where COMMAND is one of:
22
-
23
- new creates a new drails application
24
- generate(g) run a rails generator
25
- domainserver(ds) start the domain server
26
- projectionserver(ps) start the projection server
27
- server(s) start both server
28
- EOT
29
-
30
- command = ARGV.shift
31
- command = aliases[command] || command
32
-
33
- case command
34
- when 'new'
35
- require 'drails/application'
36
- when 'generate','rake','server', 'domainserver', 'projectionserver'
37
- ROOT_DIR ||= Dir.pwd
38
- require "drails/#{command}"
39
- when '-h', '--help'
40
- puts help_message
41
- else
42
- puts "Error: Command '#{command}' not recognized"
43
- puts help_message
44
- exit(1)
45
- end
7
+ require 'drails/cli'
@@ -0,0 +1,62 @@
1
+ require 'pathname'
2
+
3
+ module Drails
4
+ module AppDrailsLoader
5
+ RUBY = File.join(*RbConfig::CONFIG.values_at('bindir', 'ruby_install_name')) + RbConfig::CONFIG['EXEEXT']
6
+ EXECUTABLES = ['bin/drails']
7
+ BUNDLER_WARNING = <<EOS
8
+ Looks like your app's ./bin/drails is a stub that was generated by Bundler.
9
+
10
+ In Rails Disco, your app's bin/ directory contains executables that are versioned
11
+ like any other source code, rather than stubs that are generated on demand.
12
+
13
+ Here's how to upgrade:
14
+
15
+ bundle config --delete bin # Turn off Bundler's stub generator
16
+ rake drails:update:bin # Use the new Rails Disco executables
17
+ git add bin # Add bin/ to source control
18
+
19
+ You may need to remove bin/ from your .gitignore as well.
20
+
21
+ When you install a gem whose executable you want to use in your app,
22
+ generate it and add it to source control:
23
+
24
+ bundle binstubs some-gem-name
25
+ git add bin/new-executable
26
+
27
+ EOS
28
+
29
+ def self.exec_app_drails
30
+ original_cwd = Dir.pwd
31
+
32
+ loop do
33
+ exe = find_executable
34
+ if exe
35
+ contents = File.read(exe)
36
+
37
+ if contents =~ /(APP|ENGINE)_PATH/
38
+ exec RUBY, exe, *ARGV
39
+ break # non reachable, hack to be able to stub exec in the test suite
40
+ elsif exe.end_with?('bin/drails') && contents.include?('This file was generated by Bundler')
41
+ $stderr.puts(BUNDLER_WARNING)
42
+ Object.const_set(:APP_PATH, File.expand_path('config/application', Dir.pwd))
43
+ require File.expand_path('../boot', APP_PATH)
44
+ require 'drails/commands'
45
+ break
46
+ end
47
+ end
48
+
49
+ # If we exhaust the search there is no executable, this could be a
50
+ # call to generate a new application, so restore the original cwd.
51
+ Dir.chdir(original_cwd) and return if Pathname.new(Dir.pwd).root?
52
+
53
+ # Otherwise keep moving upwards in search of a executable.
54
+ Dir.chdir('..')
55
+ end
56
+ end
57
+
58
+ def self.find_executable
59
+ EXECUTABLES.find { |exe| File.exists?(exe) }
60
+ end
61
+ end
62
+ end
data/lib/drails/cli.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rbconfig'
2
+ require 'drails/app_drails_loader'
3
+
4
+ # If we are inside a Rails application this method performs an exec and thus
5
+ # the rest of this script is not run.
6
+ Drails::AppDrailsLoader.exec_app_drails
7
+
8
+ require 'rails/ruby_version_check'
9
+ Signal.trap('INT') { puts; exit(1) }
10
+
11
+ require 'drails/commands/application'
@@ -0,0 +1,43 @@
1
+ require 'rails-disco/version'
2
+
3
+ if ['--version', '-v'].include?(ARGV.first)
4
+ puts "Drails #{RailsDisco::VERSION::STRING}"
5
+ exit(0)
6
+ end
7
+
8
+ if ARGV.first != "new"
9
+ ARGV[0] = "--help"
10
+ else
11
+ ARGV.shift
12
+ unless ARGV.delete("--no-rc")
13
+ customrc = ARGV.index{ |x| x.include?("--rc=") }
14
+ railsrc = if customrc
15
+ File.expand_path(ARGV.delete_at(customrc).gsub(/--rc=/, ""))
16
+ else
17
+ File.join(File.expand_path("~"), '.railsrc')
18
+ end
19
+ if File.exist?(railsrc)
20
+ extra_args_string = File.read(railsrc)
21
+ extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten
22
+ puts "Using #{extra_args.join(" ")} from #{railsrc}"
23
+ ARGV.insert(1, *extra_args)
24
+ end
25
+ end
26
+ end
27
+
28
+ require 'rails/generators'
29
+ require 'generators/drails/app/app_generator'
30
+
31
+ module Drails
32
+ module Generators
33
+ class AppGenerator # :nodoc:
34
+ # We want to exit on failure to be kind to other libraries
35
+ # This is only when accessing via CLI
36
+ def self.exit_on_failure?
37
+ true
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ Drails::Generators::AppGenerator.start
@@ -0,0 +1,12 @@
1
+ require 'drails/generators'
2
+
3
+ if [nil, '-h', '--help'].include?(ARGV.first)
4
+ Rails::Generators.help 'destroy'
5
+ exit
6
+ end
7
+
8
+ name = ARGV.shift
9
+ name = name.sub(/^drails:/, '')
10
+
11
+ root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
12
+ Rails::Generators.invoke "drails:#{name}", ARGV, behavior: :revoke, destination_root: root
@@ -0,0 +1,6 @@
1
+ puts 'Starting Domain Command Server'
2
+ puts '=> Ctrl-C to shutdown domain server'
3
+ Signal.trap('INT') { puts; exit(1) }
4
+
5
+ Process.spawn({"ROOT_DIR" => Dir.pwd}, "ruby #{File.expand_path '../../server', __FILE__}/domain_server.rb")
6
+ Process.waitall
@@ -0,0 +1,12 @@
1
+ require 'drails/generators'
2
+
3
+ if [nil, '-h', '--help'].include?(ARGV.first)
4
+ Rails::Generators.help 'generate'
5
+ exit
6
+ end
7
+
8
+ name = ARGV.shift
9
+ name = name.sub(/^drails:/, '')
10
+
11
+ root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
12
+ Rails::Generators.invoke "drails:#{name}", ARGV, behavior: :invoke, destination_root: root
@@ -0,0 +1,9 @@
1
+ count = [ARGV.shift.to_i, 1].max
2
+ puts "Starting Projection Server (#{count} processes)"
3
+ puts '=> Ctrl-C to shutdown projections server'
4
+ Signal.trap('INT') { puts; exit(1) }
5
+
6
+ count.times do |i|
7
+ Process.spawn({'ROOT_DIR' => Dir.pwd, 'WORKER_COUNT' => count.to_s, 'WORKER_NUMBER' => i.to_s}, "ruby #{File.expand_path '../../server', __FILE__}/projection_servers.rb")
8
+ end
9
+ Process.waitall
@@ -0,0 +1,22 @@
1
+ count = [ARGV.shift.to_i, 1].max
2
+ puts "Starting domain, projection (*#{count}) and Rails server..."
3
+ puts '=> Ctrl-C to shutdown all servers'
4
+ env = {'ROOT_DIR' => Dir.pwd}
5
+ pids = []
6
+ pids << Process.spawn(env, "ruby #{File.expand_path '../../server', __FILE__}/domain_server.rb")
7
+ count.times do |i|
8
+ pids << Process.spawn(env.merge('WORKER_COUNT' => count.to_s, 'WORKER_NUMBER' => i.to_s), "ruby #{File.expand_path '../../server', __FILE__}/projection_servers.rb")
9
+ end
10
+ pids << Process.spawn(env, 'rails s')
11
+ trap(:INT) do
12
+ pids.each do |pid|
13
+ begin
14
+ Process.kill 9, pid
15
+ rescue Exception
16
+ # do nothing
17
+ end
18
+ end
19
+ puts
20
+ exit(1)
21
+ end
22
+ Process.waitall
@@ -0,0 +1,70 @@
1
+ ARGV << '--help' if ARGV.empty?
2
+
3
+ aliases = {
4
+ 'ds' => 'domainserver',
5
+ 's' => 'server',
6
+ 'ps' => 'projectionserver',
7
+ 'g' => 'generate',
8
+ '-h' => '--help',
9
+ '-v' => '--version',
10
+ }
11
+
12
+ help_message = <<-EOT
13
+ Usage: drails COMMAND [ARGS]
14
+
15
+ The most common drails commands are:
16
+ generate(g) Generate new Rails Disco code
17
+ domainserver(ds) Start the domain server
18
+ projectionserver(ps) Start the projection server
19
+ server(s) Start domain and projection server
20
+ new Creates a new Rails Disco application
21
+ "drails new my_app" creates a
22
+ new application called MyApp in "./my_app"
23
+
24
+ In addition to those, there are:
25
+ application Generate the Rails Disco application code
26
+ destroy(d) Undo code generated with "generate"
27
+
28
+ All commands can be run with -h (or --help) for more information.
29
+ EOT
30
+
31
+
32
+ command = ARGV.shift
33
+ command = aliases[command] || command
34
+
35
+ case command
36
+ when 'generate', 'destroy'
37
+ require 'drails/generators'
38
+
39
+ require APP_PATH
40
+ Rails.application.require_environment!
41
+ Rails.application.load_generators
42
+
43
+ require "drails/commands/#{command}"
44
+
45
+ when 'server', 'domainserver', 'projectionserver'
46
+ Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exists?(File.expand_path('config.ru'))
47
+
48
+ require "drails/commands/#{command}"
49
+
50
+ when 'new'
51
+ if %w(-h --help).include?(ARGV.first)
52
+ require 'drails/commands/application'
53
+ else
54
+ puts "Can't initialize a new Rails Disco application within the directory of another, please change to a non-Rails Disco directory first.\n"
55
+ puts "Type 'drails' for help."
56
+ exit(1)
57
+ end
58
+
59
+ when '--version'
60
+ require 'rails-disco/version'
61
+ puts "Drails #{RailsDisco::VERSION::STRING}"
62
+
63
+ when '--help'
64
+ puts help_message
65
+
66
+ else
67
+ puts "Error: Command '#{command}' not recognized"
68
+ puts help_message
69
+ exit(1)
70
+ end
@@ -0,0 +1,48 @@
1
+ require 'rails/generators'
2
+
3
+ module Rails
4
+ module Generators
5
+
6
+ def self.help(command = 'generate')
7
+ lookup!
8
+
9
+ namespaces = subclasses.map { |k| k.namespace }
10
+ namespaces.sort!
11
+
12
+ drails = []
13
+ namespaces.each do |namespace|
14
+ drails << namespace if namespace.split(':').first == 'drails'
15
+ end
16
+
17
+ puts <<-EOT
18
+ Usage: drails #{command} GENERATOR [args] [options]
19
+
20
+ General options:
21
+ -h, [--help] # Print generator's options and usage
22
+ -p, [--pretend] # Run but do not make any changes
23
+ -f, [--force] # Overwrite files that already exist
24
+ -s, [--skip] # Skip files that already exist
25
+ -q, [--quiet] # Suppress status output
26
+
27
+ Please choose a generator below.
28
+
29
+ EOT
30
+
31
+ drails.reject! { |n| hidden_namespaces.include?(n) }
32
+ drails.map! { |n| n.sub(/^drails:/, '') }
33
+ drails.delete('app')
34
+ drails.delete('plugin_new')
35
+ print_list('drails', drails)
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ Rails::Generators.options.deep_merge! drails: {
42
+ command: :command,
43
+ command_processor: :command_processor,
44
+ migration: :migration,
45
+ model: :model,
46
+ projection: :projection,
47
+ scaffold_controller: :scaffold_controller,
48
+ }
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env ruby.exe
2
+ ROOT_DIR ||= ENV['ROOT_DIR']
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ROOT_DIR)
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
+
2
6
  require 'active_event'
3
7
  require 'active_domain'
4
8
  require 'active_record'
5
9
 
6
- ROOT_DIR ||= ENV['ROOT_DIR']
7
10
  LOGGER = ActiveEvent::Support::MultiLogger.new 'Domain Server'
8
11
 
9
12
  ActiveEvent::Autoload.app_path = ROOT_DIR
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env ruby.exe
2
+ ROOT_DIR ||= ENV['ROOT_DIR']
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ROOT_DIR)
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
+
2
6
  require 'active_event'
3
7
  require 'active_projection'
4
8
  require 'active_record'
5
9
 
6
- ROOT_DIR ||= ENV['ROOT_DIR']
7
10
  WORKER_COUNT = [ENV['WORKER_COUNT'].to_i, 1].max
8
11
  WORKER_NUMBER = ENV['WORKER_NUMBER'].to_i
9
12
  LOGGER = ActiveEvent::Support::MultiLogger.new "Projection Server#{WORKER_COUNT > 1 ? " Nr. #{WORKER_NUMBER}" : ""}"
@@ -20,4 +23,4 @@ RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
20
23
  ActiveProjection::Autoload.reload
21
24
  end
22
25
  ActiveProjection::Server.base_path = ROOT_DIR
23
- ActiveProjection::Server.run
26
+ ActiveProjection::Server.run
@@ -1,13 +1,13 @@
1
- Description:
2
- Add drails to your project.
3
-
4
- Example:
5
- rails generate drails:app
6
-
7
- This will create:
8
- app/controllers/event_source_controller.rb
9
- a route for this controller
10
- config/build_validations_registry.rb
11
- config/initializers/create_domain.rb
12
- config/disco.yml
1
+ Description:
2
+ Add drails to your project.
3
+
4
+ Example:
5
+ rails generate drails:app
6
+
7
+ This will create:
8
+ app/controllers/event_source_controller.rb
9
+ a route for this controller
10
+ config/build_validations_registry.rb
11
+ config/initializers/create_domain.rb
12
+ config/disco.yml
13
13
  adds rails-disco to your gemfile
@@ -1,52 +1,134 @@
1
- module Drails
2
- module Generators
3
- class AppGenerator < Rails::Generators::NamedBase
4
- source_root File.expand_path('../templates', __FILE__)
5
- argument :name, type: :string, default: '', banner: "[name]"
6
-
7
- def copy_config
8
- copy_file 'disco.yml', File.join('config', 'disco.yml')
9
- end
10
-
11
- def create_domain_initializer
12
- template 'create_domain.rb', File.join('config', 'initializers', 'create_domain.rb')
13
- end
14
-
15
- def copy_validation_registry_initializer
16
- copy_file 'build_validations_registry.rb', File.join('config', 'initializers', 'build_validations_registry.rb')
17
- end
18
-
19
- def copy_sse_controller
20
- copy_file 'event_source_controller.rb', File.join('app', 'controllers', 'event_source_controller.rb')
21
- end
22
-
23
- def add_sse_route
24
- route "get 'event_stream' => 'event_source#stream'"
25
- end
26
-
27
- def add_drails_to_gemfile
28
- gem "rails-disco"
29
- end
30
-
31
- def enable_rake_tasks
32
- content = "
33
- require 'rails-disco/tasks'"
34
- inject_into_file File.join('config/application.rb'), content, after: /require 'rails\/all'/
35
- rescue Exception
36
- puts "Seems like you invoked it from an engine, so put\n
37
- require 'rails-disco/tasks'\n
38
- in your application.rb from the main application to have the rails disco rake tasks available"
39
- end
40
-
41
- def enable_concurrency
42
- application 'config.preload_frameworks = true'
43
- application 'config.allow_concurrency = true'
44
- rescue Exception
45
- puts "Seems like you invoked it from an engine, so remember to put\n
46
- config.preload_frameworks = true
47
- config.allow_concurrency = true\n
48
- in your application.rb from the main application"
49
- end
50
- end
51
- end
52
- end
1
+ require 'rails/generators/rails/app/app_generator'
2
+ require 'yaml'
3
+
4
+ module Drails
5
+ class AppBuilder < Rails::AppBuilder
6
+
7
+ def gemfile
8
+ super
9
+ append_file 'Gemfile', "\n# Rails Disco support
10
+ gem 'rails-disco', '~> #{RailsDisco::VERSION::STRING}'\n
11
+ # Required Multithreaded Webserver
12
+ gem 'puma'\n" unless behavior == :revoke
13
+ end
14
+
15
+ def app
16
+ super
17
+ copy_file 'app/controllers/event_source_controller.rb'
18
+ keep_file 'app/commands'
19
+ keep_file 'app/events'
20
+ keep_file 'app/projections'
21
+ keep_file 'app/validations'
22
+
23
+ keep_file 'domain/command_processors/domain'
24
+ keep_file 'domain/models/domain'
25
+ keep_file 'domain/projections/domain'
26
+ keep_file 'domain/validations/domain'
27
+ end
28
+
29
+ def bin
30
+ super
31
+ copy_file 'bin/drails'
32
+ chmod 'bin/drails', 0755, verbose: false
33
+ end
34
+
35
+ def config
36
+ super
37
+ inside 'config/initializers' do
38
+ template 'create_domain.rb'
39
+ copy_file 'build_validations_registry.rb'
40
+ end
41
+ end
42
+
43
+ def database_yml
44
+ super
45
+ template 'config/disco.yml'
46
+ end
47
+
48
+ def db
49
+ super
50
+ append_file 'db/seeds.rb', File.binread(File.expand_path('../templates/db/seeds.rb', __FILE__)) unless behavior == :revoke
51
+ end
52
+ end
53
+
54
+ module Generators
55
+ class AppGenerator < Rails::Generators::AppGenerator
56
+ remove_class_option :version
57
+ class_option :version, type: :boolean, aliases: '-v', group: :drails,
58
+ desc: 'Show Rails Disco version number and quit'
59
+
60
+ remove_class_option :help
61
+ class_option :help, type: :boolean, aliases: '-h', group: :drails,
62
+ desc: 'Show this help message and quit'
63
+
64
+ # this does not seem to work !
65
+ remove_command :apply_rails_template, :run_bundle
66
+
67
+ def source_paths
68
+ [File.join(Gem::Specification.find_by_name('railties').gem_dir, 'lib/rails/generators/rails/app/templates'), File.expand_path('../templates', __FILE__)]
69
+ end
70
+
71
+ def add_event_source_route
72
+ return if behavior == :revoke
73
+ route "get 'event_stream' => 'event_source#stream'"
74
+ end
75
+
76
+ def enable_rake_tasks
77
+ return if behavior == :revoke
78
+ content = "
79
+ require 'rails-disco/tasks'"
80
+ inject_into_file File.join('config/application.rb'), content, after: /require 'rails\/all'/
81
+ rescue Exception
82
+ puts "Seems like you invoked it from an engine, so put\n
83
+ require 'rails-disco/tasks'\n
84
+ in your application.rb from the main application to have the rails disco rake tasks available"
85
+ end
86
+
87
+ def enable_concurrency
88
+ return if behavior == :revoke
89
+ application 'config.preload_frameworks = true'
90
+ application 'config.allow_concurrency = true'
91
+ rescue Exception
92
+ puts "Seems like you invoked it from an engine, so remember to put\n
93
+ config.preload_frameworks = true
94
+ config.allow_concurrency = true\n
95
+ in your application.rb from the main application"
96
+ end
97
+
98
+ public_task :apply_rails_template, :run_bundle
99
+
100
+ private
101
+
102
+ def get_builder_class
103
+ defined?(::AppBuilder) ? ::AppBuilder : Drails::AppBuilder
104
+ end
105
+
106
+ def domain_database(env, indent_level)
107
+ config = YAML.load(File.read('config/database.yml'))[env.to_s]
108
+ config['database'].sub!(/.*#{env}/, '\0_domain')
109
+ indent( ({'domain_database' => config}.to_yaml(indentation: 2))[4..-1], indent_level)
110
+ end
111
+
112
+ # copied namespace support from NamedBase
113
+ def module_namespacing(&block)
114
+ content = capture(&block)
115
+ content = wrap_with_namespace(content) if namespace
116
+ concat(content)
117
+ end
118
+
119
+ def indent(content, multiplier = 2)
120
+ spaces = ' ' * multiplier
121
+ content.each_line.map {|line| line.blank? ? line : "#{spaces}#{line}" }.join
122
+ end
123
+
124
+ def wrap_with_namespace(content)
125
+ content = indent(content).chomp
126
+ "module #{namespace.name}\n#{content}\nend\n"
127
+ end
128
+
129
+ def namespace
130
+ Rails::Generators.namespace
131
+ end
132
+ end
133
+ end
134
+ end
@@ -1,16 +1,16 @@
1
- class EventSourceController < ApplicationController
2
- include ActionController::Live
3
- include ActiveEvent::EventSourceServer
4
-
5
- def stream
6
- event_connection.start
7
- response.headers['Content-Type'] = 'text/event-stream'
8
- sse = ActiveEvent::SSE.new(response.stream)
9
- subscribe_to event_queue do |delivery_info, properties, body|
10
- sse.write({:id => body}, :event => 'refresh')
11
- end
12
- rescue IOError
13
- ensure
14
- sse.close
15
- end
1
+ class EventSourceController < ApplicationController
2
+ include ActionController::Live
3
+ include ActiveEvent::EventSourceServer
4
+
5
+ def stream
6
+ event_connection.start
7
+ response.headers['Content-Type'] = 'text/event-stream'
8
+ sse = ActiveEvent::SSE.new(response.stream)
9
+ subscribe_to event_queue do |delivery_info, properties, body|
10
+ sse.write({:id => body}, :event => 'refresh')
11
+ end
12
+ rescue IOError
13
+ ensure
14
+ sse.close
15
+ end
16
16
  end
@@ -0,0 +1,3 @@
1
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ require_relative '../config/boot'
3
+ require 'drails/commands'