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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab1a0792baad4ead40b4de0f071a96a60cc86bc1
4
- data.tar.gz: b245a7e68dc7176fb0c22d17272990804311ca91
3
+ metadata.gz: 0bd165f0944683d0c5b4de539f11bea205e7444e
4
+ data.tar.gz: 6b02ed63e4f88f0eb0814d69a908fa5f2b582177
5
5
  SHA512:
6
- metadata.gz: 1a0cd16c7353a74797cde9590e04eae2a513a824bfe2bc8a7f3f73af3fe4c73cd5aba20ea4ccad969e7a28dd9743059263fb0c9572c3c722fa3b3ae4d7435ee8
7
- data.tar.gz: 9fc865c07e9028491fdcf826f87d6c88a5aa5049e3df08c6efa0f247fe17ca67b3057033af86d05d933eb3d36a15301db4dd25e9f91d09ac066635af15f1a872
6
+ metadata.gz: 3a782de11c12f863ce01b8d00c0553c4ce53c0fca2922147602b64ae21e713c4e4f3df28db37a2d1ac34274daa86f311ee8ab5704a12caa78e96c2a619e4b8c9
7
+ data.tar.gz: 85a24c8d0f675affd054749e9024b456579abd2729f80f96a55b73453a9bbbeeec1292408bedf45e15fbb1d979990f51fa3d03211c31dba0a0b78bb9e0e9e9fa
@@ -5,6 +5,7 @@ aliases = {
5
5
  's' => 'server',
6
6
  'ps' => 'projectionserver',
7
7
  'g' => 'generate',
8
+ 'd' => 'destroy',
8
9
  '-h' => '--help',
9
10
  '-v' => '--version',
10
11
  }
@@ -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=Things
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/things_processor.rb unless it exists
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
- command.is_valid_do { event #{event_class_name}Event.new command.to_hash#{merge} }
47
+ event #{event_class_name}Event.new command.to_hash#{merge}
48
48
  end
49
49
  end
50
50
  EOF
@@ -7,7 +7,7 @@ class <%= event_class_name %>Event
7
7
  <%- if event_attributes_names.include?('id') -%>
8
8
  attributes_except :id
9
9
  <%- else -%>
10
- attributes
10
+ to_hash
11
11
  <%- end -%>
12
12
  end
13
13
  <%- end -%>
@@ -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: 'name of the event (defaults to NAME)'
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
- assign_processor_names!(processor_name)
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 assign_processor_names!(processor_name)
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
- %w(create update delete).each do |action|
17
- args = [(class_path + ["#{action}_#{file_name}"]) * '/']
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 #{event_func}(event)
68
- #{method_bodies[action.to_sym]}
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 method_bodies
75
- @method_bodies ||= {
76
- create: "#{class_name}.create! event.to_hash",
77
- update: "#{class_name}.find(event.id).update! event.values",
78
- delete: "#{class_name}.find(event.id).destroy!",
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)
@@ -3,7 +3,7 @@ module RailsDisco
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
5
  TINY = 0
6
- PRE = "rc2"
6
+ PRE = "rc3"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
9
9
  end
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.rc2
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.rc2
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.rc2
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.rc2
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.rc2
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.rc2
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.rc2
54
+ version: 0.5.0.rc3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement