hecks-domain 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/hecks/domain/commands/generate.rb +98 -0
- data/lib/hecks/domain/commands.rb +1 -0
- data/lib/hecks/domain/generators/domain.rb +21 -0
- data/lib/hecks/domain/generators/domain_files.rb +28 -0
- data/lib/hecks/domain/generators/entity.rb +30 -0
- data/lib/hecks/domain/generators/operation.rb +32 -0
- data/lib/hecks/domain/generators/root.rb +30 -0
- data/lib/hecks/domain/generators/spec.rb +30 -0
- data/lib/hecks/domain/generators/value_object.rb +30 -0
- data/lib/hecks/domain/generators.rb +7 -0
- data/lib/hecks/domain/parser/aggregate.rb +44 -0
- data/lib/hecks/domain/parser/domain_object.rb +123 -0
- data/lib/hecks/domain/parser/entity_field.rb +55 -0
- data/lib/hecks/domain/parser/fields.rb +16 -0
- data/lib/hecks/domain/parser/list_field.rb +13 -0
- data/lib/hecks/domain/parser/operation.rb +15 -0
- data/lib/hecks/domain/parser/reference_field.rb +12 -0
- data/lib/hecks/domain/parser/spec_helper.rb +0 -0
- data/lib/hecks/domain/parser/value_field.rb +48 -0
- data/lib/hecks/domain/parser.rb +95 -0
- data/lib/hecks/domain/support/string.rb +9 -0
- data/lib/hecks/domain/support.rb +1 -0
- data/lib/hecks/domain/templates/%domain_name%.gemspec.tt +12 -0
- data/lib/hecks/domain/templates/%folder_name%/Domainfile.tt +9 -0
- data/lib/hecks/domain/templates/%folder_name%/events/command_will_run.rb.tt +11 -0
- data/lib/hecks/domain/templates/%folder_name%/spec/spec_helper.rb.tt +1 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/commands.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/events.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +37 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/invariants.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/queries.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/repository.rb.tt +68 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/subscribers.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%.rb.tt +34 -0
- data/lib/hecks/domain/templates/lib/%domain_name%.rb.tt +9 -0
- data/lib/hecks/domain/templates/lib/support/commands/command_loader.rb +18 -0
- data/lib/hecks/domain/templates/lib/support/commands/command_runner.rb +17 -0
- data/lib/hecks/domain/templates/lib/support/commands.rb +2 -0
- data/lib/hecks/domain/templates/lib/support/domain_object.rb +25 -0
- data/lib/hecks/domain/templates/lib/support/events/domain_event.rb +14 -0
- data/lib/hecks/domain/templates/lib/support/events/domain_event_publisher.rb +34 -0
- data/lib/hecks/domain/templates/lib/support/events.rb +14 -0
- data/lib/hecks/domain/templates/lib/support/factories/factory_loader.rb +21 -0
- data/lib/hecks/domain/templates/lib/support/factories.rb +1 -0
- data/lib/hecks/domain/templates/lib/support/invariants/invariant_loader.rb +24 -0
- data/lib/hecks/domain/templates/lib/support/queries/query_loader.rb +18 -0
- data/lib/hecks/domain/templates/lib/support/queries.rb +1 -0
- data/lib/hecks/domain/templates/lib/support/repositories/repository_loader.rb +32 -0
- data/lib/hecks/domain/templates/lib/support/root.rb +27 -0
- data/lib/hecks/domain/templates/lib/support/support/string.rb +9 -0
- data/lib/hecks/domain/templates/lib/support.rb +11 -0
- data/lib/hecks/domain/templates/operation/%aggregate_name%/%domain_object_name%/commands/%operation_name%.rb.tt +21 -0
- data/lib/hecks/domain/templates/root/%aggregate_name%/root.rb.tt +14 -0
- data/lib/hecks/domain/templates/spec/%aggregate_name%/%root_name%_spec.rb.tt +12 -0
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +37 -0
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories.rb.tt +11 -0
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%.rb.tt +34 -0
- data/lib/hecks/domain/top_level_methods.rb +3 -0
- data/lib/hecks/domain.rb +21 -0
- metadata +87 -42
- data/lib/cli/builder/aggregate_command_line_builder.rb +0 -21
- data/lib/cli/builder/builder.rb +0 -3
- data/lib/cli/builder/reference_command_line_builder.rb +0 -22
- data/lib/cli/builder/value_object_command_line_builder.rb +0 -22
- data/lib/cli/cli.rb +0 -8
- data/lib/cli/command_builder.rb +0 -65
- data/lib/cli/domain_object/assignment_template.rb +0 -42
- data/lib/cli/domain_object/option_formatter.rb +0 -35
- data/lib/cli/generate_domain_object.rb +0 -70
- data/lib/cli/new.rb +0 -49
- data/lib/cli/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +0 -16
- data/lib/cli/templates/aggregate/lib/domain/%name%/%name%.rb.tt +0 -9
- data/lib/cli/templates/aggregate/lib/domain/%name%/repository.rb.tt +0 -38
- data/lib/cli/templates/domain/%name%.gemspec.tt +0 -12
- data/lib/cli/templates/domain/Version +0 -1
- data/lib/cli/templates/domain/lib/%name%.rb.tt +0 -21
- data/lib/cli/templates/domain/spec/spec_helper.rb.tt +0 -4
- data/lib/cli/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +0 -25
- data/lib/cli/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +0 -24
- data/lib/domain_builder/attribute.rb +0 -61
- data/lib/domain_builder/domain.rb +0 -16
- data/lib/domain_builder/domain_module.rb +0 -32
- data/lib/domain_builder/domain_object.rb +0 -44
- data/lib/domain_builder/head.rb +0 -5
- data/lib/domain_builder/hecks-domain-builder.rb +0 -37
- data/lib/domain_builder/reference.rb +0 -16
- data/lib/domain_builder/value.rb +0 -5
- data/lib/hecks-domain.rb +0 -4
@@ -0,0 +1,21 @@
|
|
1
|
+
module <%= @domain_object.aggregate.domain.name %>
|
2
|
+
module Domain
|
3
|
+
module <%= aggregate.name%>
|
4
|
+
class <%= domain_object.name %>
|
5
|
+
module Commands
|
6
|
+
class <%= operation.name %>
|
7
|
+
attr_reader :root, :args
|
8
|
+
|
9
|
+
def initialize(root, args={})
|
10
|
+
@root = root
|
11
|
+
@args = args
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '<%= root.name.to_s.underscore %>'
|
2
|
+
<% root.aggregate.domain_objects.each do |domain_object| -%>
|
3
|
+
<% next if domain_object.is_a?(HecksDomain::Parser::Root) -%>
|
4
|
+
require_relative '<%= domain_object.name.to_s.underscore %>'
|
5
|
+
<% end -%>
|
6
|
+
|
7
|
+
module <%= domain.name %>
|
8
|
+
module Domain
|
9
|
+
module <%= aggregate.name %>
|
10
|
+
class Root < <%= root.name %>
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe <%= "#{domain.name}::Domain::#{aggregate.name}::#{root.name}" %> do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
<% root.operations_get.each do |operation| -%>
|
7
|
+
describe '#<%= operation.name.to_s.underscore %>' do
|
8
|
+
xit 'should behave' do
|
9
|
+
end
|
10
|
+
end
|
11
|
+
<% end -%>
|
12
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module <%= @domain.name %>
|
2
|
+
module Domain
|
3
|
+
module <%= @aggregate.name%>
|
4
|
+
class <%= @domain_object.name %>
|
5
|
+
module Factories
|
6
|
+
# Recursively build domain objects. Used in the domain as the primary
|
7
|
+
# factory. The results of #build can be passed to any other build
|
8
|
+
# factory in the domain. Takes a hash, or a list of hashes. If a list
|
9
|
+
# is given, it will return a list of the instantiated objects
|
10
|
+
class Build
|
11
|
+
def self.factory(args=nil)
|
12
|
+
return args if args.nil?
|
13
|
+
return args unless args.is_a?(Hash)
|
14
|
+
|
15
|
+
[args].flatten.map do |domain_object_args|
|
16
|
+
new_domain_object(domain_object_args)
|
17
|
+
end.tap do |result|
|
18
|
+
return result.first unless args.is_a?(Array)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.new_domain_object(args)
|
23
|
+
<%= @domain_object.name %>.new(
|
24
|
+
args.merge(
|
25
|
+
<% @domain_object.fields.each do |field| -%>
|
26
|
+
<% next unless (field.respond_to?(:module_name) && field.module_name) -%>
|
27
|
+
<%= field.name.to_s%>: <%= field.module_name.is_a?(Hash) ? 'Domain::' + field.module_name.to_a.join('::').to_s : field.module_name.to_s %>.build(args[:<%= field.name.to_s%>]),
|
28
|
+
<% end -%>
|
29
|
+
)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module <%= domain.name %>
|
2
|
+
module Domain
|
3
|
+
module <%= aggregate.name %>
|
4
|
+
class <%= domain_object.name %>
|
5
|
+
<%= 'include Support::Root' if domain_object.is_a?(HecksDomain::Parser::Root) %>
|
6
|
+
include Support::DomainObject
|
7
|
+
|
8
|
+
attr_reader <%= domain_object.public_accessors %>
|
9
|
+
|
10
|
+
def initialize(<%= domain_object.initializer_attributes %>)
|
11
|
+
<% domain_object.fields.each do |field| -%>
|
12
|
+
<%= "@#{field.name} = #{field.initial_state}" %>
|
13
|
+
<% end -%>
|
14
|
+
end
|
15
|
+
<% domain_object.boolean_accessors.each do |field| -%>
|
16
|
+
|
17
|
+
def <%= field.name %>?
|
18
|
+
@<%= field.name %>
|
19
|
+
end
|
20
|
+
<% end -%>
|
21
|
+
<% domain_object.list_accessors.each do |field| -%>
|
22
|
+
|
23
|
+
def <%= field.name %>
|
24
|
+
@<%= field.name %>.clone.freeze
|
25
|
+
end
|
26
|
+
<% end -%>
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_writer <%= domain_object.private_accessors %>
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/hecks/domain.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'singleton'
|
3
|
+
require 'erubis'
|
4
|
+
require 'thor'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
require_relative 'domain/support'
|
8
|
+
require_relative 'domain/parser'
|
9
|
+
require_relative 'domain/generators'
|
10
|
+
require_relative 'domain/commands'
|
11
|
+
|
12
|
+
class HecksDomain
|
13
|
+
attr_reader :domain
|
14
|
+
def initialize(name, &block)
|
15
|
+
@domain = Parser.new(name, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.parser(name, &block)
|
19
|
+
new name, &block
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,78 +1,124 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hecks-domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Hecks Domain Developer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0.8'
|
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: '
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: erubis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.7'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: thor
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
47
|
+
version: '0.20'
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
41
|
-
description:
|
42
|
-
email:
|
54
|
+
version: '0.20'
|
55
|
+
description: A Domain Specific Language for generating Domain Driven Designs
|
56
|
+
email: dev@hecks_domain.com
|
43
57
|
executables: []
|
44
58
|
extensions: []
|
45
59
|
extra_rdoc_files: []
|
46
60
|
files:
|
47
|
-
- lib/
|
48
|
-
- lib/
|
49
|
-
- lib/
|
50
|
-
- lib/
|
51
|
-
- lib/
|
52
|
-
- lib/
|
53
|
-
- lib/
|
54
|
-
- lib/
|
55
|
-
- lib/
|
56
|
-
- lib/
|
57
|
-
- lib/
|
58
|
-
- lib/
|
59
|
-
- lib/
|
60
|
-
- lib/
|
61
|
-
- lib/
|
62
|
-
- lib/
|
63
|
-
- lib/
|
64
|
-
- lib/
|
65
|
-
- lib/
|
66
|
-
- lib/
|
67
|
-
- lib/
|
68
|
-
- lib/
|
69
|
-
- lib/
|
70
|
-
- lib/
|
71
|
-
- lib/
|
72
|
-
- lib/
|
73
|
-
- lib/
|
74
|
-
- lib/hecks
|
75
|
-
|
61
|
+
- lib/hecks/domain.rb
|
62
|
+
- lib/hecks/domain/commands.rb
|
63
|
+
- lib/hecks/domain/commands/generate.rb
|
64
|
+
- lib/hecks/domain/generators.rb
|
65
|
+
- lib/hecks/domain/generators/domain.rb
|
66
|
+
- lib/hecks/domain/generators/domain_files.rb
|
67
|
+
- lib/hecks/domain/generators/entity.rb
|
68
|
+
- lib/hecks/domain/generators/operation.rb
|
69
|
+
- lib/hecks/domain/generators/root.rb
|
70
|
+
- lib/hecks/domain/generators/spec.rb
|
71
|
+
- lib/hecks/domain/generators/value_object.rb
|
72
|
+
- lib/hecks/domain/parser.rb
|
73
|
+
- lib/hecks/domain/parser/aggregate.rb
|
74
|
+
- lib/hecks/domain/parser/domain_object.rb
|
75
|
+
- lib/hecks/domain/parser/entity_field.rb
|
76
|
+
- lib/hecks/domain/parser/fields.rb
|
77
|
+
- lib/hecks/domain/parser/list_field.rb
|
78
|
+
- lib/hecks/domain/parser/operation.rb
|
79
|
+
- lib/hecks/domain/parser/reference_field.rb
|
80
|
+
- lib/hecks/domain/parser/spec_helper.rb
|
81
|
+
- lib/hecks/domain/parser/value_field.rb
|
82
|
+
- lib/hecks/domain/support.rb
|
83
|
+
- lib/hecks/domain/support/string.rb
|
84
|
+
- lib/hecks/domain/templates/%domain_name%.gemspec.tt
|
85
|
+
- lib/hecks/domain/templates/%folder_name%/Domainfile.tt
|
86
|
+
- lib/hecks/domain/templates/%folder_name%/events/command_will_run.rb.tt
|
87
|
+
- lib/hecks/domain/templates/%folder_name%/spec/spec_helper.rb.tt
|
88
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%.rb.tt
|
89
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/commands.rb.tt
|
90
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/events.rb.tt
|
91
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories.rb.tt
|
92
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories/build.rb.tt
|
93
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/invariants.rb.tt
|
94
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/queries.rb.tt
|
95
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/repository.rb.tt
|
96
|
+
- lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/subscribers.rb.tt
|
97
|
+
- lib/hecks/domain/templates/lib/%domain_name%.rb.tt
|
98
|
+
- lib/hecks/domain/templates/lib/support.rb
|
99
|
+
- lib/hecks/domain/templates/lib/support/commands.rb
|
100
|
+
- lib/hecks/domain/templates/lib/support/commands/command_loader.rb
|
101
|
+
- lib/hecks/domain/templates/lib/support/commands/command_runner.rb
|
102
|
+
- lib/hecks/domain/templates/lib/support/domain_object.rb
|
103
|
+
- lib/hecks/domain/templates/lib/support/events.rb
|
104
|
+
- lib/hecks/domain/templates/lib/support/events/domain_event.rb
|
105
|
+
- lib/hecks/domain/templates/lib/support/events/domain_event_publisher.rb
|
106
|
+
- lib/hecks/domain/templates/lib/support/factories.rb
|
107
|
+
- lib/hecks/domain/templates/lib/support/factories/factory_loader.rb
|
108
|
+
- lib/hecks/domain/templates/lib/support/invariants/invariant_loader.rb
|
109
|
+
- lib/hecks/domain/templates/lib/support/queries.rb
|
110
|
+
- lib/hecks/domain/templates/lib/support/queries/query_loader.rb
|
111
|
+
- lib/hecks/domain/templates/lib/support/repositories/repository_loader.rb
|
112
|
+
- lib/hecks/domain/templates/lib/support/root.rb
|
113
|
+
- lib/hecks/domain/templates/lib/support/support/string.rb
|
114
|
+
- lib/hecks/domain/templates/operation/%aggregate_name%/%domain_object_name%/commands/%operation_name%.rb.tt
|
115
|
+
- lib/hecks/domain/templates/root/%aggregate_name%/root.rb.tt
|
116
|
+
- lib/hecks/domain/templates/spec/%aggregate_name%/%root_name%_spec.rb.tt
|
117
|
+
- lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%.rb.tt
|
118
|
+
- lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories.rb.tt
|
119
|
+
- lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories/build.rb.tt
|
120
|
+
- lib/hecks/domain/top_level_methods.rb
|
121
|
+
homepage: http://www.example.com
|
76
122
|
licenses:
|
77
123
|
- MIT
|
78
124
|
metadata: {}
|
@@ -91,9 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
137
|
- !ruby/object:Gem::Version
|
92
138
|
version: '0'
|
93
139
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 2.6.10
|
140
|
+
rubygems_version: 3.0.3
|
96
141
|
signing_key:
|
97
142
|
specification_version: 4
|
98
|
-
summary:
|
143
|
+
summary: 3DSL
|
99
144
|
test_files: []
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module HecksDomain
|
2
|
-
module CLI
|
3
|
-
class CommandBuilder
|
4
|
-
# Build an aggregate
|
5
|
-
module AggregateCommandLineBuilder
|
6
|
-
def self.build(domain, runner)
|
7
|
-
domain.domain_modules.values.each do |domain_module|
|
8
|
-
runner.call(
|
9
|
-
[
|
10
|
-
'generate domain_object',
|
11
|
-
'-t', 'aggregate',
|
12
|
-
'-n', domain_module.name,
|
13
|
-
'--head_name', domain_module.head.name,
|
14
|
-
'-a', domain_module.head.attribute_string
|
15
|
-
])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/cli/builder/builder.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module HecksDomain
|
2
|
-
module CLI
|
3
|
-
class CommandBuilder
|
4
|
-
# Build a Reference object
|
5
|
-
module ReferenceCommandLineBuilder
|
6
|
-
def self.build(domain, runner)
|
7
|
-
domain.domain_modules.values.each do |domain_module|
|
8
|
-
domain_module.references.each do |reference|
|
9
|
-
runner.call([
|
10
|
-
'generate domain_object',
|
11
|
-
'-t', 'reference',
|
12
|
-
'-n', reference.name,
|
13
|
-
'-m', domain_module.name,
|
14
|
-
'-r', reference.referenced_entity
|
15
|
-
])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module HecksDomain
|
2
|
-
module CLI
|
3
|
-
class CommandBuilder
|
4
|
-
# Build a value object
|
5
|
-
module ValueObjectCommandLineBuilder
|
6
|
-
def self.build(domain, runner)
|
7
|
-
domain.domain_modules.values.each do |domain_module|
|
8
|
-
(domain_module.objects - [domain_module.head]).each do |value_object|
|
9
|
-
runner.call([
|
10
|
-
'generate domain_object',
|
11
|
-
'-t', 'value_object',
|
12
|
-
'-n', value_object.name,
|
13
|
-
'-m', domain_module.name,
|
14
|
-
'-a', value_object.attribute_string
|
15
|
-
])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/cli/cli.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
require_relative 'generate_domain_object'
|
4
|
-
require_relative 'new'
|
5
|
-
require_relative 'builder/builder'
|
6
|
-
require_relative 'command_builder'
|
7
|
-
require_relative "domain_object/assignment_template"
|
8
|
-
require_relative "domain_object/option_formatter"
|
data/lib/cli/command_builder.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'pathname'
|
3
|
-
|
4
|
-
if ENV['HECKS_DOMAIN_PATH']
|
5
|
-
load(ENV['HECKS_DOMAIN_PATH'])
|
6
|
-
else
|
7
|
-
load('Domain') if File.exist?('Domain')
|
8
|
-
end
|
9
|
-
|
10
|
-
module HecksDomain
|
11
|
-
module CLI
|
12
|
-
# Class for generating domain objects
|
13
|
-
class CommandBuilder
|
14
|
-
def initialize(name:, dry_run: false)
|
15
|
-
@name = name
|
16
|
-
@domain = DOMAIN
|
17
|
-
@dry_run = dry_run
|
18
|
-
@runner = HecksCLI::CommandRunner.new(domain, name, dry_run)
|
19
|
-
end
|
20
|
-
|
21
|
-
def call
|
22
|
-
delete_tmpfile
|
23
|
-
puts "\n"
|
24
|
-
generate :domain
|
25
|
-
generate :modules
|
26
|
-
generate :value_objects
|
27
|
-
generate :references
|
28
|
-
execute_tmpfile && return unless @dry_run
|
29
|
-
print_tmpfile
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
attr_reader :runner, :name, :domain
|
35
|
-
|
36
|
-
def print_tmpfile
|
37
|
-
puts File.read('tmp/hecks')
|
38
|
-
end
|
39
|
-
|
40
|
-
def delete_tmpfile
|
41
|
-
return unless Pathname('tmp/hecks').exist?
|
42
|
-
FileUtils.rm('tmp/hecks')
|
43
|
-
end
|
44
|
-
|
45
|
-
def execute_tmpfile
|
46
|
-
exec('bash -x tmp/hecks')
|
47
|
-
end
|
48
|
-
|
49
|
-
def generate(command)
|
50
|
-
case command
|
51
|
-
when :references
|
52
|
-
ReferenceCommandLineBuilder.build(domain, runner)
|
53
|
-
when :domain
|
54
|
-
runner.call(['new', '-n', name])
|
55
|
-
when :modules
|
56
|
-
AggregateCommandLineBuilder.build(domain, runner)
|
57
|
-
when :value_objects
|
58
|
-
ValueObjectCommandLineBuilder.build(domain, runner)
|
59
|
-
else
|
60
|
-
raise "unrecognized command: #{command}"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module HecksDomain
|
2
|
-
module CLI
|
3
|
-
# Helpful methods for supporting object creation
|
4
|
-
class GenerateDomainObject
|
5
|
-
class AssignmentTemplate
|
6
|
-
def initialize(attributes)
|
7
|
-
@attributes = attributes
|
8
|
-
end
|
9
|
-
|
10
|
-
def render
|
11
|
-
attributes.map do |attribute|
|
12
|
-
@attribute = HecksDomainBuilder::Attribute.new(attribute)
|
13
|
-
do_assignment
|
14
|
-
end.join("\n")
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_reader :attributes, :attribute
|
20
|
-
|
21
|
-
def do_assignment
|
22
|
-
return value_assignment if HecksDomainBuilder::Types.values.include?(@attribute.type)
|
23
|
-
return value_assignment if @attribute.type == 'Value'
|
24
|
-
return reference_factory_assignment if attribute.domain_module
|
25
|
-
return factory_assignment
|
26
|
-
end
|
27
|
-
|
28
|
-
def reference_factory_assignment
|
29
|
-
"@#{attribute.name} = #{attribute.type}Reference.factory(#{attribute.name})"
|
30
|
-
end
|
31
|
-
|
32
|
-
def factory_assignment
|
33
|
-
"@#{attribute.name} = #{attribute.type}.factory(#{attribute.name})"
|
34
|
-
end
|
35
|
-
|
36
|
-
def value_assignment
|
37
|
-
"@#{attribute.name} = #{attribute.name}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module HecksDomain
|
2
|
-
module CLI
|
3
|
-
class GenerateDomainObject
|
4
|
-
# Generates options in templates
|
5
|
-
class OptionFormatter
|
6
|
-
def initialize(attributes)
|
7
|
-
@attributes = attributes.map do |attribute|
|
8
|
-
HecksDomainBuilder::Attribute.new(attribute)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(format, include_id: false)
|
13
|
-
case format
|
14
|
-
when 'keys_and_values'
|
15
|
-
attributes(include_id).map { |attribute| (attribute.name + ': ' + attribute.name) }.join(', ')
|
16
|
-
when 'attribute_string'
|
17
|
-
attributes(include_id).map { |attribute| ':' + attribute.name }.join ', '
|
18
|
-
when 'param_names'
|
19
|
-
attributes(include_id).map { |attribute| attribute.name + ':' }.join ', '
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def attributes(include_id)
|
26
|
-
if include_id
|
27
|
-
@attributes + [HecksDomainBuilder::Attribute.new('id:value')]
|
28
|
-
else
|
29
|
-
@attributes
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module HecksDomain
|
3
|
-
module CLI
|
4
|
-
# Generate a domain object
|
5
|
-
class GenerateDomainObject < Thor::Group
|
6
|
-
include Thor::Actions
|
7
|
-
|
8
|
-
class_option :head_name, aliases: '-h', desc: 'the name of the aggregate head'
|
9
|
-
class_option :attributes, aliases: '-a', type: :array, desc: 'attributes for the aggregate head'
|
10
|
-
class_option :name, aliases: '-n', desc: 'attributes for the aggregate head'
|
11
|
-
class_option :type, aliases: '-t', desc: 'The type of domain object you want to create'
|
12
|
-
class_option :module_name, aliases: '-m', desc: 'Domain Module'
|
13
|
-
class_option :referenced_entity, aliases: '-r', desc: 'Referenced Entity'
|
14
|
-
|
15
|
-
def self.source_root
|
16
|
-
File.dirname(__FILE__) + '/templates'
|
17
|
-
end
|
18
|
-
|
19
|
-
def create_aggregate_folder
|
20
|
-
directory(options[:type].to_s, '.')
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def assignment_template(attributes)
|
26
|
-
AssignmentTemplate.new(attributes).render
|
27
|
-
end
|
28
|
-
|
29
|
-
def option_format(format, include_id: false)
|
30
|
-
OptionFormatter.new(options[:attributes]).call(format, include_id: include_id)
|
31
|
-
end
|
32
|
-
|
33
|
-
def head_name
|
34
|
-
options[:head_name]
|
35
|
-
end
|
36
|
-
|
37
|
-
def name
|
38
|
-
options[:name]
|
39
|
-
end
|
40
|
-
|
41
|
-
def file_name
|
42
|
-
name.underscore
|
43
|
-
end
|
44
|
-
|
45
|
-
def attribute_names_without_id
|
46
|
-
attributes_without_id.map(&:name)
|
47
|
-
end
|
48
|
-
|
49
|
-
def module_name
|
50
|
-
options[:module_name]
|
51
|
-
end
|
52
|
-
|
53
|
-
def domain_name
|
54
|
-
Dir.pwd.split('/').last
|
55
|
-
end
|
56
|
-
|
57
|
-
def attributes_without_id_as_string
|
58
|
-
attributes_without_id.map { |attribute| ':' + HecksDomainBuilder::Attribute.new(attribute).name }.join ', '
|
59
|
-
end
|
60
|
-
|
61
|
-
def attributes
|
62
|
-
options[:attributes] + ['id:integer']
|
63
|
-
end
|
64
|
-
|
65
|
-
def attributes_without_id
|
66
|
-
options[:attributes]
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|