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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 190e248050371c87592a293601aef341276718a2fac594564c34bb351ccf03b2
|
4
|
+
data.tar.gz: fdf5c867345ae5cfc47f57732a88e729e7209a4893c53d9ebf52b55e391ac1ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7f27ac2c55df2395eeccd421951b2ec3dc96f57781aa9eab22136a29ab303dccd9a23e4e883b1cd6b17983cbda222640d0738c65fcdaf4da49bc6a4d1de571b
|
7
|
+
data.tar.gz: e1cd143c164877eb341252e6f59e0c069dac56ef4682ca929f8c660667a4c51d04d079c12078f96e9367e713edf00d2335bd7553d83063c35a96dbba204b4013
|
@@ -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
|
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
|