hecks-domain 0.1.16.rc → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cli/builder/aggregate_command_line_builder.rb +15 -16
  3. data/lib/cli/builder/reference_command_line_builder.rb +15 -16
  4. data/lib/cli/builder/value_object_command_line_builder.rb +15 -16
  5. data/lib/cli/command_builder.rb +50 -45
  6. data/lib/cli/domain_object/assignment_template.rb +30 -31
  7. data/lib/cli/domain_object/option_formatter.rb +24 -25
  8. data/lib/cli/generate_domain_object.rb +50 -51
  9. data/lib/cli/new.rb +44 -45
  10. data/lib/cli/templates/aggregate/lib/domain/%name%/repository.rb.tt +2 -5
  11. data/lib/domain_builder/attribute.rb +58 -57
  12. data/lib/domain_builder/domain.rb +12 -15
  13. data/lib/domain_builder/domain_module.rb +24 -20
  14. data/lib/domain_builder/domain_object.rb +40 -39
  15. data/lib/domain_builder/head.rb +3 -6
  16. data/lib/domain_builder/hecks-domain-builder.rb +37 -0
  17. data/lib/domain_builder/reference.rb +11 -14
  18. data/lib/domain_builder/value.rb +3 -6
  19. data/lib/hecks-domain.rb +1 -3
  20. metadata +11 -27
  21. data/lib/adapters/adapters.rb +0 -2
  22. data/lib/adapters/resource_server/cli/cli.rb +0 -1
  23. data/lib/adapters/resource_server/cli/generate_resource_server.rb +0 -25
  24. data/lib/adapters/resource_server/cli/templates/resource_server/config.ru.tt +0 -8
  25. data/lib/adapters/resource_server/resource_server.rb +0 -3
  26. data/lib/adapters/sql_database/cli/cli.rb +0 -3
  27. data/lib/adapters/sql_database/cli/generate_domain_migrations.rb +0 -33
  28. data/lib/adapters/sql_database/cli/generate_sql_database.rb +0 -35
  29. data/lib/adapters/sql_database/cli/migration_builder.rb +0 -51
  30. data/lib/adapters/sql_database/cli/templates/migration.rb.tt +0 -14
  31. data/lib/adapters/sql_database/cli/templates/repository.rb.tt +0 -24
  32. data/lib/adapters/sql_database/cli/templates/sql_database/Rakefile +0 -15
  33. data/lib/adapters/sql_database/commands/read/fetch_references.rb +0 -58
  34. data/lib/adapters/sql_database/commands/update/delete_references.rb +0 -45
  35. data/lib/adapters/sql_database/commands/update/link_to_references.rb +0 -45
  36. data/lib/adapters/sql_database/sql_database.rb +0 -1
  37. data/lib/domain_builder/domain_builder.rb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7ac35f924127c1f9983b3b9771813a454bf49ab
4
- data.tar.gz: d1f2ce2bba8052d76d86ed132eb2aa999b65c035
3
+ metadata.gz: 36115f8f920445947e5b136b7e6ec72f6f6f697f
4
+ data.tar.gz: 38140ef2136f7e3a3e0f742effc121cacf288001
5
5
  SHA512:
6
- metadata.gz: 1a697a9a0aa0183f9f220961c476f1e876c09db534d800e9c7d81fa714470f44b7d0309ff08af3b8b5975b4169ecaad9a8b78de082a99a4507eb5594c8643546
7
- data.tar.gz: d20d3bd3b3bc4e1a4099a6743f4d13762469e97bdf704116296ff36b068708513dc3b30dafdf502a942a0d5cca37177bbfe237d4f07372b460aed6d1104da627
6
+ metadata.gz: af0c0408823a0d433eef1f7a84720b3256c6f85f5cc3765d9d4699e15f88af6df7d916bd2e49c409cf116e56fdfd27427814945075214d5d7f5771a5b5175b25
7
+ data.tar.gz: ae1950175278917b083ef1a72ecb77c0b3e760856cc213bf01925a2c3ac83fbd7aae31c3438b503b5d0add46d73241281d9ee82ba5be182c25e16fb2b206c43e
@@ -1,19 +1,18 @@
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
1
+ module HecksDomain
2
+ module CLI
3
+ class CommandBuilder
4
+ # Build an aggregate
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
+ ])
17
16
  end
18
17
  end
19
18
  end
@@ -1,19 +1,18 @@
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
1
+ module HecksDomain
2
+ module CLI
3
+ class CommandBuilder
4
+ # Build a Reference object
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
+ ])
17
16
  end
18
17
  end
19
18
  end
@@ -1,19 +1,18 @@
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
1
+ module HecksDomain
2
+ module CLI
3
+ class CommandBuilder
4
+ # Build a value object
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
+ ])
17
16
  end
18
17
  end
19
18
  end
@@ -1,58 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
  require 'pathname'
3
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
4
+ if ENV['HECKS_DOMAIN_PATH']
5
+ load(ENV['HECKS_DOMAIN_PATH'])
6
+ else
7
+ load('Domain') if File.exist?('Domain')
8
+ end
14
9
 
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
10
+ module HecksDomain
11
+ module CLI
12
+ # Class for generating domain objects
13
+ class CommandBuilder
14
+ def initialize(name:, dry_run: false)
15
+ @name = name
16
+ @domain = DOMAIN
17
+ @dry_run = dry_run
18
+ @runner = HecksCLI::CommandRunner.new(domain, name, dry_run)
19
+ end
25
20
 
26
- private
21
+ def call
22
+ delete_tmpfile
23
+ puts "\n"
24
+ generate :domain
25
+ generate :modules
26
+ generate :value_objects
27
+ generate :references
28
+ execute_tmpfile && return unless @dry_run
29
+ print_tmpfile
30
+ end
27
31
 
28
- attr_reader :runner, :name, :domain
32
+ private
29
33
 
30
- def print_tmpfile
31
- puts File.read('tmp/hecks')
32
- end
34
+ attr_reader :runner, :name, :domain
33
35
 
34
- def delete_tmpfile
35
- return unless Pathname('tmp/hecks').exist?
36
- FileUtils.rm('tmp/hecks')
37
- end
36
+ def print_tmpfile
37
+ puts File.read('tmp/hecks')
38
+ end
38
39
 
39
- def execute_tmpfile
40
- exec('bash -x tmp/hecks')
41
- end
40
+ def delete_tmpfile
41
+ return unless Pathname('tmp/hecks').exist?
42
+ FileUtils.rm('tmp/hecks')
43
+ end
44
+
45
+ def execute_tmpfile
46
+ exec('bash -x tmp/hecks')
47
+ end
42
48
 
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
49
+ def generate(command)
50
+ case command
51
+ when :references
52
+ ReferenceCommandLineBuilder.build(domain, runner)
53
+ when :domain
54
+ runner.call(['new', '-n', name])
55
+ when :modules
56
+ AggregateCommandLineBuilder.build(domain, runner)
57
+ when :value_objects
58
+ ValueObjectCommandLineBuilder.build(domain, runner)
59
+ else
60
+ raise "unrecognized command: #{command}"
56
61
  end
57
62
  end
58
63
  end
@@ -1,41 +1,40 @@
1
- module Hecks
2
- module Domain
3
- module CLI
4
- class GenerateDomainObject
5
- class AssignmentTemplate
6
- def initialize(attributes)
7
- @attributes = attributes
8
- end
1
+ module HecksDomain
2
+ module CLI
3
+ # Helpful methods for supporting object creation
4
+ class GenerateDomainObject
5
+ class AssignmentTemplate
6
+ def initialize(attributes)
7
+ @attributes = attributes
8
+ end
9
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
10
+ def render
11
+ attributes.map do |attribute|
12
+ @attribute = HecksDomainBuilder::Attribute.new(attribute)
13
+ do_assignment
14
+ end.join("\n")
15
+ end
16
16
 
17
- private
17
+ private
18
18
 
19
- attr_reader :attributes, :attribute
19
+ attr_reader :attributes, :attribute
20
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
21
+ def do_assignment
22
+ return value_assignment if HecksDomainBuilder::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
27
 
28
- def reference_factory_assignment
29
- "@#{attribute.name} = #{attribute.type}Reference.factory(#{attribute.name})"
30
- end
28
+ def reference_factory_assignment
29
+ "@#{attribute.name} = #{attribute.type}Reference.factory(#{attribute.name})"
30
+ end
31
31
 
32
- def factory_assignment
33
- "@#{attribute.name} = #{attribute.type}.factory(#{attribute.name})"
34
- end
32
+ def factory_assignment
33
+ "@#{attribute.name} = #{attribute.type}.factory(#{attribute.name})"
34
+ end
35
35
 
36
- def value_assignment
37
- "@#{attribute.name} = #{attribute.name}"
38
- end
36
+ def value_assignment
37
+ "@#{attribute.name} = #{attribute.name}"
39
38
  end
40
39
  end
41
40
  end
@@ -1,33 +1,32 @@
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
1
+ module HecksDomain
2
+ module CLI
3
+ class GenerateDomainObject
4
+ # Generates options in templates
5
+ class OptionFormatter
6
+ def initialize(attributes)
7
+ @attributes = attributes.map do |attribute|
8
+ HecksDomainBuilder::Attribute.new(attribute)
10
9
  end
10
+ end
11
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
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 ', '
21
20
  end
21
+ end
22
22
 
23
- private
23
+ private
24
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
25
+ def attributes(include_id)
26
+ if include_id
27
+ @attributes + [HecksDomainBuilder::Attribute.new('id:value')]
28
+ else
29
+ @attributes
31
30
  end
32
31
  end
33
32
  end
@@ -1,70 +1,69 @@
1
1
  # frozen_string_literal: true
2
- module Hecks
3
- module Domain
4
- module CLI
5
- class GenerateDomainObject < Thor::Group
6
- include Thor::Actions
2
+ module HecksDomain
3
+ module CLI
4
+ # Generate a domain object
5
+ class GenerateDomainObject < Thor::Group
6
+ include Thor::Actions
7
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'
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
14
 
15
- def self.source_root
16
- File.dirname(__FILE__) + '/templates'
17
- end
15
+ def self.source_root
16
+ File.dirname(__FILE__) + '/templates'
17
+ end
18
18
 
19
- def create_aggregate_folder
20
- directory(options[:type].to_s, '.')
21
- end
19
+ def create_aggregate_folder
20
+ directory(options[:type].to_s, '.')
21
+ end
22
22
 
23
- private
23
+ private
24
24
 
25
- def assignment_template(attributes)
26
- AssignmentTemplate.new(attributes).render
27
- end
25
+ def assignment_template(attributes)
26
+ AssignmentTemplate.new(attributes).render
27
+ end
28
28
 
29
- def option_format(format, include_id: false)
30
- OptionFormatter.new(options[:attributes]).call(format, include_id: include_id)
31
- end
29
+ def option_format(format, include_id: false)
30
+ OptionFormatter.new(options[:attributes]).call(format, include_id: include_id)
31
+ end
32
32
 
33
- def head_name
34
- options[:head_name]
35
- end
33
+ def head_name
34
+ options[:head_name]
35
+ end
36
36
 
37
- def name
38
- options[:name]
39
- end
37
+ def name
38
+ options[:name]
39
+ end
40
40
 
41
- def file_name
42
- name.underscore
43
- end
41
+ def file_name
42
+ name.underscore
43
+ end
44
44
 
45
- def attribute_names_without_id
46
- attributes_without_id.map(&:name)
47
- end
45
+ def attribute_names_without_id
46
+ attributes_without_id.map(&:name)
47
+ end
48
48
 
49
- def module_name
50
- options[:module_name]
51
- end
49
+ def module_name
50
+ options[:module_name]
51
+ end
52
52
 
53
- def domain_name
54
- Dir.pwd.split('/').last
55
- end
53
+ def domain_name
54
+ Dir.pwd.split('/').last
55
+ end
56
56
 
57
- def attributes_without_id_as_string
58
- attributes_without_id.map { |attribute| ':' + Hecks::Domain::DomainBuilder::Attribute.new(attribute).name }.join ', '
59
- end
57
+ def attributes_without_id_as_string
58
+ attributes_without_id.map { |attribute| ':' + HecksDomainBuilder::Attribute.new(attribute).name }.join ', '
59
+ end
60
60
 
61
- def attributes
62
- options[:attributes] + ['id:integer']
63
- end
61
+ def attributes
62
+ options[:attributes] + ['id:integer']
63
+ end
64
64
 
65
- def attributes_without_id
66
- options[:attributes]
67
- end
65
+ def attributes_without_id
66
+ options[:attributes]
68
67
  end
69
68
  end
70
69
  end
data/lib/cli/new.rb CHANGED
@@ -1,49 +1,48 @@
1
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
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('_')
47
46
  end
48
47
  end
49
48
  end
@@ -3,12 +3,10 @@ module <%= domain_name.camelize %>
3
3
  module <%= name.camelize %>
4
4
  class Repository
5
5
  @collection = {}
6
- @last_id = 0
7
6
 
8
7
  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
8
+ id = attributes[:id]
9
+ @collection[id] = <%= options[:head_name].camelize %>.new(attributes)
12
10
  Struct.new(:id).new(id)
13
11
  end
14
12
 
@@ -33,7 +31,6 @@ module <%= domain_name.camelize %>
33
31
 
34
32
  def self.delete_all
35
33
  @collection = {}
36
- @last_id = 0
37
34
  end
38
35
  end
39
36
  end