disco-railties 0.5.0.rc1 → 0.5.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/disco/command/command_generator.rb +25 -5
- data/lib/generators/disco/command/templates/command.rb.erb +2 -10
- data/lib/generators/disco/command/templates/event.rb.erb +6 -2
- data/lib/generators/disco/command_processor/command_processor_generator.rb +1 -1
- data/lib/generators/disco/event_name.rb +2 -2
- data/lib/generators/disco/model/model_generator.rb +1 -1
- data/lib/generators/disco/model/templates/{domain_model.rb → domain_model.rb.erb} +1 -1
- data/lib/generators/disco/model/templates/{model.rb → model.rb.erb} +2 -2
- data/lib/generators/disco/processor_name.rb +2 -2
- data/lib/generators/disco/scaffold/scaffold_generator.rb +5 -9
- data/lib/generators/disco/use_domain_option.rb +1 -1
- data/lib/rails-disco/version.rb +1 -1
- metadata +11 -11
- /data/lib/generators/disco/command_processor/templates/{command_processor.rb → command_processor.rb.erb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab1a0792baad4ead40b4de0f071a96a60cc86bc1
|
4
|
+
data.tar.gz: b245a7e68dc7176fb0c22d17272990804311ca91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a0cd16c7353a74797cde9590e04eae2a513a824bfe2bc8a7f3f73af3fe4c73cd5aba20ea4ccad969e7a28dd9743059263fb0c9572c3c722fa3b3ae4d7435ee8
|
7
|
+
data.tar.gz: 9fc865c07e9028491fdcf826f87d6c88a5aa5049e3df08c6efa0f247fe17ca67b3057033af86d05d933eb3d36a15301db4dd25e9f91d09ac066635af15f1a872
|
@@ -7,6 +7,7 @@ module Disco
|
|
7
7
|
class CommandGenerator < Rails::Generators::NamedBase
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
9
9
|
argument :attributes, type: :array, default: [], banner: 'attribute attribute'
|
10
|
+
class_option :unique_id, type: :boolean, default: false, desc: 'Create a unique id when processing the command'
|
10
11
|
class_option :skip_model, type: :boolean, default: false, desc: 'Skip active model from the command'
|
11
12
|
class_option :model_name, type: :string, desc: 'Name of the active model behind the command'
|
12
13
|
class_option :persisted, type: :boolean, default: false, desc: 'Does the command update an existing model'
|
@@ -20,7 +21,6 @@ module Disco
|
|
20
21
|
|
21
22
|
def create_related_event_file
|
22
23
|
return if skip_event?
|
23
|
-
raise 'do not use id as attribute, this is reserved for the event id itself' if attributes_names.include? 'id'
|
24
24
|
template 'event.rb.erb', File.join('app/events', event_class_path, "#{event_file_name}_event.rb")
|
25
25
|
end
|
26
26
|
|
@@ -35,17 +35,29 @@ module Disco
|
|
35
35
|
|
36
36
|
def add_to_command_processor
|
37
37
|
return if skip_processor? || (behavior == :revoke)
|
38
|
-
|
38
|
+
extra, merge = '', ''
|
39
|
+
if unique_id?
|
40
|
+
extra = "\n id = ActiveDomain::UniqueCommandIdRepository.new_for command.class.name"
|
41
|
+
merge = '.merge(id: id)'
|
42
|
+
end
|
43
|
+
content = <<-EOF
|
39
44
|
|
40
45
|
process #{class_name}Command do |command|
|
41
|
-
command.is_valid_do
|
42
|
-
|
46
|
+
command.is_valid_do do#{extra}
|
47
|
+
command.is_valid_do { event #{event_class_name}Event.new command.to_hash#{merge} }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
EOF
|
43
51
|
file = File.join('domain/command_processors', processor_domain_class_path, "#{processor_file_name}_processor.rb")
|
44
|
-
inject_into_file file, content, after:
|
52
|
+
inject_into_file file, content, after: /\s*include\s+ActiveDomain::CommandProcessor/
|
45
53
|
end
|
46
54
|
|
47
55
|
protected
|
48
56
|
|
57
|
+
def unique_id?
|
58
|
+
options[:unique_id]
|
59
|
+
end
|
60
|
+
|
49
61
|
def skip_model?
|
50
62
|
options[:skip_model]
|
51
63
|
end
|
@@ -58,6 +70,14 @@ module Disco
|
|
58
70
|
options[:persisted]
|
59
71
|
end
|
60
72
|
|
73
|
+
def event_attributes_names
|
74
|
+
@event_attribute_names ||= if unique_id?
|
75
|
+
attributes_names.dup.unshift 'id'
|
76
|
+
else
|
77
|
+
attributes_names
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
61
81
|
private
|
62
82
|
|
63
83
|
# allow this generator to be called multiple times
|
@@ -4,18 +4,10 @@ class <%= class_name %>Command
|
|
4
4
|
include ActiveModel::Model
|
5
5
|
<%- end -%>
|
6
6
|
include ActiveEvent::Command
|
7
|
-
attributes <%= (['id'] + attributes_names).map{|x| ":#{x}"}.join(', ') %>
|
8
7
|
<%- if !model_name.blank? && !skip_model? -%>
|
9
|
-
|
10
|
-
def self.model_name
|
11
|
-
@_model_name ||= begin
|
12
|
-
namespace = self.parents.detect do |n|
|
13
|
-
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
14
|
-
end
|
15
|
-
ActiveModel::Name.new(self, namespace, <%= model_name.inspect %>)
|
16
|
-
end
|
17
|
-
end
|
8
|
+
form_name '<%= model_name %>'
|
18
9
|
<%- end -%>
|
10
|
+
attributes <%= attributes_names.map{|x| ":#{x}"}.join(', ') %>
|
19
11
|
<%- if persisted? && ! skip_model? -%>
|
20
12
|
|
21
13
|
def persisted?; true end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
class <%= event_class_name %>Event
|
3
3
|
include ActiveEvent::EventType
|
4
|
-
attributes <%=
|
5
|
-
<%- unless attributes_names
|
4
|
+
attributes <%= event_attributes_names.map{|x| ":#{x}"}.join(', ') %>
|
5
|
+
<%- unless attributes_names == ['id'] -%>
|
6
6
|
def values
|
7
|
+
<%- if event_attributes_names.include?('id') -%>
|
7
8
|
attributes_except :id
|
9
|
+
<%- else -%>
|
10
|
+
attributes
|
11
|
+
<%- end -%>
|
8
12
|
end
|
9
13
|
<%- end -%>
|
10
14
|
end
|
@@ -8,7 +8,7 @@ module Disco
|
|
8
8
|
hide!
|
9
9
|
|
10
10
|
def create_command_processor_file
|
11
|
-
template 'command_processor.rb', File.join('domain/command_processors', domain_class_path, "#{file_name}_processor.rb")
|
11
|
+
template 'command_processor.rb.erb', File.join('domain/command_processors', domain_class_path, "#{file_name}_processor.rb")
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
@@ -6,8 +6,8 @@ module Disco
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
|
-
class_option :event, type: :string, default: nil, desc:
|
10
|
-
class_option :skip_event, type: :boolean, default: false, desc:
|
9
|
+
class_option :event, type: :string, default: nil, desc: 'name of the event (defaults to NAME)'
|
10
|
+
class_option :skip_event, type: :boolean, default: false, desc: 'skip event generation'
|
11
11
|
end
|
12
12
|
|
13
13
|
def initialize(args, *options)
|
@@ -12,7 +12,7 @@ module Disco
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_model_file
|
15
|
-
template use_domain('model.rb'), use_domain_class_file_path('models', "#{file_name}.rb")
|
15
|
+
template use_domain('model.rb.erb'), use_domain_class_file_path('models', "#{file_name}.rb")
|
16
16
|
end
|
17
17
|
|
18
18
|
hook_for :migration, require: true do |hook|
|
@@ -6,8 +6,8 @@ module Disco
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
|
-
class_option :processor, type: :string, default: nil, desc:
|
10
|
-
class_option :skip_processor, type: :boolean, default: false, desc:
|
9
|
+
class_option :processor, type: :string, default: nil, desc: 'class_name of the command processor (defaults to NAME)'
|
10
|
+
class_option :skip_processor, type: :boolean, default: false, desc: 'Skip command processor generation'
|
11
11
|
end
|
12
12
|
|
13
13
|
def initialize(args, *options)
|
@@ -12,18 +12,20 @@ module Disco
|
|
12
12
|
hook_for :model, in: :disco, require: true
|
13
13
|
|
14
14
|
hook_for :command, in: :disco, require: true do |hook|
|
15
|
+
raise 'do not use id as scaffolding attribute! This is reserved for the model id' if attributes_names.include? 'id'
|
15
16
|
%w(create update delete).each do |action|
|
16
17
|
args = [(class_path + ["#{action}_#{file_name}"]) * '/']
|
18
|
+
args << 'id' unless action == 'create'
|
17
19
|
args += attributes_names unless action == 'delete'
|
18
20
|
opts = ["--event=#{(class_path + ["#{action}d_#{file_name}"]) * '/'}"]
|
19
21
|
opts << "--processor=#{processor_name}" unless skip_processor?
|
20
|
-
opts << '--skip_model' if action == 'delete'
|
21
22
|
opts << "--model_name=#{class_name}"
|
23
|
+
opts << '--unique_id' if action == 'create'
|
22
24
|
opts << '--persisted' if action == 'update'
|
25
|
+
opts << '--skip_model' if action == 'delete'
|
23
26
|
invoke hook, args, opts
|
24
27
|
add_to_projections(action)
|
25
28
|
end
|
26
|
-
add_to_command_processor
|
27
29
|
end
|
28
30
|
|
29
31
|
def add_routes
|
@@ -57,12 +59,6 @@ module Disco
|
|
57
59
|
prepend_to_file File.join('app/views', class_path, plural_file_name, 'show.html.erb'), include_text
|
58
60
|
end
|
59
61
|
|
60
|
-
def add_to_command_processor
|
61
|
-
return if behavior == :revoke
|
62
|
-
content = "\n command.id = ActiveDomain::UniqueCommandIdRepository.new_for command.class.name"
|
63
|
-
insert_into_file File.join('domain/command_processors', domain_class_path, "#{processor_file_name}_processor.rb"), content, after: /(\s)*process(\s)*(.)*CreateCommand(.)*/
|
64
|
-
end
|
65
|
-
|
66
62
|
def add_to_projections(action)
|
67
63
|
return if behavior == :revoke
|
68
64
|
event_func = (class_path + ["#{action}d_#{file_name}_event"]) * '__'
|
@@ -77,7 +73,7 @@ module Disco
|
|
77
73
|
|
78
74
|
def method_bodies
|
79
75
|
@method_bodies ||= {
|
80
|
-
create: "#{class_name}.create! event.
|
76
|
+
create: "#{class_name}.create! event.to_hash",
|
81
77
|
update: "#{class_name}.find(event.id).update! event.values",
|
82
78
|
delete: "#{class_name}.find(event.id).destroy!",
|
83
79
|
}
|
data/lib/rails-disco/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HicknHack Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_event
|
@@ -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.rc2
|
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.rc2
|
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.rc2
|
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.rc2
|
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.rc2
|
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.rc2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,7 +99,7 @@ files:
|
|
99
99
|
- lib/generators/disco/command/templates/event.rb.erb
|
100
100
|
- lib/generators/disco/command/USAGE
|
101
101
|
- lib/generators/disco/command_processor/command_processor_generator.rb
|
102
|
-
- lib/generators/disco/command_processor/templates/command_processor.rb
|
102
|
+
- lib/generators/disco/command_processor/templates/command_processor.rb.erb
|
103
103
|
- lib/generators/disco/command_processor/USAGE
|
104
104
|
- lib/generators/disco/domain.rb
|
105
105
|
- lib/generators/disco/event_name.rb
|
@@ -107,8 +107,8 @@ files:
|
|
107
107
|
- lib/generators/disco/migration/templates/create_table_migration.rb
|
108
108
|
- lib/generators/disco/migration/USAGE
|
109
109
|
- lib/generators/disco/model/model_generator.rb
|
110
|
-
- lib/generators/disco/model/templates/domain_model.rb
|
111
|
-
- lib/generators/disco/model/templates/model.rb
|
110
|
+
- lib/generators/disco/model/templates/domain_model.rb.erb
|
111
|
+
- lib/generators/disco/model/templates/model.rb.erb
|
112
112
|
- lib/generators/disco/model/USAGE
|
113
113
|
- lib/generators/disco/processor_name.rb
|
114
114
|
- lib/generators/disco/projection/projection_generator.rb
|
File without changes
|