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
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hecks
|
3
|
+
module Domain
|
4
|
+
module CLI
|
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| ':' + Hecks::Domain::DomainBuilder::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
|
71
|
+
end
|
data/lib/cli/new.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
load('Domain') if File.exist?('Domain')
|
3
|
+
module Hecks
|
4
|
+
module Domain
|
5
|
+
module CLI
|
6
|
+
class New < Thor::Group
|
7
|
+
namespace :hecks
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
class_option :nobuilder, aliases: '-n', desc: 'load schema from builder'
|
11
|
+
class_option :dry_run, aliases: '-d', desc: 'Use when specifying a schema file to output the commands, without running them'
|
12
|
+
|
13
|
+
def self.source_root
|
14
|
+
File.dirname(__FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_from_builder
|
18
|
+
return if options[:nobuilder]
|
19
|
+
CommandBuilder.new(
|
20
|
+
name: File.basename(Dir.getwd),
|
21
|
+
dry_run: !options[:dry_run].nil?
|
22
|
+
).call
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_hexagon_folder
|
26
|
+
return unless options[:nobuilder]
|
27
|
+
directory('templates/domain', ".")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def name
|
33
|
+
File.basename(Dir.getwd)
|
34
|
+
end
|
35
|
+
|
36
|
+
def module_name
|
37
|
+
name.camelize
|
38
|
+
end
|
39
|
+
|
40
|
+
def domain_module_name
|
41
|
+
domain_name.camelize
|
42
|
+
end
|
43
|
+
|
44
|
+
def condensed_module_name
|
45
|
+
name.delete('_')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module <%= domain_name.camelize %>
|
2
|
+
module Domain
|
3
|
+
module <%= name.camelize %>
|
4
|
+
class <%= options[:head_name].camelize %>
|
5
|
+
attr_accessor <%= option_format('attribute_string', include_id: true) %>
|
6
|
+
def initialize(<%= option_format('param_names', include_id: true) %>)
|
7
|
+
<%= assignment_template(attributes) %>
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_json
|
11
|
+
JSON.generate(<%= option_format('keys_and_values', include_id: true) %>)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module <%= domain_name.camelize %>
|
2
|
+
module Domain
|
3
|
+
module <%= name.camelize %>
|
4
|
+
class Repository
|
5
|
+
@collection = {}
|
6
|
+
@last_id = 0
|
7
|
+
|
8
|
+
def self.create attributes={}
|
9
|
+
id = @last_id + 1
|
10
|
+
@collection[id] = <%= options[:head_name].camelize %>.new(attributes.merge(id: id))
|
11
|
+
@last_id = id
|
12
|
+
Struct.new(:id).new(id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.update id, attributes
|
16
|
+
entity = read id
|
17
|
+
|
18
|
+
return unless entity
|
19
|
+
attributes.each do |field, value|
|
20
|
+
entity.send("#{field}=", value)
|
21
|
+
end
|
22
|
+
|
23
|
+
entity
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.read id
|
27
|
+
@collection[id]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.delete(id)
|
31
|
+
@collection.delete(id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.delete_all
|
35
|
+
@collection = {}
|
36
|
+
@last_id = 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = '<%= name %>'
|
3
|
+
s.homepage = ""
|
4
|
+
s.version = File.read('Version').gsub("\n", '')
|
5
|
+
s.date = '2016-09-12'
|
6
|
+
s.summary = "Summary"
|
7
|
+
s.description = "Description"
|
8
|
+
s.authors = ["Author"]
|
9
|
+
s.email = 'email@example.com'
|
10
|
+
s.files = Dir["lib/**/*"]
|
11
|
+
s.license = 'MIT'
|
12
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module <%= module_name %>
|
2
|
+
Dir[File.dirname(__FILE__) + "/domain/**/*.rb"].each {|file| require file}
|
3
|
+
|
4
|
+
def self.domain_modules
|
5
|
+
Domain.constants.map { |name| Domain.const_get(name)}
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.repositories
|
9
|
+
domain_modules.map do |domain_module|
|
10
|
+
[module_name(domain_module), domain_module.const_get(:Repository)]
|
11
|
+
end.to_h
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.module_name(domain_module)
|
15
|
+
domain_module.to_s.downcase.split("::").last.to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.spec_path
|
19
|
+
File.dirname(__FILE__) + '/../Domain'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module <%= domain_name.camelize %>
|
2
|
+
module Domain
|
3
|
+
module <%= module_name.camelize %>
|
4
|
+
class <%= name.camelize %>
|
5
|
+
attr_accessor :id, :referenced_entity
|
6
|
+
|
7
|
+
def self.factory(group_attributes)
|
8
|
+
return <%= name.camelize %>.new(group_attributes) unless group_attributes.is_a?(Array)
|
9
|
+
group_attributes.map do |attributes|
|
10
|
+
<%= name.camelize %>.new(attributes)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(id:)
|
15
|
+
@id = id
|
16
|
+
@referenced_entity = <%= options[:referenced_entity] %>
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json(config)
|
20
|
+
JSON.generate({id: @id, referenced_entity: @referenced_entity})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module <%= domain_name.camelize %>
|
2
|
+
module Domain
|
3
|
+
module <%= module_name.camelize %>
|
4
|
+
class <%= name.camelize %>
|
5
|
+
attr_accessor <%= attributes_without_id_as_string %>
|
6
|
+
|
7
|
+
def self.factory(group_attributes)
|
8
|
+
return <%= name.camelize %>.new(group_attributes) unless group_attributes.is_a?(Array)
|
9
|
+
group_attributes.map do |attributes|
|
10
|
+
<%= name.camelize %>.new(attributes)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(<%= option_format('param_names') %>)
|
15
|
+
<%= assignment_template(attributes_without_id) %>
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_json(config)
|
19
|
+
JSON.generate(<%= option_format('keys_and_values') %>)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
class DomainBuilder
|
4
|
+
class Attribute
|
5
|
+
attr_writer :type
|
6
|
+
attr_reader :object_name
|
7
|
+
|
8
|
+
def initialize(string)
|
9
|
+
@string = string
|
10
|
+
@object_name = object_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def list?
|
14
|
+
@string.include?("[")
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
@string.split(":").first
|
19
|
+
end
|
20
|
+
|
21
|
+
def type
|
22
|
+
return @type if @type
|
23
|
+
@string.split(":").last.delete("[").delete("]").camelize
|
24
|
+
end
|
25
|
+
|
26
|
+
def domain_module
|
27
|
+
return unless @string.include?("::")
|
28
|
+
@string.split("::").first.split(":").last.camelize
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy(new_values={})
|
32
|
+
result = self.class.new(@string)
|
33
|
+
result.type = new_values[:type] if new_values[:type]
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
def reference?
|
38
|
+
!primitive? && !list?
|
39
|
+
end
|
40
|
+
|
41
|
+
def referenced_object
|
42
|
+
return unless reference?
|
43
|
+
return @string.split("::").last if @string.include?("::")
|
44
|
+
@string.split(":").last
|
45
|
+
end
|
46
|
+
|
47
|
+
def primitive?
|
48
|
+
['String', 'Integer', 'Currency'].include?(type)
|
49
|
+
end
|
50
|
+
|
51
|
+
def ==(other)
|
52
|
+
return false if other.name != name
|
53
|
+
return false if other.type != type
|
54
|
+
return false if other.domain_module != domain_module
|
55
|
+
return true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
class DomainBuilder
|
4
|
+
class Domain
|
5
|
+
attr_reader :domain_modules, :name
|
6
|
+
def initialize(name:)
|
7
|
+
@name = name
|
8
|
+
@domain_modules = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def module(name, &block)
|
12
|
+
result = DomainModule.new(name: name)
|
13
|
+
@domain_modules[name.to_sym] = result
|
14
|
+
yield(result)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'attribute'
|
2
|
+
require_relative 'domain'
|
3
|
+
require_relative 'domain_module'
|
4
|
+
require_relative 'domain_object'
|
5
|
+
require_relative 'value'
|
6
|
+
require_relative 'head'
|
7
|
+
require_relative 'reference'
|
8
|
+
|
9
|
+
module Hecks
|
10
|
+
module Domain
|
11
|
+
class DomainBuilder
|
12
|
+
Types = { string: 'String', integer: 'Integer', currency: 'Currency'}
|
13
|
+
|
14
|
+
attr_accessor :domain, :specification, :name
|
15
|
+
|
16
|
+
def initialize(domain_name:, &block)
|
17
|
+
@name = domain_name
|
18
|
+
@domain = Domain.new(name: domain_name)
|
19
|
+
block.yield(@domain)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def domain_modules
|
24
|
+
@domain.domain_modules
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](module_name)
|
28
|
+
domain_modules[module_name]
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def self.build(domain_name, &block)
|
33
|
+
new(domain_name: domain_name, &block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
class DomainBuilder
|
4
|
+
class DomainModule
|
5
|
+
attr_reader :objects, :name, :references
|
6
|
+
|
7
|
+
def initialize(name:)
|
8
|
+
@name = name
|
9
|
+
@objects = []
|
10
|
+
@references = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def head(name=nil)
|
14
|
+
return (@objects << Head.new(name: name)).last if name
|
15
|
+
objects.find{ |o| o.is_a?(Head) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def value(name)
|
19
|
+
(@objects << Value.new(name: name)).last
|
20
|
+
end
|
21
|
+
|
22
|
+
def reference(name)
|
23
|
+
(@references << Reference.new(name)).last
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
class DomainBuilder
|
4
|
+
class DomainObject
|
5
|
+
attr_reader :name, :attributes
|
6
|
+
|
7
|
+
def initialize(name:)
|
8
|
+
@name = name
|
9
|
+
end
|
10
|
+
|
11
|
+
def attributes(*values)
|
12
|
+
return @attributes if @attributes
|
13
|
+
@attributes = values.map { |value| Hecks::Domain::DomainBuilder::Attribute.new(value) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def attribute_hash
|
17
|
+
attributes.map do |attribute|
|
18
|
+
[attribute.name.to_sym, type_with_domain_module(attribute)]
|
19
|
+
end.to_h
|
20
|
+
end
|
21
|
+
|
22
|
+
def attribute_string
|
23
|
+
attributes.map do |attribute|
|
24
|
+
[attribute.name, type_with_domain_module(attribute)].join(':')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def references
|
29
|
+
@attributes.reject(&:primitive?)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def type_with_domain_module(attribute)
|
35
|
+
type = DomainBuilder::Types.values.include?(attribute.type) ? "Value" : attribute.type
|
36
|
+
type = '[' + type + ']' if attribute.list?
|
37
|
+
return type unless attribute.domain_module
|
38
|
+
[attribute.domain_module, type].join("::")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Hecks
|
2
|
+
module Domain
|
3
|
+
class DomainBuilder
|
4
|
+
class Reference
|
5
|
+
def initialize(reference)
|
6
|
+
@reference = reference
|
7
|
+
end
|
8
|
+
|
9
|
+
def referenced_entity
|
10
|
+
@reference.split("::").map(&:camelcase).join("::")
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
@reference.split("::").last.camelcase + "Reference"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|