disco-railties 0.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +1 -0
- data/bin/disco +7 -0
- data/bin/drails +3 -0
- data/lib/disco/app_disco_loader.rb +62 -0
- data/lib/disco/cli.rb +11 -0
- data/lib/disco/commands/application.rb +43 -0
- data/lib/disco/commands/destroy.rb +12 -0
- data/lib/disco/commands/domainserver.rb +6 -0
- data/lib/disco/commands/generate.rb +12 -0
- data/lib/disco/commands/projectionserver.rb +9 -0
- data/lib/disco/commands/server.rb +22 -0
- data/lib/disco/commands.rb +70 -0
- data/lib/disco/generators.rb +48 -0
- data/lib/disco/server/domain_server.rb +26 -0
- data/lib/disco/server/projection_servers.rb +26 -0
- data/lib/generators/disco/app/USAGE +14 -0
- data/lib/generators/disco/app/app_generator.rb +140 -0
- data/lib/generators/disco/app/templates/app/controllers/event_source_controller.rb +16 -0
- data/lib/generators/disco/app/templates/bin/disco +3 -0
- data/lib/generators/disco/app/templates/config/disco.yml +27 -0
- data/lib/generators/disco/app/templates/config/initializers/build_validations_registry.rb +19 -0
- data/lib/generators/disco/app/templates/config/initializers/create_domain.rb +5 -0
- data/lib/generators/disco/app/templates/db/seeds.rb +14 -0
- data/lib/generators/disco/command/USAGE +11 -0
- data/lib/generators/disco/command/command_generator.rb +69 -0
- data/lib/generators/disco/command/templates/command.rb.erb +24 -0
- data/lib/generators/disco/command/templates/event.rb.erb +11 -0
- data/lib/generators/disco/command_processor/USAGE +1 -0
- data/lib/generators/disco/command_processor/command_processor_generator.rb +22 -0
- data/lib/generators/disco/command_processor/templates/command_processor.rb +5 -0
- data/lib/generators/disco/domain.rb +19 -0
- data/lib/generators/disco/event_name.rb +52 -0
- data/lib/generators/disco/migration/USAGE +41 -0
- data/lib/generators/disco/migration/migration_generator.rb +27 -0
- data/lib/generators/disco/migration/templates/create_table_migration.rb +19 -0
- data/lib/generators/disco/model/USAGE +17 -0
- data/lib/generators/disco/model/model_generator.rb +29 -0
- data/lib/generators/disco/model/templates/domain_model.rb +5 -0
- data/lib/generators/disco/model/templates/model.rb +5 -0
- data/lib/generators/disco/processor_name.rb +48 -0
- data/lib/generators/disco/projection/USAGE +13 -0
- data/lib/generators/disco/projection/projection_generator.rb +19 -0
- data/lib/generators/disco/projection/templates/domain_projection.rb +9 -0
- data/lib/generators/disco/projection/templates/domain_projection_test.rb +6 -0
- data/lib/generators/disco/projection/templates/projection.rb +9 -0
- data/lib/generators/disco/projection/templates/projection_test.rb +6 -0
- data/lib/generators/disco/scaffold/USAGE +27 -0
- data/lib/generators/disco/scaffold/scaffold_generator.rb +91 -0
- data/lib/generators/disco/scaffold/templates/_eventstream.js.erb +16 -0
- data/lib/generators/disco/scaffold_controller/USAGE +1 -0
- data/lib/generators/disco/scaffold_controller/scaffold_controller_generator.rb +27 -0
- data/lib/generators/disco/scaffold_controller/templates/controller.rb +68 -0
- data/lib/generators/disco/scaffold_controller/templates/controller_test.rb +45 -0
- data/lib/generators/disco/use_domain_option.rb +54 -0
- data/lib/rails-disco/railtie.rb +8 -0
- data/lib/rails-disco/tasks.rb +1 -0
- data/lib/rails-disco/version.rb +10 -0
- data/lib/tasks/db.rake +222 -0
- data/lib/tasks/split.rake +94 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62f23a6b10dcf4e0713820c095a72ad018b0bc8b
|
4
|
+
data.tar.gz: 9f180b0beec4b72601f52654452f4bcb00fd8915
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fea79118ee04f8ec04c221d8fde4e40eeab7c2ba3a9b720ac0b09f4773c9a62d0f1b6d025ba081b8bc31aa31eb7101155ea8f58a2118e497cb9e37ddb3b631f2
|
7
|
+
data.tar.gz: 775eae3ebb53b9502f7e07df793c3b7e73db01c896ae3151bc878ae2c36c4161049c8d9213cf2205580c88dac6ba5e368079c3c591f1898b2b7115b0bfdd995d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Robert Kranz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob('lib/tasks/*.rake').each {|r| import r}
|
data/bin/disco
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
unless Gem::Specification.find_by_name('disco-railties').gem_dir == File.expand_path('../..', __FILE__)
|
4
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
5
|
+
$:.delete "#{Gem::Specification.find_by_name('disco-railties').gem_dir}/lib"
|
6
|
+
end
|
7
|
+
require 'disco/cli'
|
data/bin/drails
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Disco
|
4
|
+
module AppDiscoLoader
|
5
|
+
RUBY = File.join(*RbConfig::CONFIG.values_at('bindir', 'ruby_install_name')) + RbConfig::CONFIG['EXEEXT']
|
6
|
+
EXECUTABLES = ['bin/disco']
|
7
|
+
BUNDLER_WARNING = <<EOS
|
8
|
+
Looks like your app's ./bin/disco 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 disco: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_disco
|
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/disco') && 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 'disco/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/disco/cli.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'disco/app_disco_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
|
+
Disco::AppDiscoLoader.exec_app_disco
|
7
|
+
|
8
|
+
require 'rails/ruby_version_check'
|
9
|
+
Signal.trap('INT') { puts; exit(1) }
|
10
|
+
|
11
|
+
require 'disco/commands/application'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails-disco/version'
|
2
|
+
|
3
|
+
if ['--version', '-v'].include?(ARGV.first)
|
4
|
+
puts "Rails Disco #{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/disco/app/app_generator'
|
30
|
+
|
31
|
+
module Disco
|
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
|
+
Disco::Generators::AppGenerator.start
|
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -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: disco COMMAND [ARGS]
|
14
|
+
|
15
|
+
The most common disco 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
|
+
"disco 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 'disco/generators'
|
38
|
+
|
39
|
+
require APP_PATH
|
40
|
+
Rails.application.require_environment!
|
41
|
+
Rails.application.load_generators
|
42
|
+
|
43
|
+
require "disco/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 "disco/commands/#{command}"
|
49
|
+
|
50
|
+
when 'new'
|
51
|
+
if %w(-h --help).include?(ARGV.first)
|
52
|
+
require 'disco/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 'disco' for help."
|
56
|
+
exit(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
when '--version'
|
60
|
+
require 'rails-disco/version'
|
61
|
+
puts "Rails Disco #{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
|
+
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
|
+
}
|
@@ -0,0 +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
|
@@ -0,0 +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_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
|
+
ActiveProjection::Autoload.worker_config = {path: ROOT_DIR, count: WORKER_COUNT, number: WORKER_NUMBER}
|
17
|
+
|
18
|
+
watchable_dirs = ActiveEvent::Autoload.watchable_dirs.merge ActiveProjection::Autoload.watchable_dirs
|
19
|
+
RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
|
20
|
+
ActiveEvent::Autoload.reload_module :ValidationsRegistry
|
21
|
+
ActiveProjection::Autoload.reload_module :ProjectionTypeRegistry
|
22
|
+
ActiveEvent::Autoload.reload
|
23
|
+
ActiveProjection::Autoload.reload
|
24
|
+
end
|
25
|
+
ActiveProjection::Server.base_path = ROOT_DIR
|
26
|
+
ActiveProjection::Server.run
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Description:
|
2
|
+
Create a new Rails Disco app or add Rails Disco to your project.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate disco:app .
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
bin/disco
|
9
|
+
app/controllers/event_source_controller.rb
|
10
|
+
a route for this controller
|
11
|
+
config/initializers/build_validations_registry.rb
|
12
|
+
config/initializers/create_domain.rb
|
13
|
+
config/disco.yml
|
14
|
+
adds rails-disco to your gemfile
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'rails/generators/rails/app/app_generator'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Disco
|
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/disco'
|
32
|
+
chmod 'bin/disco', 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: :disco,
|
58
|
+
desc: 'Show Rails Disco version number and quit'
|
59
|
+
|
60
|
+
remove_class_option :help
|
61
|
+
class_option :help, type: :boolean, aliases: '-h', group: :disco,
|
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
|
+
protected
|
101
|
+
|
102
|
+
def self.banner
|
103
|
+
"disco new #{self.arguments.map(&:usage).join(' ')} [options]"
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def get_builder_class
|
109
|
+
defined?(::AppBuilder) ? ::AppBuilder : Disco::AppBuilder
|
110
|
+
end
|
111
|
+
|
112
|
+
def domain_database(env, indent_level)
|
113
|
+
config = YAML.load(File.read('config/database.yml'))[env.to_s]
|
114
|
+
config['database'].sub!(/.*#{env}/, '\0_domain')
|
115
|
+
indent( ({'domain_database' => config}.to_yaml(indentation: 2))[4..-1], indent_level)
|
116
|
+
end
|
117
|
+
|
118
|
+
# copied namespace support from NamedBase
|
119
|
+
def module_namespacing(&block)
|
120
|
+
content = capture(&block)
|
121
|
+
content = wrap_with_namespace(content) if namespace
|
122
|
+
concat(content)
|
123
|
+
end
|
124
|
+
|
125
|
+
def indent(content, multiplier = 2)
|
126
|
+
spaces = ' ' * multiplier
|
127
|
+
content.each_line.map {|line| line.blank? ? line : "#{spaces}#{line}" }.join
|
128
|
+
end
|
129
|
+
|
130
|
+
def wrap_with_namespace(content)
|
131
|
+
content = indent(content).chomp
|
132
|
+
"module #{namespace.name}\n#{content}\nend\n"
|
133
|
+
end
|
134
|
+
|
135
|
+
def namespace
|
136
|
+
Rails::Generators.namespace
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +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
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
development:
|
2
|
+
<%= domain_database(:development, 2) -%>
|
3
|
+
drb_server:
|
4
|
+
scheme: druby
|
5
|
+
host: 127.0.0.1
|
6
|
+
port: 8787
|
7
|
+
event_connection:
|
8
|
+
scheme: amqp
|
9
|
+
host: 127.0.0.1
|
10
|
+
port: 5672
|
11
|
+
event_exchange: events
|
12
|
+
|
13
|
+
test:
|
14
|
+
<%= domain_database(:test, 2) -%>
|
15
|
+
|
16
|
+
production:
|
17
|
+
<%= domain_database(:production, 2) -%>
|
18
|
+
drb_server:
|
19
|
+
protocol: druby
|
20
|
+
host: 127.0.0.1
|
21
|
+
port: 8787
|
22
|
+
event_connection:
|
23
|
+
scheme: amqp
|
24
|
+
userinfo: amqp:password
|
25
|
+
host: 127.0.0.1
|
26
|
+
port: 9797
|
27
|
+
event_exchange: events
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_event'
|
2
|
+
require 'active_projection'
|
3
|
+
ActiveEvent::Autoload.app_path = File.expand_path('../../..', __FILE__)
|
4
|
+
ActiveProjection::Autoload.app_path = File.expand_path('../../..', __FILE__)
|
5
|
+
LOGGER = ActiveEvent::Support::MultiLogger.new 'Rails Server'
|
6
|
+
|
7
|
+
watchable_dirs = ActiveEvent::Autoload.watchable_dirs.merge ActiveProjection::Autoload.watchable_dirs
|
8
|
+
RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
|
9
|
+
ActiveEvent::Autoload.reload_module :ValidationsRegistry
|
10
|
+
ActiveEvent::Autoload.reload
|
11
|
+
ActiveProjection::Autoload.reload
|
12
|
+
ActiveEvent::ValidationsRegistry.build
|
13
|
+
end
|
14
|
+
|
15
|
+
ActionDispatch::Reloader.to_prepare do
|
16
|
+
RELOADER.execute_if_updated
|
17
|
+
end
|
18
|
+
|
19
|
+
ActiveEvent::ValidationsRegistry.build
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#
|
2
|
+
# With Rails Disco you can invoke domain commands
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# city_id = domain_run(CityCreateCommand.new(name: 'Chicago'))
|
7
|
+
# domain_run(MayorCreateCommand(name: 'Emanuel', city_id: city_id)
|
8
|
+
@@can_run = true
|
9
|
+
def domain_run(command)
|
10
|
+
Domain.run_command(command) if @@can_run
|
11
|
+
rescue DRb::DRbConnError
|
12
|
+
puts 'no domain server for seeds'
|
13
|
+
@@can_run = false
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a Command, an Event and adds it to the CommandProcessor or creates one.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate disco:command CreateThing [attr1, attr2] --event=CreatedThing --processor=Things
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
app/commands/create_thing_command.rb
|
9
|
+
app/events/created_thing_event.rb
|
10
|
+
domain/command_processors/things_processor.rb unless it exists
|
11
|
+
Adds a command handler to this or an existing processor
|