disco-railties 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +19 -19
  3. data/Rakefile +1 -1
  4. data/bin/disco +7 -7
  5. data/lib/disco/app_disco_loader.rb +65 -62
  6. data/lib/disco/cli.rb +14 -11
  7. data/lib/disco/commands.rb +74 -71
  8. data/lib/disco/commands/application.rb +43 -43
  9. data/lib/disco/commands/destroy.rb +12 -12
  10. data/lib/disco/commands/domainserver.rb +9 -6
  11. data/lib/disco/commands/generate.rb +12 -12
  12. data/lib/disco/commands/projectionserver.rb +13 -9
  13. data/lib/disco/commands/server.rb +23 -22
  14. data/lib/disco/generators.rb +46 -48
  15. data/lib/disco/server/domain_server.rb +26 -26
  16. data/lib/disco/server/projection_servers.rb +25 -25
  17. data/lib/generators/disco/app/app_generator.rb +11 -11
  18. data/lib/generators/disco/app/templates/app/assets/stylesheets/event_source.css +4 -4
  19. data/lib/generators/disco/app/templates/app/controllers/event_source_controller.rb +2 -3
  20. data/lib/generators/disco/app/templates/app/helpers/event_source_helper.rb +11 -11
  21. data/lib/generators/disco/app/templates/config/initializers/event_source_server.rb +2 -2
  22. data/lib/generators/disco/command/command_generator.rb +1 -1
  23. data/lib/generators/disco/event_name.rb +3 -3
  24. data/lib/generators/disco/processor_name.rb +2 -2
  25. data/lib/generators/disco/projection/USAGE +13 -13
  26. data/lib/generators/disco/projection/projection_generator.rb +19 -19
  27. data/lib/generators/disco/scaffold/scaffold_generator.rb +4 -3
  28. data/lib/generators/disco/scaffold_controller/scaffold_controller_generator.rb +1 -1
  29. data/lib/rails-disco/railtie.rb +8 -8
  30. data/lib/rails-disco/tasks.rb +1 -1
  31. data/lib/rails-disco/version.rb +3 -3
  32. data/lib/tasks/db.rake +222 -222
  33. data/lib/tasks/split.rake +93 -93
  34. metadata +8 -8
@@ -1,12 +1,12 @@
1
- require 'disco/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(/^disco:/, '')
10
-
11
- root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
12
- Rails::Generators.invoke "disco:#{name}", ARGV, behavior: :revoke, destination_root: root
1
+ require 'disco/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(/^disco:/, '')
10
+
11
+ root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
12
+ Rails::Generators.invoke "disco:#{name}", ARGV, behavior: :revoke, destination_root: root
@@ -1,6 +1,9 @@
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
1
+ puts 'Starting Domain Command Server'
2
+ puts '=> Ctrl-C to shutdown domain server'
3
+ Signal.trap('INT') do
4
+ puts
5
+ exit(1)
6
+ end
7
+
8
+ Process.spawn({'ROOT_DIR' => Dir.pwd}, "ruby #{File.expand_path '../../server', __FILE__}/domain_server.rb")
9
+ Process.waitall
@@ -1,12 +1,12 @@
1
- require 'disco/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(/^disco:/, '')
10
-
11
- root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
12
- Rails::Generators.invoke "disco:#{name}", ARGV, behavior: :invoke, destination_root: root
1
+ require 'disco/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(/^disco:/, '')
10
+
11
+ root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
12
+ Rails::Generators.invoke "disco:#{name}", ARGV, behavior: :invoke, destination_root: root
@@ -1,9 +1,13 @@
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
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') do
5
+ puts
6
+ exit(1)
7
+ end
8
+
9
+ count.times do |i|
10
+ server_env = {'ROOT_DIR' => Dir.pwd, 'WORKER_COUNT' => count.to_s, 'WORKER_NUMBER' => i.to_s}
11
+ Process.spawn(server_env, "ruby #{File.expand_path '../../server', __FILE__}/projection_servers.rb")
12
+ end
13
+ Process.waitall
@@ -1,22 +1,23 @@
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
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
+ server_env = env.merge('WORKER_COUNT' => count.to_s, 'WORKER_NUMBER' => i.to_s)
9
+ pids << Process.spawn(server_env, "ruby #{File.expand_path '../../server', __FILE__}/projection_servers.rb")
10
+ end
11
+ pids << Process.spawn(env, 'rails s')
12
+ trap(:INT) do
13
+ pids.each do |pid|
14
+ begin
15
+ Process.kill 9, pid
16
+ rescue
17
+ # do nothing
18
+ end
19
+ end
20
+ puts
21
+ exit(1)
22
+ end
23
+ Process.waitall
@@ -1,48 +1,46 @@
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
- disco = []
13
- namespaces.each do |namespace|
14
- disco << namespace if namespace.split(':').first == 'disco'
15
- end
16
-
17
- puts <<-EOT
18
- Usage: disco #{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
- disco.reject! { |n| hidden_namespaces.include?(n) }
32
- disco.map! { |n| n.sub(/^disco:/, '') }
33
- disco.delete('app')
34
- disco.delete('plugin_new')
35
- print_list('disco', disco)
36
- end
37
-
38
- end
39
- end
40
-
41
- Rails::Generators.options.deep_merge! disco: {
42
- command: :command,
43
- command_processor: :command_processor,
44
- migration: :migration,
45
- model: :model,
46
- projection: :projection,
47
- scaffold_controller: :scaffold_controller,
48
- }
1
+ require 'rails/generators'
2
+
3
+ module Rails
4
+ module Generators
5
+ def self.help(command = 'generate')
6
+ lookup!
7
+
8
+ namespaces = subclasses.map { |k| k.namespace }
9
+ namespaces.sort!
10
+
11
+ disco = []
12
+ namespaces.each do |namespace|
13
+ disco << namespace if namespace.split(':').first == 'disco'
14
+ end
15
+
16
+ puts <<-EOT
17
+ Usage: disco #{command} GENERATOR [args] [options]
18
+
19
+ General options:
20
+ -h, [--help] # Print generator's options and usage
21
+ -p, [--pretend] # Run but do not make any changes
22
+ -f, [--force] # Overwrite files that already exist
23
+ -s, [--skip] # Skip files that already exist
24
+ -q, [--quiet] # Suppress status output
25
+
26
+ Please choose a generator below.
27
+
28
+ EOT
29
+
30
+ disco.reject! { |n| hidden_namespaces.include?(n) }
31
+ disco.map! { |n| n.sub(/^disco:/, '') }
32
+ disco.delete('app')
33
+ disco.delete('plugin_new')
34
+ print_list('disco', disco)
35
+ end
36
+ end
37
+ end
38
+
39
+ Rails::Generators.options.deep_merge! disco: {
40
+ command: :command,
41
+ command_processor: :command_processor,
42
+ migration: :migration,
43
+ model: :model,
44
+ projection: :projection,
45
+ scaffold_controller: :scaffold_controller,
46
+ }
@@ -1,26 +1,26 @@
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
-
6
- require 'active_event'
7
- require 'active_domain'
8
- require 'active_record'
9
-
10
- LOGGER = ActiveEvent::Support::MultiLogger.new 'Domain Server'
11
-
12
- ActiveEvent::Autoload.app_path = ROOT_DIR
13
- ActiveDomain::Autoload.app_path = ROOT_DIR
14
-
15
- watchable_dirs = ActiveEvent::Autoload.watchable_dirs.merge ActiveDomain::Autoload.watchable_dirs
16
- RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
17
- ActiveEvent::Autoload.reload_module :ValidationsRegistry
18
- ActiveDomain::Autoload.reload_module :ProjectionRegistry
19
- ActiveEvent::Autoload.reload
20
- ActiveDomain::Autoload.reload
21
- ActiveEvent::ValidationsRegistry.build
22
- end
23
-
24
- ActiveEvent::ValidationsRegistry.build
25
- ActiveDomain::Server.base_path = ROOT_DIR
26
- ActiveDomain::Server.run
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.exist?(ENV['BUNDLE_GEMFILE'])
5
+
6
+ require 'active_event'
7
+ require 'active_domain'
8
+ require 'active_record'
9
+
10
+ LOGGER = ActiveEvent::Support::MultiLogger.new 'Domain Server'
11
+
12
+ ActiveEvent::Autoload.app_path = ROOT_DIR
13
+ ActiveDomain::Autoload.app_path = ROOT_DIR
14
+
15
+ watchable_dirs = ActiveEvent::Autoload.watchable_dirs.merge ActiveDomain::Autoload.watchable_dirs
16
+ RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
17
+ ActiveEvent::Autoload.reload_module :ValidationsRegistry
18
+ ActiveDomain::Autoload.reload_module :ProjectionRegistry
19
+ ActiveEvent::Autoload.reload
20
+ ActiveDomain::Autoload.reload
21
+ ActiveEvent::ValidationsRegistry.build
22
+ end
23
+
24
+ ActiveEvent::ValidationsRegistry.build
25
+ ActiveDomain::Server.base_path = ROOT_DIR
26
+ ActiveDomain::Server.run
@@ -1,25 +1,25 @@
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
-
6
- require 'active_event'
7
- require 'active_projection'
8
- require 'active_record'
9
-
10
- WORKER_COUNT = [ENV['WORKER_COUNT'].to_i, 1].max
11
- WORKER_NUMBER = ENV['WORKER_NUMBER'].to_i
12
- LOGGER = ActiveEvent::Support::MultiLogger.new "Projection Server#{WORKER_COUNT > 1 ? " Nr. #{WORKER_NUMBER}" : ''}"
13
-
14
- ActiveEvent::Autoload.app_path = ROOT_DIR
15
- ActiveProjection::Autoload.app_path = ROOT_DIR
16
-
17
- watchable_dirs = ActiveEvent::Autoload.watchable_dirs.merge ActiveProjection::Autoload.watchable_dirs
18
- RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
19
- ActiveEvent::Autoload.reload_module :ValidationsRegistry
20
- ActiveProjection::Autoload.reload_module :ProjectionTypeRegistry
21
- ActiveEvent::Autoload.reload
22
- ActiveProjection::Autoload.reload
23
- end
24
- ActiveProjection::Server.base_path = ROOT_DIR
25
- ActiveProjection::Server.run
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.exist?(ENV['BUNDLE_GEMFILE'])
5
+
6
+ require 'active_event'
7
+ require 'active_projection'
8
+ require 'active_record'
9
+
10
+ WORKER_COUNT = [ENV['WORKER_COUNT'].to_i, 1].max
11
+ WORKER_NUMBER = ENV['WORKER_NUMBER'].to_i
12
+ LOGGER = ActiveEvent::Support::MultiLogger.new "Projection Server#{WORKER_COUNT > 1 ? " Nr. #{WORKER_NUMBER}" : ''}"
13
+
14
+ ActiveEvent::Autoload.app_path = ROOT_DIR
15
+ ActiveProjection::Autoload.app_path = ROOT_DIR
16
+
17
+ watchable_dirs = ActiveEvent::Autoload.watchable_dirs.merge ActiveProjection::Autoload.watchable_dirs
18
+ RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
19
+ ActiveEvent::Autoload.reload_module :ValidationsRegistry
20
+ ActiveProjection::Autoload.reload_module :ProjectionTypeRegistry
21
+ ActiveEvent::Autoload.reload
22
+ ActiveProjection::Autoload.reload
23
+ end
24
+ ActiveProjection::Server.base_path = ROOT_DIR
25
+ ActiveProjection::Server.run
@@ -3,7 +3,6 @@ require 'yaml'
3
3
 
4
4
  module Disco
5
5
  class AppBuilder < Rails::AppBuilder
6
-
7
6
  def gemfile
8
7
  super
9
8
  append_file 'Gemfile', "\n# Rails Disco support
@@ -60,17 +59,20 @@ gem 'puma'\n" unless behavior == :revoke
60
59
  class AppGenerator < Rails::Generators::AppGenerator
61
60
  remove_class_option :version
62
61
  class_option :version, type: :boolean, aliases: '-v', group: :disco,
63
- desc: 'Show Rails Disco version number and quit'
62
+ desc: 'Show Rails Disco version number and quit'
64
63
 
65
64
  remove_class_option :help
66
65
  class_option :help, type: :boolean, aliases: '-h', group: :disco,
67
- desc: 'Show this help message and quit'
66
+ desc: 'Show this help message and quit'
68
67
 
69
68
  # this does not seem to work !
70
69
  remove_command :apply_rails_template, :run_bundle
71
70
 
72
71
  def source_paths
73
- [File.join(Gem::Specification.find_by_name('railties').gem_dir, 'lib/rails/generators/rails/app/templates'), File.expand_path('../templates', __FILE__)]
72
+ [
73
+ File.join(Gem::Specification.find_by_name('railties').gem_dir, 'lib/rails/generators/rails/app/templates'),
74
+ File.expand_path('../templates', __FILE__),
75
+ ]
74
76
  end
75
77
 
76
78
  def add_event_source_route
@@ -83,7 +85,7 @@ gem 'puma'\n" unless behavior == :revoke
83
85
  content = "
84
86
  require 'rails-disco/tasks'"
85
87
  inject_into_file File.join('config/application.rb'), content, after: /require 'rails\/all'/
86
- rescue Exception
88
+ rescue
87
89
  puts "Seems like you invoked it from an engine, so put\n
88
90
  require 'rails-disco/tasks'\n
89
91
  in your application.rb from the main application to have the rails disco rake tasks available"
@@ -93,7 +95,7 @@ require 'rails-disco/tasks'"
93
95
  return if behavior == :revoke
94
96
  application 'config.preload_frameworks = true'
95
97
  application 'config.allow_concurrency = true'
96
- rescue Exception
98
+ rescue
97
99
  puts "Seems like you invoked it from an engine, so remember to put\n
98
100
  config.preload_frameworks = true
99
101
  config.allow_concurrency = true\n
@@ -102,10 +104,8 @@ require 'rails-disco/tasks'"
102
104
 
103
105
  public_task :apply_rails_template, :run_bundle
104
106
 
105
- protected
106
-
107
107
  def self.banner
108
- "disco new #{self.arguments.map(&:usage).join(' ')} [options]"
108
+ "disco new #{arguments.map(&:usage).join(' ')} [options]"
109
109
  end
110
110
 
111
111
  private
@@ -117,7 +117,7 @@ require 'rails-disco/tasks'"
117
117
  def domain_database(env, indent_level)
118
118
  config = YAML.load(File.read('config/database.yml'))[env.to_s]
119
119
  config['database'].sub!(/.*#{env}/, '\0_domain')
120
- indent( ({'domain_database' => config}.to_yaml(indentation: 2))[4..-1], indent_level)
120
+ indent(({'domain_database' => config}.to_yaml(indentation: 2))[4..-1], indent_level)
121
121
  end
122
122
 
123
123
  # copied namespace support from NamedBase
@@ -129,7 +129,7 @@ require 'rails-disco/tasks'"
129
129
 
130
130
  def indent(content, multiplier = 2)
131
131
  spaces = ' ' * multiplier
132
- content.each_line.map {|line| line.blank? ? line : "#{spaces}#{line}" }.join
132
+ content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join
133
133
  end
134
134
 
135
135
  def wrap_with_namespace(content)
@@ -1,4 +1,4 @@
1
-
2
- .alert-projection { border: solid 2px #f44; padding: 4px; }
3
- .alert-projection .message { font-size: 200%; color: #f44; }
4
- .alert-projection .backtrace { white-space: pre; }
1
+
2
+ .alert-projection { border: solid 2px #f44; padding: 4px; }
3
+ .alert-projection .message { font-size: 200%; color: #f44; }
4
+ .alert-projection .backtrace { white-space: pre; }
@@ -4,9 +4,8 @@ class EventSourceController < ApplicationController
4
4
  def projected
5
5
  response.headers['Content-Type'] = 'text/event-stream'
6
6
  sse = ActiveEvent::SSE.new(response.stream)
7
- ActiveEvent::EventSourceServer.after_event_projection event_id, projection do
8
- sse.event('projected')
9
- end
7
+ ActiveEvent::EventSourceServer.wait_for_event_projection event_id, projection, timeout: 10
8
+ sse.event('projected')
10
9
  rescue IOError
11
10
  # ignore disconnect
12
11
  rescue ActiveEvent::ProjectionException => e
@@ -1,11 +1,11 @@
1
- module EventSourceHelper
2
- def event_source(projection)
3
- ActiveEvent::EventSourceServer.projection_status(projection)
4
- event_id = read_and_clear_event_id
5
- if event_id
6
- content_tag(:div, '',
7
- class: 'event-source',
8
- data: {href: event_source_path(projection: projection, event: event_id)})
9
- end
10
- end
11
- end
1
+ module EventSourceHelper
2
+ def event_source(projection)
3
+ ActiveEvent::EventSourceServer.fail_on_projection_error(projection)
4
+ event_id = read_and_clear_event_id
5
+ if event_id
6
+ content_tag(:div, '',
7
+ class: 'event-source',
8
+ data: {href: event_source_path(projection: projection, event: event_id)})
9
+ end
10
+ end
11
+ end