hecks-domain 0.1.0 → 0.1.2.rc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/adapters/adapters.rb +2 -0
- data/lib/adapters/resource_server/cli/cli.rb +1 -0
- data/lib/adapters/resource_server/cli/generate_resource_server.rb +25 -0
- data/lib/adapters/resource_server/cli/templates/resource_server/config.ru.tt +8 -0
- data/lib/adapters/resource_server/resource_server.rb +3 -0
- data/lib/adapters/sql_database/cli/cli.rb +3 -0
- data/lib/adapters/sql_database/cli/generate_domain_migrations.rb +33 -0
- data/lib/adapters/sql_database/cli/generate_sql_database.rb +35 -0
- data/lib/adapters/sql_database/cli/migration_builder.rb +51 -0
- data/lib/adapters/sql_database/cli/templates/migration.rb.tt +14 -0
- data/lib/adapters/sql_database/cli/templates/repository.rb.tt +24 -0
- data/lib/adapters/sql_database/cli/templates/sql_database/Rakefile +15 -0
- data/lib/adapters/sql_database/commands/read/fetch_references.rb +58 -0
- data/lib/adapters/sql_database/commands/update/delete_references.rb +45 -0
- data/lib/adapters/sql_database/commands/update/link_to_references.rb +45 -0
- data/lib/adapters/sql_database/sql_database.rb +1 -0
- data/lib/cli/builder/aggregate_command_line_builder.rb +22 -0
- data/lib/cli/builder/builder.rb +3 -0
- data/lib/cli/builder/reference_command_line_builder.rb +23 -0
- data/lib/cli/builder/value_object_command_line_builder.rb +23 -0
- data/lib/cli/cli.rb +8 -0
- data/lib/cli/command_builder.rb +60 -0
- data/lib/cli/domain_object/assignment_template.rb +43 -0
- data/lib/cli/domain_object/option_formatter.rb +36 -0
- data/lib/cli/generate_domain_object.rb +71 -0
- data/lib/cli/new.rb +50 -0
- data/lib/cli/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +16 -0
- data/lib/cli/templates/aggregate/lib/domain/%name%/%name%.rb.tt +9 -0
- data/lib/cli/templates/aggregate/lib/domain/%name%/repository.rb.tt +41 -0
- data/lib/cli/templates/domain/%name%.gemspec.tt +12 -0
- data/lib/cli/templates/domain/Version +1 -0
- data/lib/cli/templates/domain/lib/%name%.rb.tt +21 -0
- data/lib/cli/templates/domain/spec/spec_helper.rb.tt +4 -0
- data/lib/cli/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +25 -0
- data/lib/cli/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +24 -0
- data/lib/domain_builder/attribute.rb +60 -0
- data/lib/domain_builder/domain.rb +19 -0
- data/lib/domain_builder/domain_builder.rb +37 -0
- data/lib/domain_builder/domain_module.rb +28 -0
- data/lib/domain_builder/domain_object.rb +43 -0
- data/lib/domain_builder/head.rb +8 -0
- data/lib/domain_builder/reference.rb +19 -0
- data/lib/domain_builder/value.rb +8 -0
- data/lib/hecks-domain.rb +6 -0
- metadata +58 -101
- data/lib/hecks/domain/commands/generate.rb +0 -98
- data/lib/hecks/domain/commands.rb +0 -1
- data/lib/hecks/domain/generators/domain.rb +0 -21
- data/lib/hecks/domain/generators/domain_files.rb +0 -28
- data/lib/hecks/domain/generators/entity.rb +0 -30
- data/lib/hecks/domain/generators/operation.rb +0 -32
- data/lib/hecks/domain/generators/root.rb +0 -30
- data/lib/hecks/domain/generators/spec.rb +0 -30
- data/lib/hecks/domain/generators/value_object.rb +0 -30
- data/lib/hecks/domain/generators.rb +0 -7
- data/lib/hecks/domain/parser/aggregate.rb +0 -44
- data/lib/hecks/domain/parser/domain_object.rb +0 -123
- data/lib/hecks/domain/parser/entity_field.rb +0 -55
- data/lib/hecks/domain/parser/fields.rb +0 -16
- data/lib/hecks/domain/parser/list_field.rb +0 -13
- data/lib/hecks/domain/parser/operation.rb +0 -15
- data/lib/hecks/domain/parser/reference_field.rb +0 -12
- data/lib/hecks/domain/parser/spec_helper.rb +0 -0
- data/lib/hecks/domain/parser/value_field.rb +0 -48
- data/lib/hecks/domain/parser.rb +0 -95
- data/lib/hecks/domain/support/string.rb +0 -9
- data/lib/hecks/domain/support.rb +0 -1
- data/lib/hecks/domain/templates/%domain_name%.gemspec.tt +0 -12
- data/lib/hecks/domain/templates/%folder_name%/Domainfile.tt +0 -9
- data/lib/hecks/domain/templates/%folder_name%/events/command_will_run.rb.tt +0 -11
- data/lib/hecks/domain/templates/%folder_name%/spec/spec_helper.rb.tt +0 -1
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/commands.rb.tt +0 -11
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/events.rb.tt +0 -11
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +0 -37
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories.rb.tt +0 -11
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/invariants.rb.tt +0 -11
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/queries.rb.tt +0 -11
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/repository.rb.tt +0 -68
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/subscribers.rb.tt +0 -11
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%.rb.tt +0 -34
- data/lib/hecks/domain/templates/lib/%domain_name%.rb.tt +0 -9
- data/lib/hecks/domain/templates/lib/support/commands/command_loader.rb +0 -18
- data/lib/hecks/domain/templates/lib/support/commands/command_runner.rb +0 -17
- data/lib/hecks/domain/templates/lib/support/commands.rb +0 -2
- data/lib/hecks/domain/templates/lib/support/domain_object.rb +0 -25
- data/lib/hecks/domain/templates/lib/support/events/domain_event.rb +0 -14
- data/lib/hecks/domain/templates/lib/support/events/domain_event_publisher.rb +0 -34
- data/lib/hecks/domain/templates/lib/support/events.rb +0 -14
- data/lib/hecks/domain/templates/lib/support/factories/factory_loader.rb +0 -21
- data/lib/hecks/domain/templates/lib/support/factories.rb +0 -1
- data/lib/hecks/domain/templates/lib/support/invariants/invariant_loader.rb +0 -24
- data/lib/hecks/domain/templates/lib/support/queries/query_loader.rb +0 -18
- data/lib/hecks/domain/templates/lib/support/queries.rb +0 -1
- data/lib/hecks/domain/templates/lib/support/repositories/repository_loader.rb +0 -32
- data/lib/hecks/domain/templates/lib/support/root.rb +0 -27
- data/lib/hecks/domain/templates/lib/support/support/string.rb +0 -9
- data/lib/hecks/domain/templates/lib/support.rb +0 -11
- data/lib/hecks/domain/templates/operation/%aggregate_name%/%domain_object_name%/commands/%operation_name%.rb.tt +0 -21
- data/lib/hecks/domain/templates/root/%aggregate_name%/root.rb.tt +0 -14
- data/lib/hecks/domain/templates/spec/%aggregate_name%/%root_name%_spec.rb.tt +0 -12
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +0 -37
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories.rb.tt +0 -11
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%.rb.tt +0 -34
- data/lib/hecks/domain/top_level_methods.rb +0 -3
- data/lib/hecks/domain.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a536bc9f2ac7b7d13f4635b662fb30fc2eba0ed8
|
4
|
+
data.tar.gz: 456828d3dd5ca5059518fa424da1b8cacc475f02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbdccc798e4c10cebcff60b8e8080988026d28a57957fd05c56c0e1663095fcd3a7221d108f5453dc9e86864a9fbee0a9c1c591aff19fe8adf272f53caa18b4f
|
7
|
+
data.tar.gz: fe556a16948d109242f5d7e04f54bff10fa8a1426ca9ff57d33149b049dca7c6ea5c0fadbbf98c60eed511464e41ac2d4cb1b47134340c77bb76895137f0376a
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'generate_resource_server'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module Adapters
|
4
|
+
module ResourceServer
|
5
|
+
module CLI
|
6
|
+
class GenerateResourceServer < Thor::Group
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.dirname(__FILE__) + '/templates/'
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_aggregate_folder
|
14
|
+
directory('resource_server', '.')
|
15
|
+
end
|
16
|
+
|
17
|
+
def domain
|
18
|
+
File.basename(Dir.getwd)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module Adapters
|
4
|
+
class SQLDatabase
|
5
|
+
module CLI
|
6
|
+
class GenerateDomainMigrations < Thor::Group
|
7
|
+
include Thor::Actions
|
8
|
+
attr_writer :migration_builder
|
9
|
+
|
10
|
+
def load_domain_spec
|
11
|
+
load('../../Domain')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.source_root
|
15
|
+
File.dirname(__FILE__) + '/templates/'
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_migration_file
|
19
|
+
@migration_builder = MigrationBuilder.new(self, DOMAIN)
|
20
|
+
@migration_builder.call
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def migration_builder
|
26
|
+
@migration_builder
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module Adapters
|
4
|
+
class SQLDatabase
|
5
|
+
module CLI
|
6
|
+
class GenerateSQLDatabase < Thor::Group
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.dirname(__FILE__) + '/templates/'
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_sql_database_folder
|
14
|
+
directory('sql_database', './adapters/sql_database')
|
15
|
+
end
|
16
|
+
|
17
|
+
def bundle
|
18
|
+
run 'bundle'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def class_name
|
24
|
+
@class_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def domain_module_name
|
28
|
+
DOMAIN.name.camelize
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module Adapters
|
4
|
+
class SQLDatabase
|
5
|
+
module CLI
|
6
|
+
class MigrationBuilder
|
7
|
+
def initialize(generator, specification)
|
8
|
+
@generator = generator
|
9
|
+
@schema = Hecks::Adapters::SQLDatabase::Schema.factory(specification)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
generate_migrations
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def table_name
|
18
|
+
@table.name
|
19
|
+
end
|
20
|
+
|
21
|
+
def columns
|
22
|
+
@table.columns
|
23
|
+
end
|
24
|
+
|
25
|
+
def tables
|
26
|
+
@schema.tables
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :generator
|
32
|
+
|
33
|
+
def file_name(index, object)
|
34
|
+
"#{index}_create_#{table_name}.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_migrations
|
38
|
+
tables.each.with_index(1) do |table, index|
|
39
|
+
@table = table
|
40
|
+
@generator.template(
|
41
|
+
"migration.rb.tt",
|
42
|
+
"db/migrate/" + file_name(index, table)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
create_table(:<%= migration_builder.table_name %>) do
|
4
|
+
primary_key :id
|
5
|
+
<%- migration_builder.columns.each do |column| -%>
|
6
|
+
<%= column.type.camelcase %> :<%= column.name.to_sym %>, :null=>false
|
7
|
+
<%- end -%>
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
down do
|
12
|
+
drop_table(:<%= migration_builder.table_name %>)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module <%= domain_module_name %>
|
2
|
+
module Adapters
|
3
|
+
class SQLDatabase
|
4
|
+
module Repositories
|
5
|
+
class <%= class_name %>
|
6
|
+
def self.create attributes = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.update id, attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.read id
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.delete id
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.delete_all
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
namespace :db do
|
2
|
+
desc "Run migrations"
|
3
|
+
task :migrate, [:version] do |t, args|
|
4
|
+
require "sequel"
|
5
|
+
Sequel.extension :migration
|
6
|
+
db = Sequel.connect(ENV.fetch("DATABASE_URL"))
|
7
|
+
if args[:version]
|
8
|
+
puts "Migrating to version #{args[:version]}"
|
9
|
+
Sequel::Migrator.run(db, "db/migrate", target: args[:version].to_i)
|
10
|
+
else
|
11
|
+
puts "Migrating to latest"
|
12
|
+
Sequel::Migrator.run(db, "db/migrate")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module Adapters
|
4
|
+
class SQLDatabase
|
5
|
+
module Commands
|
6
|
+
class Read
|
7
|
+
class FetchReferences
|
8
|
+
attr_reader :reference_map
|
9
|
+
def initialize(read_command)
|
10
|
+
@head = read_command.head
|
11
|
+
@reference_map = {}
|
12
|
+
@entity = read_command.entity
|
13
|
+
@table = read_command.table
|
14
|
+
@id = read_command.id
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
@head.references.each do |reference|
|
19
|
+
fetch_reference(reference)
|
20
|
+
fetch_references(reference)
|
21
|
+
end
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def fetch_reference(reference)
|
28
|
+
return if reference.list?
|
29
|
+
column = Column.factory(reference)
|
30
|
+
value = DB[column.to_table_name].first(id: @entity[column.to_foreign_key])
|
31
|
+
|
32
|
+
@entity.delete(column.to_foreign_key)
|
33
|
+
value.delete(:id)
|
34
|
+
@reference_map[column.name.to_sym] = value
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch_references(reference)
|
38
|
+
return unless reference.list?
|
39
|
+
|
40
|
+
where_clause = {}
|
41
|
+
where_clause[@table.to_foreign_key.to_sym] = @id
|
42
|
+
column = Column.factory(reference)
|
43
|
+
|
44
|
+
@reference_map[column.name.to_sym] ||= []
|
45
|
+
|
46
|
+
DB[JoinTable(@table, reference).name.to_sym].where(where_clause).map do |record|
|
47
|
+
value_object = DB[column.to_table_name].first(id: record[column.to_foreign_key])
|
48
|
+
value_object.delete(:id)
|
49
|
+
@reference_map[column.name.to_sym] << value_object
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module Adapters
|
4
|
+
class SQLDatabase
|
5
|
+
module Commands
|
6
|
+
class Update
|
7
|
+
class DeleteReferences
|
8
|
+
attr_reader :attributes
|
9
|
+
|
10
|
+
def initialize(table:, attributes:, reference:)
|
11
|
+
@table = table
|
12
|
+
@attributes = attributes
|
13
|
+
@reference = reference
|
14
|
+
@where_clause = {}
|
15
|
+
@dataset = DB[JoinTable.new(@table, @reference).name.to_sym]
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
build_where_clause
|
20
|
+
delete_references
|
21
|
+
remove_references_from_attributes
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_where_clause
|
28
|
+
DB[JoinTable.new(@table, @reference).name.to_sym]
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_references_from_attributes
|
32
|
+
@attributes.delete(@reference.name.to_sym)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_references
|
36
|
+
return unless @reference.list?
|
37
|
+
@dataset.where(@where_clause).delete
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module Adapters
|
4
|
+
class SQLDatabase
|
5
|
+
module Commands
|
6
|
+
class Update
|
7
|
+
class LinkToReferences
|
8
|
+
attr_reader :reference_ids
|
9
|
+
def initialize(reference:, table:, reference_ids:, attributes:)
|
10
|
+
@reference = reference
|
11
|
+
@reference_ids = reference_ids
|
12
|
+
@table = table
|
13
|
+
@attributes = attributes
|
14
|
+
@column = Column.factory(@reference)
|
15
|
+
@record = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
make_linking_records
|
20
|
+
make_foreign_keys
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def make_linking_records
|
27
|
+
return unless @reference.list?
|
28
|
+
@reference_ids[@reference.name.to_sym].each do |value|
|
29
|
+
@record[@column.to_foreign_key] = value
|
30
|
+
@record[@table.to_foreign_key] = @attributes[:id]
|
31
|
+
DB[JoinTable.new(@table, @reference).name.to_sym].insert(@record)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def make_foreign_keys
|
36
|
+
return if @reference.list?
|
37
|
+
@attributes[@column.to_foreign_key] = @reference_ids[@reference.name]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'cli/cli'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module CLI
|
4
|
+
class CommandBuilder
|
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
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module CLI
|
4
|
+
class CommandBuilder
|
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
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module CLI
|
4
|
+
class CommandBuilder
|
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
|
23
|
+
end
|
data/lib/cli/cli.rb
ADDED
@@ -0,0 +1,8 @@
|
|
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"
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Hecks
|
5
|
+
module Domain
|
6
|
+
module CLI
|
7
|
+
class CommandBuilder
|
8
|
+
def initialize(name:, dry_run: false)
|
9
|
+
@name = name
|
10
|
+
@domain = DOMAIN
|
11
|
+
@dry_run = dry_run
|
12
|
+
@runner = CommandRunner.new(domain, name, dry_run)
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
delete_tmpfile
|
17
|
+
puts "\n"
|
18
|
+
generate :domain
|
19
|
+
generate :modules
|
20
|
+
generate :value_objects
|
21
|
+
generate :references
|
22
|
+
execute_tmpfile && return unless @dry_run
|
23
|
+
print_tmpfile
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :runner, :name, :domain
|
29
|
+
|
30
|
+
def print_tmpfile
|
31
|
+
puts File.read('tmp/hecks')
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_tmpfile
|
35
|
+
return unless Pathname('tmp/hecks').exist?
|
36
|
+
FileUtils.rm('tmp/hecks')
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute_tmpfile
|
40
|
+
exec('bash -x tmp/hecks')
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate(command)
|
44
|
+
case command
|
45
|
+
when :references
|
46
|
+
ReferenceCommandLineBuilder.build(domain, runner)
|
47
|
+
when :domain
|
48
|
+
runner.call(['new', '-n', name])
|
49
|
+
when :modules
|
50
|
+
AggregateCommandLineBuilder.build(domain, runner)
|
51
|
+
when :value_objects
|
52
|
+
ValueObjectCommandLineBuilder.build(domain, runner)
|
53
|
+
else
|
54
|
+
raise "unrecognized command: #{command}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module CLI
|
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 = Hecks::Domain::DomainBuilder::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 Hecks::Domain::DomainBuilder::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
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
module CLI
|
4
|
+
class GenerateDomainObject
|
5
|
+
class OptionFormatter
|
6
|
+
def initialize(attributes)
|
7
|
+
@attributes = attributes.map do |attribute|
|
8
|
+
Hecks::Domain::DomainBuilder::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 + [Hecks::Domain::DomainBuilder::Attribute.new('id:value')]
|
28
|
+
else
|
29
|
+
@attributes
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|