disco-railties 0.5.0.rc2 → 0.5.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/disco/commands.rb +1 -0
- data/lib/generators/disco/command/USAGE +2 -2
- data/lib/generators/disco/command/command_generator.rb +1 -1
- data/lib/generators/disco/command/templates/event.rb.erb +1 -1
- data/lib/generators/disco/event_name.rb +1 -1
- data/lib/generators/disco/processor_name.rb +2 -2
- data/lib/generators/disco/scaffold/scaffold_generator.rb +46 -20
- data/lib/rails-disco/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bd165f0944683d0c5b4de539f11bea205e7444e
|
4
|
+
data.tar.gz: 6b02ed63e4f88f0eb0814d69a908fa5f2b582177
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a782de11c12f863ce01b8d00c0553c4ce53c0fca2922147602b64ae21e713c4e4f3df28db37a2d1ac34274daa86f311ee8ab5704a12caa78e96c2a619e4b8c9
|
7
|
+
data.tar.gz: 85a24c8d0f675affd054749e9024b456579abd2729f80f96a55b73453a9bbbeeec1292408bedf45e15fbb1d979990f51fa3d03211c31dba0a0b78bb9e0e9e9fa
|
data/lib/disco/commands.rb
CHANGED
@@ -2,10 +2,10 @@ Description:
|
|
2
2
|
Generates a Command, an Event and adds it to the CommandProcessor or creates one.
|
3
3
|
|
4
4
|
Example:
|
5
|
-
rails generate disco:command CreateThing [attr1, attr2] --event=CreatedThing --processor=
|
5
|
+
rails generate disco:command CreateThing [attr1, attr2] --event=CreatedThing --processor=Thing
|
6
6
|
|
7
7
|
This will create:
|
8
8
|
app/commands/create_thing_command.rb
|
9
9
|
app/events/created_thing_event.rb
|
10
|
-
domain/command_processors/
|
10
|
+
domain/command_processors/thing_processor.rb unless it exists
|
11
11
|
Adds a command handler to this or an existing processor
|
@@ -44,7 +44,7 @@ module Disco
|
|
44
44
|
|
45
45
|
process #{class_name}Command do |command|
|
46
46
|
command.is_valid_do do#{extra}
|
47
|
-
|
47
|
+
event #{event_class_name}Event.new command.to_hash#{merge}
|
48
48
|
end
|
49
49
|
end
|
50
50
|
EOF
|
@@ -6,7 +6,7 @@ module Disco
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
|
-
class_option :event, type: :string, default: nil, desc: '
|
9
|
+
class_option :event, type: :string, default: nil, desc: 'class_name of the event (defaults to NAME)'
|
10
10
|
class_option :skip_event, type: :boolean, default: false, desc: 'skip event generation'
|
11
11
|
end
|
12
12
|
|
@@ -12,7 +12,7 @@ module Disco
|
|
12
12
|
|
13
13
|
def initialize(args, *options)
|
14
14
|
super
|
15
|
-
|
15
|
+
assign_processor_name!(processor_name)
|
16
16
|
end
|
17
17
|
|
18
18
|
protected
|
@@ -38,7 +38,7 @@ module Disco
|
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
-
def
|
41
|
+
def assign_processor_name!(processor_name)
|
42
42
|
@processor_class_path = processor_name.include?('/') ? processor_name.split('/') : processor_name.split('::')
|
43
43
|
@processor_class_path.map! &:underscore
|
44
44
|
@processor_file_name = @processor_class_path.pop
|
@@ -9,21 +9,14 @@ module Disco
|
|
9
9
|
include ProcessorName
|
10
10
|
include Domain
|
11
11
|
|
12
|
+
ACTIONS = %w(create update delete)
|
13
|
+
|
12
14
|
hook_for :model, in: :disco, require: true
|
13
15
|
|
14
16
|
hook_for :command, in: :disco, require: true do |hook|
|
15
17
|
raise 'do not use id as scaffolding attribute! This is reserved for the model id' if attributes_names.include? 'id'
|
16
|
-
|
17
|
-
|
18
|
-
args << 'id' unless action == 'create'
|
19
|
-
args += attributes_names unless action == 'delete'
|
20
|
-
opts = ["--event=#{(class_path + ["#{action}d_#{file_name}"]) * '/'}"]
|
21
|
-
opts << "--processor=#{processor_name}" unless skip_processor?
|
22
|
-
opts << "--model_name=#{class_name}"
|
23
|
-
opts << '--unique_id' if action == 'create'
|
24
|
-
opts << '--persisted' if action == 'update'
|
25
|
-
opts << '--skip_model' if action == 'delete'
|
26
|
-
invoke hook, args, opts
|
18
|
+
ACTIONS.each do |action|
|
19
|
+
invoke hook, args_for_command_action(action), opts_for_command_action(action)
|
27
20
|
add_to_projections(action)
|
28
21
|
end
|
29
22
|
end
|
@@ -52,6 +45,23 @@ module Disco
|
|
52
45
|
|
53
46
|
protected
|
54
47
|
|
48
|
+
def args_for_command_action(action)
|
49
|
+
args = [command_name_for_action(action)]
|
50
|
+
args << 'id' unless action == 'create'
|
51
|
+
args += attributes_names unless action == 'delete'
|
52
|
+
args
|
53
|
+
end
|
54
|
+
|
55
|
+
def opts_for_command_action(action)
|
56
|
+
opts = ["--event=#{event_name_for_action(action)}"]
|
57
|
+
opts << "--processor=#{processor_name}" unless skip_processor?
|
58
|
+
opts << "--model_name=#{class_name}"
|
59
|
+
opts << '--unique_id' if action == 'create'
|
60
|
+
opts << '--persisted' if action == 'update'
|
61
|
+
opts << '--skip_model' if action == 'delete'
|
62
|
+
opts
|
63
|
+
end
|
64
|
+
|
55
65
|
def add_event_stream_to_views
|
56
66
|
return if behavior == :revoke
|
57
67
|
include_text = '<%= javascript_tag render partial: \'application/eventstream/eventstream\', formats: [:js], locals: {event_id: @event_id} %>'
|
@@ -61,22 +71,38 @@ module Disco
|
|
61
71
|
|
62
72
|
def add_to_projections(action)
|
63
73
|
return if behavior == :revoke
|
64
|
-
event_func = (class_path + ["#{action}d_#{file_name}_event"]) * '__'
|
65
74
|
content = "
|
66
75
|
|
67
|
-
def #{
|
68
|
-
#{
|
76
|
+
def #{projection_name_for_action(action)}(event)
|
77
|
+
#{projection_body_for_action(action)}
|
69
78
|
end"
|
70
79
|
indent(content) if namespaced?
|
71
80
|
inject_into_file File.join('app/projections', class_path, "#{plural_file_name}_projection.rb"), content, after: /(\s)*include(\s)*ActiveProjection::ProjectionType/
|
72
81
|
end
|
73
82
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
}
|
83
|
+
def command_name_for_action(action)
|
84
|
+
(class_path + ["#{action}_#{file_name}"]) * '/'
|
85
|
+
end
|
86
|
+
|
87
|
+
def event_name_for_action(action)
|
88
|
+
(class_path + ["#{action}d_#{file_name}"]) * '/'
|
89
|
+
end
|
90
|
+
|
91
|
+
def projection_name_for_action(action)
|
92
|
+
(event_name_for_action(action) + '_event').gsub('/', '__')
|
93
|
+
end
|
94
|
+
|
95
|
+
def projection_body_for_action(action)
|
96
|
+
case action
|
97
|
+
when 'create'
|
98
|
+
"#{class_name}.create! event.to_hash"
|
99
|
+
when 'update'
|
100
|
+
"#{class_name}.find(event.id).update! event.values"
|
101
|
+
when 'delete'
|
102
|
+
"#{class_name}.find(event.id).destroy!"
|
103
|
+
else
|
104
|
+
raise 'unknown action'
|
105
|
+
end
|
80
106
|
end
|
81
107
|
|
82
108
|
def add_line_with_indent(target, indent, str)
|
data/lib/rails-disco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disco-railties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0.
|
4
|
+
version: 0.5.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HicknHack Software
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.5.0.
|
19
|
+
version: 0.5.0.rc3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.5.0.
|
26
|
+
version: 0.5.0.rc3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: active_domain
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.5.0.
|
33
|
+
version: 0.5.0.rc3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.5.0.
|
40
|
+
version: 0.5.0.rc3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: active_projection
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.5.0.
|
47
|
+
version: 0.5.0.rc3
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.5.0.
|
54
|
+
version: 0.5.0.rc3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|