hecks-domain 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +5 -5
  2. data/lib/hecks/domain/commands/generate.rb +98 -0
  3. data/lib/hecks/domain/commands.rb +1 -0
  4. data/lib/hecks/domain/generators/domain.rb +21 -0
  5. data/lib/hecks/domain/generators/domain_files.rb +28 -0
  6. data/lib/hecks/domain/generators/entity.rb +30 -0
  7. data/lib/hecks/domain/generators/operation.rb +32 -0
  8. data/lib/hecks/domain/generators/root.rb +30 -0
  9. data/lib/hecks/domain/generators/spec.rb +30 -0
  10. data/lib/hecks/domain/generators/value_object.rb +30 -0
  11. data/lib/hecks/domain/generators.rb +7 -0
  12. data/lib/hecks/domain/parser/aggregate.rb +44 -0
  13. data/lib/hecks/domain/parser/domain_object.rb +123 -0
  14. data/lib/hecks/domain/parser/entity_field.rb +55 -0
  15. data/lib/hecks/domain/parser/fields.rb +16 -0
  16. data/lib/hecks/domain/parser/list_field.rb +13 -0
  17. data/lib/hecks/domain/parser/operation.rb +15 -0
  18. data/lib/hecks/domain/parser/reference_field.rb +12 -0
  19. data/lib/hecks/domain/parser/spec_helper.rb +0 -0
  20. data/lib/hecks/domain/parser/value_field.rb +48 -0
  21. data/lib/hecks/domain/parser.rb +95 -0
  22. data/lib/hecks/domain/support/string.rb +9 -0
  23. data/lib/hecks/domain/support.rb +1 -0
  24. data/lib/hecks/domain/templates/%domain_name%.gemspec.tt +12 -0
  25. data/lib/hecks/domain/templates/%folder_name%/Domainfile.tt +9 -0
  26. data/lib/hecks/domain/templates/%folder_name%/events/command_will_run.rb.tt +11 -0
  27. data/lib/hecks/domain/templates/%folder_name%/spec/spec_helper.rb.tt +1 -0
  28. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/commands.rb.tt +11 -0
  29. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/events.rb.tt +11 -0
  30. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +37 -0
  31. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories.rb.tt +11 -0
  32. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/invariants.rb.tt +11 -0
  33. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/queries.rb.tt +11 -0
  34. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/repository.rb.tt +68 -0
  35. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/subscribers.rb.tt +11 -0
  36. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%.rb.tt +34 -0
  37. data/lib/hecks/domain/templates/lib/%domain_name%.rb.tt +9 -0
  38. data/lib/hecks/domain/templates/lib/support/commands/command_loader.rb +18 -0
  39. data/lib/hecks/domain/templates/lib/support/commands/command_runner.rb +17 -0
  40. data/lib/hecks/domain/templates/lib/support/commands.rb +2 -0
  41. data/lib/hecks/domain/templates/lib/support/domain_object.rb +25 -0
  42. data/lib/hecks/domain/templates/lib/support/events/domain_event.rb +14 -0
  43. data/lib/hecks/domain/templates/lib/support/events/domain_event_publisher.rb +34 -0
  44. data/lib/hecks/domain/templates/lib/support/events.rb +14 -0
  45. data/lib/hecks/domain/templates/lib/support/factories/factory_loader.rb +21 -0
  46. data/lib/hecks/domain/templates/lib/support/factories.rb +1 -0
  47. data/lib/hecks/domain/templates/lib/support/invariants/invariant_loader.rb +24 -0
  48. data/lib/hecks/domain/templates/lib/support/queries/query_loader.rb +18 -0
  49. data/lib/hecks/domain/templates/lib/support/queries.rb +1 -0
  50. data/lib/hecks/domain/templates/lib/support/repositories/repository_loader.rb +32 -0
  51. data/lib/hecks/domain/templates/lib/support/root.rb +27 -0
  52. data/lib/hecks/domain/templates/lib/support/support/string.rb +9 -0
  53. data/lib/hecks/domain/templates/lib/support.rb +11 -0
  54. data/lib/hecks/domain/templates/operation/%aggregate_name%/%domain_object_name%/commands/%operation_name%.rb.tt +21 -0
  55. data/lib/hecks/domain/templates/root/%aggregate_name%/root.rb.tt +14 -0
  56. data/lib/hecks/domain/templates/spec/%aggregate_name%/%root_name%_spec.rb.tt +12 -0
  57. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +37 -0
  58. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories.rb.tt +11 -0
  59. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%.rb.tt +34 -0
  60. data/lib/hecks/domain/top_level_methods.rb +3 -0
  61. data/lib/hecks/domain.rb +22 -0
  62. metadata +101 -59
  63. data/lib/adapters/adapters.rb +0 -2
  64. data/lib/adapters/resource_server/cli/cli.rb +0 -1
  65. data/lib/adapters/resource_server/cli/generate_resource_server.rb +0 -25
  66. data/lib/adapters/resource_server/cli/templates/resource_server/config.ru.tt +0 -8
  67. data/lib/adapters/resource_server/resource_server.rb +0 -1
  68. data/lib/adapters/sql_database/cli/cli.rb +0 -3
  69. data/lib/adapters/sql_database/cli/generate_domain_migrations.rb +0 -33
  70. data/lib/adapters/sql_database/cli/generate_sql_database.rb +0 -35
  71. data/lib/adapters/sql_database/cli/migration_builder.rb +0 -51
  72. data/lib/adapters/sql_database/cli/templates/migration.rb.tt +0 -14
  73. data/lib/adapters/sql_database/cli/templates/repository.rb.tt +0 -24
  74. data/lib/adapters/sql_database/cli/templates/sql_database/Gemfile +0 -10
  75. data/lib/adapters/sql_database/cli/templates/sql_database/Rakefile +0 -15
  76. data/lib/adapters/sql_database/commands/read/fetch_references.rb +0 -58
  77. data/lib/adapters/sql_database/commands/update/delete_references.rb +0 -45
  78. data/lib/adapters/sql_database/commands/update/link_to_references.rb +0 -45
  79. data/lib/adapters/sql_database/sql_database.rb +0 -1
  80. data/lib/cli/builder/aggregate_command_line_builder.rb +0 -22
  81. data/lib/cli/builder/builder.rb +0 -3
  82. data/lib/cli/builder/reference_command_line_builder.rb +0 -23
  83. data/lib/cli/builder/value_object_command_line_builder.rb +0 -23
  84. data/lib/cli/cli.rb +0 -8
  85. data/lib/cli/command_builder.rb +0 -59
  86. data/lib/cli/domain_object/assignment_template.rb +0 -43
  87. data/lib/cli/domain_object/option_formatter.rb +0 -36
  88. data/lib/cli/generate_domain_object.rb +0 -71
  89. data/lib/cli/new.rb +0 -50
  90. data/lib/cli/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +0 -16
  91. data/lib/cli/templates/aggregate/lib/domain/%name%/%name%.rb.tt +0 -9
  92. data/lib/cli/templates/aggregate/lib/domain/%name%/repository.rb.tt +0 -41
  93. data/lib/cli/templates/domain/%name%.gemspec.tt +0 -12
  94. data/lib/cli/templates/domain/Version +0 -1
  95. data/lib/cli/templates/domain/lib/%name%.rb.tt +0 -21
  96. data/lib/cli/templates/domain/spec/spec_helper.rb.tt +0 -4
  97. data/lib/cli/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +0 -25
  98. data/lib/cli/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +0 -24
  99. data/lib/domain_builder/attribute.rb +0 -60
  100. data/lib/domain_builder/domain.rb +0 -19
  101. data/lib/domain_builder/domain_builder.rb +0 -37
  102. data/lib/domain_builder/domain_module.rb +0 -28
  103. data/lib/domain_builder/domain_object.rb +0 -43
  104. data/lib/domain_builder/head.rb +0 -8
  105. data/lib/domain_builder/reference.rb +0 -19
  106. data/lib/domain_builder/value.rb +0 -8
  107. data/lib/hecks-domain.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0e407c46ded01180a5c47b3b779aa5f193509002
4
- data.tar.gz: d36411b8e9533bc8a42d4e9c845ab61329fd05a7
2
+ SHA256:
3
+ metadata.gz: 641ebe21abe5d22ba77c1a288eef0340f10d5ba5b9117bb2f51656838621c77d
4
+ data.tar.gz: bb824dc6c678d341787569f799e8fa4207c14b0944acb8e36597fae027cbb726
5
5
  SHA512:
6
- metadata.gz: d89bcd8761dab08e36ca8cab1ea1d7e42cd63be5685d826bae3ca2b5d4e16ea007de15c00770111d900bf5bc69a9eb24c9e5517f77329a28c6b40588e1fd308f
7
- data.tar.gz: 852174b857cdbd06b0f5d68ee75f54d756988250163052ce9247a12f41c2b3fe2016f985c8863422dac157405483ae010846a6bc8877b87875f4bf71d5c22265
6
+ metadata.gz: dab60d9477a8dc4e2dc3ab3d3dedef7abe09817562e5d7b8a5183839121702612fad4cf5f1f2ad2c69d06b331b69ea59bcf2f34b5de87190bfe5f26b0828fdfb
7
+ data.tar.gz: f3a00dc69d10a0639b10d6f860e3e6775bc92d9342d0341ea07fce831ec56673270169905ee9d26c9e7b33de001f2738fc370cf0e7f13cd4a138b5818a2610f4
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ class HecksDomain
4
+ module Commands
5
+ # Generate a Domainfile
6
+ class Generate < Thor
7
+ package_name 'Hecks'
8
+ include Thor::Actions
9
+
10
+ HECKS_FILE_NAME = 'Domainfile'
11
+
12
+ def self.source_root
13
+ File.dirname(__FILE__) + '/../templates'
14
+ end
15
+
16
+ desc 'domain', 'Generate domain objects from a Domainfile'
17
+ method_option :skip_operations, default: true, type: :boolean
18
+ method_option :skip_spec_generation, default: true, type: :boolean
19
+ def domain_from_domain_file
20
+ generate_domain_objects(domain_get)
21
+ generate_domain_files(domain_get)
22
+ generate_roots(domain_get)
23
+ generate_operations(domain_get, options)
24
+ generate_specs(domain_get, options)
25
+ end
26
+
27
+ private
28
+
29
+ def generate_roots(domain)
30
+ domain.aggregates.each do |aggregate|
31
+ aggregate.domain_objects.each do |domain_object|
32
+ next unless domain_object.is_a?(HecksDomain::Parser::Root)
33
+
34
+ Generators::Root.new(
35
+ [domain, aggregate, domain_object]
36
+ ).invoke_all
37
+ end
38
+ end
39
+ end
40
+
41
+ def generate_specs(domain, options)
42
+ domain.for_each_domain_object do |aggregate, domain_object|
43
+ next unless domain_object.is_a?(HecksDomain::Parser::Root)
44
+
45
+ Generators::Spec.new(
46
+ [domain, aggregate, domain_object], options
47
+ ).invoke_all
48
+ end
49
+ end
50
+
51
+ def domain_get
52
+ instance_eval(domain_file).domain
53
+ end
54
+
55
+ def domain_file
56
+ return unless File.exist?(HECKS_FILE_NAME)
57
+
58
+ File.open(HECKS_FILE_NAME).read
59
+ end
60
+
61
+ def generate_domain_files(domain)
62
+ Generators::DomainFiles.new([domain]).invoke_all
63
+ end
64
+
65
+ def generate_operations(domain, options)
66
+ domain.for_each_operation do |aggregate, domain_object, operation|
67
+ Generators::Operation.new(
68
+ [domain, aggregate, domain_object, operation],
69
+ skip: options[:skip_operations]
70
+ ).invoke_all
71
+ end
72
+ end
73
+
74
+ def generate_domain_objects(domain)
75
+ domain.for_each_domain_object do |aggregate, domain_object|
76
+ generate_entity(domain, aggregate, domain_object)
77
+ generate_value_object(domain, aggregate, domain_object)
78
+ end
79
+ end
80
+
81
+ def generate_value_object(domain, aggregate, domain_object)
82
+ return unless domain_object.is_a?(HecksDomain::Parser::ValueObject)
83
+
84
+ Generators::ValueObject.new(
85
+ [domain, aggregate, domain_object]
86
+ ).invoke_all
87
+ end
88
+
89
+ def generate_entity(domain, aggregate, domain_object)
90
+ return unless domain_object.is_a?(HecksDomain::Parser::Entity)
91
+
92
+ Generators::Entity.new(
93
+ [domain, aggregate, domain_object]
94
+ ).invoke_all
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1 @@
1
+ require_relative 'commands/generate'
@@ -0,0 +1,21 @@
1
+ class HecksDomain
2
+ module Generators
3
+ class Domain < Thor::Group
4
+ include Thor::Actions
5
+
6
+ argument :domain_name, optional: true
7
+
8
+ def self.source_root
9
+ File.dirname(__FILE__) + '/../templates'
10
+ end
11
+
12
+ def folder_name
13
+ domain_name.underscore
14
+ end
15
+
16
+ def write_domain_directory
17
+ directory('%folder_name%')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ class HecksDomain
2
+ module Generators
3
+ class DomainFiles < Thor::Group
4
+ include Thor::Actions
5
+
6
+ attr_reader :domain_name, :domain, :gemspec
7
+
8
+ def initialize(args)
9
+ @domain = args.first
10
+ @gemspec = @domain.gemspec
11
+
12
+ @domain_name = @domain.name.to_s.underscore
13
+ super
14
+ end
15
+
16
+ argument :name
17
+
18
+ def self.source_root
19
+ File.dirname(__FILE__) + '/../templates'
20
+ end
21
+
22
+ def write_gemspec
23
+ template('%domain_name%.gemspec.tt')
24
+ directory('lib')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ class HecksDomain
2
+ module Generators
3
+ class Entity < Thor::Group
4
+ include Thor::Actions
5
+
6
+ attr_reader :aggregate_name, :domain_name, :domain_object_name, :domain, :aggregate, :domain_object
7
+
8
+ def initialize(args)
9
+ @domain = args[0]
10
+ @aggregate = args[1]
11
+ @domain_object = args[2]
12
+
13
+ @domain_name = @domain.name.to_s.underscore
14
+ @aggregate_name = @aggregate.name.to_s.underscore
15
+ @domain_object_name = @domain_object.name.to_s.underscore
16
+ super
17
+ end
18
+
19
+ argument :name
20
+
21
+ def self.source_root
22
+ File.dirname(__FILE__) + '/../templates'
23
+ end
24
+
25
+ def write_aggregate_directory
26
+ directory('entity', 'domain')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ class HecksDomain
2
+ module Generators
3
+ class Operation < Thor::Group
4
+ include Thor::Actions
5
+
6
+ attr_reader :aggregate_name, :domain_name, :operation_name, :domain_object_name, :domain, :aggregate, :domain_object, :operation
7
+
8
+ def initialize(args, options)
9
+ @domain = args[0]
10
+ @aggregate = args[1]
11
+ @domain_object = args[2]
12
+ @operation = args[3]
13
+
14
+ @domain_name = @domain.name.to_s.underscore
15
+ @aggregate_name = @aggregate.name.to_s.underscore
16
+ @domain_object_name = @domain_object.name.to_s.underscore
17
+ @operation_name = @operation.name.to_s.underscore
18
+ super(args, options)
19
+ end
20
+
21
+ argument :name
22
+
23
+ def self.source_root
24
+ File.dirname(__FILE__) + '/../templates'
25
+ end
26
+
27
+ def write_aggregate_directory
28
+ directory('operation', 'domain')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ class HecksDomain
2
+ module Generators
3
+ class Root < Thor::Group
4
+ include Thor::Actions
5
+
6
+ attr_reader :aggregate_name, :domain_name, :root_name, :domain, :aggregate, :root
7
+
8
+ def initialize(args)
9
+ @domain = args[0]
10
+ @aggregate = args[1]
11
+ @root = args[2]
12
+
13
+ @domain_name = @domain.name.to_s.underscore
14
+ @aggregate_name = @aggregate.name.to_s.underscore
15
+ @root_name = @root.name.to_s.underscore
16
+ super
17
+ end
18
+
19
+ argument :name
20
+
21
+ def self.source_root
22
+ File.dirname(__FILE__) + '/../templates'
23
+ end
24
+
25
+ def write_aggregate_directory
26
+ directory('root', 'domain')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ class HecksDomain
2
+ module Generators
3
+ class Spec < Thor::Group
4
+ include Thor::Actions
5
+
6
+ attr_reader :aggregate_name, :domain_name, :root_name, :domain, :aggregate, :root
7
+
8
+ def initialize(args, options)
9
+ @domain = args[0]
10
+ @aggregate = args[1]
11
+ @root = args[2]
12
+
13
+ @domain_name = @domain.name.to_s.underscore
14
+ @aggregate_name = @aggregate.name.to_s.underscore
15
+ @root_name = @root.name.to_s.underscore
16
+ super
17
+ end
18
+
19
+ argument :name
20
+
21
+ def self.source_root
22
+ File.dirname(__FILE__) + '/../templates'
23
+ end
24
+
25
+ def write_directory
26
+ directory('spec', skip: options[:skip_spec_generation])
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ class HecksDomain
2
+ module Generators
3
+ class ValueObject < Thor::Group
4
+ include Thor::Actions
5
+
6
+ attr_reader :aggregate_name, :domain_name, :domain_object_name, :domain, :aggregate, :domain_object
7
+
8
+ def initialize(args)
9
+ @domain = args[0]
10
+ @aggregate = args[1]
11
+ @domain_object = args[2]
12
+
13
+ @domain_name = @domain.name.to_s.underscore
14
+ @aggregate_name = @aggregate.name.to_s.underscore
15
+ @domain_object_name = @domain_object.name.to_s.underscore
16
+ super
17
+ end
18
+
19
+ argument :name
20
+
21
+ def self.source_root
22
+ File.dirname(__FILE__) + '/../templates'
23
+ end
24
+
25
+ def write_aggregate_directory
26
+ directory('value_object', 'domain')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'generators/domain'
2
+ require_relative 'generators/entity'
3
+ require_relative 'generators/root'
4
+ require_relative 'generators/value_object'
5
+ require_relative 'generators/operation'
6
+ require_relative 'generators/domain_files'
7
+ require_relative 'generators/spec'
@@ -0,0 +1,44 @@
1
+ class HecksDomain
2
+ class Parser
3
+ class Aggregate
4
+ attr_reader :domain, :name, :domain_objects
5
+
6
+ def initialize(name, domain, &block)
7
+ @name = name
8
+ @entities = []
9
+ @value_objects = []
10
+ @domain = domain
11
+ instance_eval(&block)
12
+ @domain_objects = @entities + @value_objects
13
+ end
14
+
15
+ def entity(name, &block)
16
+ Entity.new(name, self, &block).tap do |entity|
17
+ @entities << entity
18
+ end
19
+ end
20
+
21
+ def file_name
22
+ folder_name + '.rb'
23
+ end
24
+
25
+ def folder_name
26
+ name.to_s.underscore
27
+ end
28
+
29
+ def root(name, &block)
30
+ @root = Root.new(name, self, &block).tap do |root|
31
+ @entities << root
32
+ end
33
+ end
34
+
35
+ def value(name, &block)
36
+ @value_objects << ValueObject.new(name, self, &block)
37
+ end
38
+
39
+ def binding
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,123 @@
1
+ class HecksDomain
2
+ class Parser
3
+ class DomainObject
4
+ attr_reader :name, :aggregate, :fields
5
+
6
+ def initialize(name, aggregate, &block)
7
+ @name = name
8
+ @aggregate = aggregate
9
+ @operations = []
10
+ @fields = []
11
+ if is_a?(Entity)
12
+ add_field(:id, IntegerField).tap { |field| field.optional = true }
13
+ end
14
+ instance_eval(&block)
15
+ end
16
+
17
+ def optional(value)
18
+ value.optional = true
19
+ end
20
+
21
+ def initializer_attributes
22
+ @fields.reject(&:read_only?).map(&:attribute_name).join(', ')
23
+ end
24
+
25
+ def invariants
26
+ @invariants
27
+ end
28
+
29
+ def boolean_accessors
30
+ @fields.select { |field| field.is_a?(BooleanField) }
31
+ end
32
+
33
+ def list_accessors
34
+ @fields.select { |field| field.is_a?(ListField) }
35
+ end
36
+
37
+ def public_accessors
38
+ @fields.map do |field|
39
+ field.public_accessor
40
+ end.tap do |fields|
41
+ fields << ':id' if is_a?(Entity)
42
+ end.compact.join(', ')
43
+ end
44
+
45
+ def private_accessors
46
+ @fields.map do |field|
47
+ field.private_accessor
48
+ end.compact.join(', ')
49
+ end
50
+
51
+ def commands
52
+ @commands
53
+ end
54
+
55
+ def list(name)
56
+ add_field(name, ListField)
57
+ end
58
+
59
+ def string(name)
60
+ add_field(name, StringField)
61
+ end
62
+
63
+ def integer(name)
64
+ add_field(name, IntegerField)
65
+ end
66
+
67
+ def operations(list)
68
+ @operations = list
69
+
70
+ @operations = list.map do |name|
71
+ Operation.new(name: name, domain_object: self)
72
+ end
73
+ end
74
+
75
+ def operations_get
76
+ @operations
77
+ end
78
+
79
+ def currency(name)
80
+ add_field(name, CurrencyField)
81
+ end
82
+
83
+ def value(name)
84
+ add_field(name, ValueField)
85
+ end
86
+
87
+ def boolean(name)
88
+ add_field(name, BooleanField)
89
+ end
90
+
91
+ def entity(name)
92
+ add_field(name, EntityField)
93
+ end
94
+
95
+ def reference(name)
96
+ add_field(name, ReferenceField)
97
+ end
98
+
99
+ def file_name
100
+ folder_name + '.rb'
101
+ end
102
+
103
+ def folder_name
104
+ @name.to_s.underscore
105
+ end
106
+
107
+ def read_only(value)
108
+ value.read_only = true
109
+ value
110
+ end
111
+
112
+ def binding
113
+ super
114
+ end
115
+
116
+ private
117
+
118
+ def add_field(name, type)
119
+ type.new(name).tap { |field| @fields << field }
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,55 @@
1
+ class HecksDomain
2
+ class Parser
3
+ class EntityField
4
+ attr_reader :name
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+
10
+ def as(name)
11
+ @as = name
12
+ self
13
+ end
14
+
15
+ def module_name
16
+ @as
17
+ end
18
+
19
+ def public_accessor
20
+ ":#{name}"
21
+ end
22
+
23
+ def private_accessor
24
+ ":#{name}"
25
+ end
26
+
27
+ def initial_state
28
+ name
29
+ end
30
+
31
+ def read_only=(value)
32
+ @read_only = value
33
+ end
34
+
35
+ def optional=(value)
36
+ @optional = value
37
+ end
38
+
39
+ def read_only?
40
+ @read_only
41
+ end
42
+
43
+ def optional?
44
+ @optional
45
+ end
46
+
47
+ def attribute_name
48
+ return name.to_s + ':' unless optional?
49
+ return name.to_s + ': []' if is_a?(ListField)
50
+
51
+ name.to_s + ': nil'
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,16 @@
1
+ class HecksDomain
2
+ class Parser
3
+ class BooleanField < ValueField
4
+ def initial_state
5
+ return 'nil' if read_only?
6
+ name
7
+ end
8
+ end
9
+ class Entity < DomainObject;end
10
+ class Root < Entity;end
11
+ class ValueObject < DomainObject;end
12
+ class StringField < ValueField;end
13
+ class IntegerField < ValueField;end
14
+ class CurrencyField < ValueField;end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ class HecksDomain
2
+ class Parser
3
+ class ListField < EntityField
4
+ def initial_state
5
+ return '[]' if read_only?
6
+
7
+ name
8
+ end
9
+
10
+ def public_accessor; end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class HecksDomain
2
+ class Parser
3
+ class Operation
4
+ attr_reader :name
5
+ def initialize(name:, domain_object:)
6
+ @name = name
7
+ @domain_object = domain_object
8
+ end
9
+
10
+ def binding
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ class HecksDomain
2
+ class Parser
3
+ class ReferenceField
4
+ class ReferenceField < EntityField
5
+ attr_reader :name
6
+ def module_name
7
+ @as.keys.first.to_s + '::' + @as.values.first.to_s
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
File without changes
@@ -0,0 +1,48 @@
1
+ class HecksDomain
2
+ class Parser
3
+ class ValueField
4
+ attr_reader :name
5
+ attr_writer :optional
6
+ attr_writer :read_only
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ end
11
+
12
+ def optional?
13
+ @optional
14
+ end
15
+
16
+ def initial_state
17
+ name
18
+ end
19
+
20
+ def attribute_name
21
+ return name.to_s + ':' unless optional?
22
+
23
+ name.to_s + ': nil'
24
+ end
25
+
26
+ def public_accessor
27
+ ":#{name}"
28
+ end
29
+
30
+ def private_accessor
31
+ ":#{name}"
32
+ end
33
+
34
+ def module_name
35
+ @as
36
+ end
37
+
38
+ def read_only?
39
+ @read_only
40
+ end
41
+
42
+ def as(name)
43
+ @as = name
44
+ self
45
+ end
46
+ end
47
+ end
48
+ end