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
data/lib/cli/new.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module HecksDomain
|
4
|
-
module CLI
|
5
|
-
# Generate a new domain project
|
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
|
@@ -1,16 +0,0 @@
|
|
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
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module <%= domain_name.camelize %>
|
2
|
-
module Domain
|
3
|
-
module <%= name.camelize %>
|
4
|
-
class Repository
|
5
|
-
@collection = {}
|
6
|
-
|
7
|
-
def self.create attributes={}
|
8
|
-
id = attributes[:id]
|
9
|
-
@collection[id] = <%= options[:head_name].camelize %>.new(attributes)
|
10
|
-
Struct.new(:id).new(id)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.update id, attributes
|
14
|
-
entity = read id
|
15
|
-
|
16
|
-
return unless entity
|
17
|
-
attributes.each do |field, value|
|
18
|
-
entity.send("#{field}=", value)
|
19
|
-
end
|
20
|
-
|
21
|
-
entity
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.read id
|
25
|
-
@collection[id]
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.delete(id)
|
29
|
-
@collection.delete(id)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.delete_all
|
33
|
-
@collection = {}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,12 +0,0 @@
|
|
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/**/*"] + ['Domain']
|
11
|
-
s.license = 'MIT'
|
12
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
0.0.0
|
@@ -1,21 +0,0 @@
|
|
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
|
@@ -1,25 +0,0 @@
|
|
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
|
@@ -1,24 +0,0 @@
|
|
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
|
@@ -1,61 +0,0 @@
|
|
1
|
-
class HecksDomainBuilder
|
2
|
-
# A Domain Object attribute
|
3
|
-
class Attribute
|
4
|
-
attr_writer :type
|
5
|
-
attr_reader :object_name
|
6
|
-
|
7
|
-
def initialize(string)
|
8
|
-
@string = string
|
9
|
-
@object_name = object_name
|
10
|
-
end
|
11
|
-
|
12
|
-
def list?
|
13
|
-
@string.include?("[")
|
14
|
-
end
|
15
|
-
|
16
|
-
def name
|
17
|
-
@string.split(":").first
|
18
|
-
end
|
19
|
-
|
20
|
-
def type
|
21
|
-
return @type if @type
|
22
|
-
@string.split(":").last.delete("[").delete("]").camelize
|
23
|
-
end
|
24
|
-
|
25
|
-
def domain_module
|
26
|
-
return unless @string.include?("::")
|
27
|
-
@string.split("::").first.split(":").last.camelize
|
28
|
-
end
|
29
|
-
|
30
|
-
def copy(new_values={})
|
31
|
-
result = self.class.new(@string)
|
32
|
-
result.type = new_values[:type] if new_values[:type]
|
33
|
-
result
|
34
|
-
end
|
35
|
-
|
36
|
-
def reference?
|
37
|
-
!primitive? && !list?
|
38
|
-
end
|
39
|
-
|
40
|
-
def domain_reference?
|
41
|
-
@string.include?('::')
|
42
|
-
end
|
43
|
-
|
44
|
-
def referenced_object
|
45
|
-
return unless reference?
|
46
|
-
return @string.split("::").last if @string.include?("::")
|
47
|
-
@string.split(":").last
|
48
|
-
end
|
49
|
-
|
50
|
-
def primitive?
|
51
|
-
['String', 'Integer', 'Currency'].include?(type)
|
52
|
-
end
|
53
|
-
|
54
|
-
def ==(other)
|
55
|
-
return false if other.name != name
|
56
|
-
return false if other.type != type
|
57
|
-
return false if other.domain_module != domain_module
|
58
|
-
return true
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class HecksDomainBuilder
|
2
|
-
# A domain
|
3
|
-
class Domain
|
4
|
-
attr_reader :domain_modules, :name
|
5
|
-
def initialize(name:)
|
6
|
-
@name = name
|
7
|
-
@domain_modules = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
def module(name, &block)
|
11
|
-
result = DomainModule.new(name: name)
|
12
|
-
@domain_modules[name.to_sym] = result
|
13
|
-
yield(result)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
class HecksDomainBuilder
|
2
|
-
# A domain module
|
3
|
-
class DomainModule
|
4
|
-
attr_reader :objects, :name, :references
|
5
|
-
|
6
|
-
def initialize(name:)
|
7
|
-
@name = name
|
8
|
-
@objects = []
|
9
|
-
@references = []
|
10
|
-
end
|
11
|
-
|
12
|
-
def head(name=nil)
|
13
|
-
return (@objects << Head.new(name: name)).last if name
|
14
|
-
objects.find{ |o| o.is_a?(Head) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def value(name)
|
18
|
-
(@objects << Value.new(name: name)).last
|
19
|
-
end
|
20
|
-
|
21
|
-
def reference(name)
|
22
|
-
(@references << Reference.new(name)).last
|
23
|
-
end
|
24
|
-
|
25
|
-
def find(name)
|
26
|
-
@objects.each do |object|
|
27
|
-
return object if object.name.downcase == name.downcase
|
28
|
-
end
|
29
|
-
return nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
class HecksDomainBuilder
|
2
|
-
# A Domain Object
|
3
|
-
class DomainObject
|
4
|
-
attr_reader :name, :attributes
|
5
|
-
|
6
|
-
def initialize(name:)
|
7
|
-
@name = name
|
8
|
-
end
|
9
|
-
|
10
|
-
def attributes(*values)
|
11
|
-
return @attributes if @attributes
|
12
|
-
@attributes = values.map { |value| Attribute.new(value) }
|
13
|
-
end
|
14
|
-
|
15
|
-
def attribute_hash
|
16
|
-
attributes.map do |attribute|
|
17
|
-
[attribute.name.to_sym, type_with_domain_module(attribute)]
|
18
|
-
end.to_h
|
19
|
-
end
|
20
|
-
|
21
|
-
def attribute_string
|
22
|
-
attributes.map do |attribute|
|
23
|
-
[attribute.name, type_with_domain_module(attribute)].join(':')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def references
|
28
|
-
@attributes.reject(&:primitive?)
|
29
|
-
end
|
30
|
-
|
31
|
-
def domain_references
|
32
|
-
@attributes.select(&:domain_reference?)
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def type_with_domain_module(attribute)
|
38
|
-
type = Types.values.include?(attribute.type) ? "Value" : attribute.type
|
39
|
-
type = '[' + type + ']' if attribute.list?
|
40
|
-
return type unless attribute.domain_module
|
41
|
-
[attribute.domain_module, type].join("::")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/domain_builder/head.rb
DELETED
@@ -1,37 +0,0 @@
|
|
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
|
-
# Represents information about your domain
|
10
|
-
class HecksDomainBuilder
|
11
|
-
Types ||= {
|
12
|
-
string: 'String',
|
13
|
-
integer: 'Integer',
|
14
|
-
currency: 'Currency'
|
15
|
-
}
|
16
|
-
|
17
|
-
attr_accessor :domain, :specification, :name
|
18
|
-
|
19
|
-
def initialize(domain_name:, &block)
|
20
|
-
@name = domain_name
|
21
|
-
@domain = Domain.new(name: domain_name)
|
22
|
-
block.yield(@domain)
|
23
|
-
self
|
24
|
-
end
|
25
|
-
|
26
|
-
def domain_modules
|
27
|
-
@domain.domain_modules
|
28
|
-
end
|
29
|
-
|
30
|
-
def [](module_name)
|
31
|
-
domain_modules[module_name]
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.build(domain_name, &block)
|
35
|
-
new(domain_name: domain_name, &block)
|
36
|
-
end
|
37
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class HecksDomainBuilder
|
2
|
-
# Represents a reference object
|
3
|
-
class Reference
|
4
|
-
def initialize(reference)
|
5
|
-
@reference = reference
|
6
|
-
end
|
7
|
-
|
8
|
-
def referenced_entity
|
9
|
-
@reference.split("::").map(&:camelcase).join("::")
|
10
|
-
end
|
11
|
-
|
12
|
-
def name
|
13
|
-
@reference.split("::").last.camelcase + "Reference"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/domain_builder/value.rb
DELETED
data/lib/hecks-domain.rb
DELETED