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.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/lib/adapters/adapters.rb +2 -0
  3. data/lib/adapters/resource_server/cli/cli.rb +1 -0
  4. data/lib/adapters/resource_server/cli/generate_resource_server.rb +25 -0
  5. data/lib/adapters/resource_server/cli/templates/resource_server/config.ru.tt +8 -0
  6. data/lib/adapters/resource_server/resource_server.rb +3 -0
  7. data/lib/adapters/sql_database/cli/cli.rb +3 -0
  8. data/lib/adapters/sql_database/cli/generate_domain_migrations.rb +33 -0
  9. data/lib/adapters/sql_database/cli/generate_sql_database.rb +35 -0
  10. data/lib/adapters/sql_database/cli/migration_builder.rb +51 -0
  11. data/lib/adapters/sql_database/cli/templates/migration.rb.tt +14 -0
  12. data/lib/adapters/sql_database/cli/templates/repository.rb.tt +24 -0
  13. data/lib/adapters/sql_database/cli/templates/sql_database/Rakefile +15 -0
  14. data/lib/adapters/sql_database/commands/read/fetch_references.rb +58 -0
  15. data/lib/adapters/sql_database/commands/update/delete_references.rb +45 -0
  16. data/lib/adapters/sql_database/commands/update/link_to_references.rb +45 -0
  17. data/lib/adapters/sql_database/sql_database.rb +1 -0
  18. data/lib/cli/builder/aggregate_command_line_builder.rb +22 -0
  19. data/lib/cli/builder/builder.rb +3 -0
  20. data/lib/cli/builder/reference_command_line_builder.rb +23 -0
  21. data/lib/cli/builder/value_object_command_line_builder.rb +23 -0
  22. data/lib/cli/cli.rb +8 -0
  23. data/lib/cli/command_builder.rb +60 -0
  24. data/lib/cli/domain_object/assignment_template.rb +43 -0
  25. data/lib/cli/domain_object/option_formatter.rb +36 -0
  26. data/lib/cli/generate_domain_object.rb +71 -0
  27. data/lib/cli/new.rb +50 -0
  28. data/lib/cli/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +16 -0
  29. data/lib/cli/templates/aggregate/lib/domain/%name%/%name%.rb.tt +9 -0
  30. data/lib/cli/templates/aggregate/lib/domain/%name%/repository.rb.tt +41 -0
  31. data/lib/cli/templates/domain/%name%.gemspec.tt +12 -0
  32. data/lib/cli/templates/domain/Version +1 -0
  33. data/lib/cli/templates/domain/lib/%name%.rb.tt +21 -0
  34. data/lib/cli/templates/domain/spec/spec_helper.rb.tt +4 -0
  35. data/lib/cli/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +25 -0
  36. data/lib/cli/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +24 -0
  37. data/lib/domain_builder/attribute.rb +60 -0
  38. data/lib/domain_builder/domain.rb +19 -0
  39. data/lib/domain_builder/domain_builder.rb +37 -0
  40. data/lib/domain_builder/domain_module.rb +28 -0
  41. data/lib/domain_builder/domain_object.rb +43 -0
  42. data/lib/domain_builder/head.rb +8 -0
  43. data/lib/domain_builder/reference.rb +19 -0
  44. data/lib/domain_builder/value.rb +8 -0
  45. data/lib/hecks-domain.rb +6 -0
  46. metadata +58 -101
  47. data/lib/hecks/domain/commands/generate.rb +0 -98
  48. data/lib/hecks/domain/commands.rb +0 -1
  49. data/lib/hecks/domain/generators/domain.rb +0 -21
  50. data/lib/hecks/domain/generators/domain_files.rb +0 -28
  51. data/lib/hecks/domain/generators/entity.rb +0 -30
  52. data/lib/hecks/domain/generators/operation.rb +0 -32
  53. data/lib/hecks/domain/generators/root.rb +0 -30
  54. data/lib/hecks/domain/generators/spec.rb +0 -30
  55. data/lib/hecks/domain/generators/value_object.rb +0 -30
  56. data/lib/hecks/domain/generators.rb +0 -7
  57. data/lib/hecks/domain/parser/aggregate.rb +0 -44
  58. data/lib/hecks/domain/parser/domain_object.rb +0 -123
  59. data/lib/hecks/domain/parser/entity_field.rb +0 -55
  60. data/lib/hecks/domain/parser/fields.rb +0 -16
  61. data/lib/hecks/domain/parser/list_field.rb +0 -13
  62. data/lib/hecks/domain/parser/operation.rb +0 -15
  63. data/lib/hecks/domain/parser/reference_field.rb +0 -12
  64. data/lib/hecks/domain/parser/spec_helper.rb +0 -0
  65. data/lib/hecks/domain/parser/value_field.rb +0 -48
  66. data/lib/hecks/domain/parser.rb +0 -95
  67. data/lib/hecks/domain/support/string.rb +0 -9
  68. data/lib/hecks/domain/support.rb +0 -1
  69. data/lib/hecks/domain/templates/%domain_name%.gemspec.tt +0 -12
  70. data/lib/hecks/domain/templates/%folder_name%/Domainfile.tt +0 -9
  71. data/lib/hecks/domain/templates/%folder_name%/events/command_will_run.rb.tt +0 -11
  72. data/lib/hecks/domain/templates/%folder_name%/spec/spec_helper.rb.tt +0 -1
  73. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/commands.rb.tt +0 -11
  74. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/events.rb.tt +0 -11
  75. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +0 -37
  76. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories.rb.tt +0 -11
  77. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/invariants.rb.tt +0 -11
  78. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/queries.rb.tt +0 -11
  79. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/repository.rb.tt +0 -68
  80. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/subscribers.rb.tt +0 -11
  81. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%.rb.tt +0 -34
  82. data/lib/hecks/domain/templates/lib/%domain_name%.rb.tt +0 -9
  83. data/lib/hecks/domain/templates/lib/support/commands/command_loader.rb +0 -18
  84. data/lib/hecks/domain/templates/lib/support/commands/command_runner.rb +0 -17
  85. data/lib/hecks/domain/templates/lib/support/commands.rb +0 -2
  86. data/lib/hecks/domain/templates/lib/support/domain_object.rb +0 -25
  87. data/lib/hecks/domain/templates/lib/support/events/domain_event.rb +0 -14
  88. data/lib/hecks/domain/templates/lib/support/events/domain_event_publisher.rb +0 -34
  89. data/lib/hecks/domain/templates/lib/support/events.rb +0 -14
  90. data/lib/hecks/domain/templates/lib/support/factories/factory_loader.rb +0 -21
  91. data/lib/hecks/domain/templates/lib/support/factories.rb +0 -1
  92. data/lib/hecks/domain/templates/lib/support/invariants/invariant_loader.rb +0 -24
  93. data/lib/hecks/domain/templates/lib/support/queries/query_loader.rb +0 -18
  94. data/lib/hecks/domain/templates/lib/support/queries.rb +0 -1
  95. data/lib/hecks/domain/templates/lib/support/repositories/repository_loader.rb +0 -32
  96. data/lib/hecks/domain/templates/lib/support/root.rb +0 -27
  97. data/lib/hecks/domain/templates/lib/support/support/string.rb +0 -9
  98. data/lib/hecks/domain/templates/lib/support.rb +0 -11
  99. data/lib/hecks/domain/templates/operation/%aggregate_name%/%domain_object_name%/commands/%operation_name%.rb.tt +0 -21
  100. data/lib/hecks/domain/templates/root/%aggregate_name%/root.rb.tt +0 -14
  101. data/lib/hecks/domain/templates/spec/%aggregate_name%/%root_name%_spec.rb.tt +0 -12
  102. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +0 -37
  103. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories.rb.tt +0 -11
  104. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%.rb.tt +0 -34
  105. data/lib/hecks/domain/top_level_methods.rb +0 -3
  106. data/lib/hecks/domain.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 641ebe21abe5d22ba77c1a288eef0340f10d5ba5b9117bb2f51656838621c77d
4
- data.tar.gz: bb824dc6c678d341787569f799e8fa4207c14b0944acb8e36597fae027cbb726
2
+ SHA1:
3
+ metadata.gz: a536bc9f2ac7b7d13f4635b662fb30fc2eba0ed8
4
+ data.tar.gz: 456828d3dd5ca5059518fa424da1b8cacc475f02
5
5
  SHA512:
6
- metadata.gz: dab60d9477a8dc4e2dc3ab3d3dedef7abe09817562e5d7b8a5183839121702612fad4cf5f1f2ad2c69d06b331b69ea59bcf2f34b5de87190bfe5f26b0828fdfb
7
- data.tar.gz: f3a00dc69d10a0639b10d6f860e3e6775bc92d9342d0341ea07fce831ec56673270169905ee9d26c9e7b33de001f2738fc370cf0e7f13cd4a138b5818a2610f4
6
+ metadata.gz: fbdccc798e4c10cebcff60b8e8080988026d28a57957fd05c56c0e1663095fcd3a7221d108f5453dc9e86864a9fbee0a9c1c591aff19fe8adf272f53caa18b4f
7
+ data.tar.gz: fe556a16948d109242f5d7e04f54bff10fa8a1426ca9ff57d33149b049dca7c6ea5c0fadbbf98c60eed511464e41ac2d4cb1b47134340c77bb76895137f0376a
@@ -0,0 +1,2 @@
1
+ require_relative 'sql_database/sql_database'
2
+ require_relative 'resource_server/resource_server'
@@ -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,8 @@
1
+ require_relative "lib/<%= domain %>.rb"
2
+ require 'hecks'
3
+
4
+ run Hecks::Adapters::ResourceServer.new(
5
+ application_adapter: Hecks::Application.new(
6
+ domain: <%= domain.camelize %>
7
+ )
8
+ )
@@ -0,0 +1,3 @@
1
+ require_relative 'cli/cli'
2
+ module Hecks
3
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'generate_domain_migrations'
2
+ require_relative 'generate_sql_database'
3
+ require_relative 'migration_builder'
@@ -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,3 @@
1
+ require_relative 'value_object_command_line_builder'
2
+ require_relative 'aggregate_command_line_builder'
3
+ require_relative 'reference_command_line_builder'
@@ -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