hecks 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/bin/hecks +6 -0
  3. data/bin/hecks_console +10 -0
  4. data/lib/adapters/adapters.rb +6 -0
  5. data/lib/adapters/events/events.rb +27 -0
  6. data/lib/adapters/logger/logger.rb +18 -0
  7. data/lib/adapters/memory_database/memory_database.rb +18 -0
  8. data/lib/adapters/resource_server/methods.rb +22 -0
  9. data/lib/adapters/resource_server/methods/create.rb +49 -0
  10. data/lib/adapters/resource_server/methods/delete.rb +45 -0
  11. data/lib/adapters/resource_server/methods/read.rb +44 -0
  12. data/lib/adapters/resource_server/methods/update.rb +50 -0
  13. data/lib/adapters/resource_server/resource_server.rb +52 -0
  14. data/lib/adapters/validator/validator.rb +33 -0
  15. data/lib/application/application.rb +45 -0
  16. data/lib/application/commands/commands.rb +5 -0
  17. data/lib/application/commands/create.rb +52 -0
  18. data/lib/application/commands/crud_handler.rb +40 -0
  19. data/lib/application/commands/delete.rb +40 -0
  20. data/lib/application/commands/runner.rb +48 -0
  21. data/lib/application/commands/update.rb +41 -0
  22. data/lib/application/queries/find_by_id.rb +19 -0
  23. data/lib/application/queries/queries.rb +2 -0
  24. data/lib/application/queries/query_runner.rb +28 -0
  25. data/lib/cli/cli.rb +24 -0
  26. data/lib/cli/command_runner.rb +25 -0
  27. data/lib/cli/commands.rb +5 -0
  28. data/lib/cli/commands/build.rb +10 -0
  29. data/lib/cli/commands/console.rb +8 -0
  30. data/lib/cli/commands/generate.rb +26 -0
  31. data/lib/cli/commands/generate/builder.rb +60 -0
  32. data/lib/cli/commands/generate/builder/aggregate_command_line_builder.rb +18 -0
  33. data/lib/cli/commands/generate/builder/reference_command_line_builder.rb +19 -0
  34. data/lib/cli/commands/generate/builder/value_object_command_line_builder.rb +19 -0
  35. data/lib/cli/commands/generate/generate_aws_package.rb +17 -0
  36. data/lib/cli/commands/generate/generate_binary_package.rb +92 -0
  37. data/lib/cli/commands/generate/generate_domain_object.rb +71 -0
  38. data/lib/cli/commands/generate/generate_domain_object/assignment_template.rb +36 -0
  39. data/lib/cli/commands/generate/generate_domain_object/option_formatter.rb +30 -0
  40. data/lib/cli/commands/generate/generate_lambda_package.rb +20 -0
  41. data/lib/cli/commands/generate/generate_resource_server.rb +17 -0
  42. data/lib/cli/commands/generate/new.rb +47 -0
  43. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +16 -0
  44. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%name%.rb.tt +9 -0
  45. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/repository.rb.tt +40 -0
  46. data/lib/cli/commands/generate/templates/binary_package/build/linux-x86_64/lib/app/hello.rb +1 -0
  47. data/lib/cli/commands/generate/templates/binary_package/build/resources/%domain_name%.rb.tt +17 -0
  48. data/lib/cli/commands/generate/templates/binary_package/build/resources/Dockerfile.tt +8 -0
  49. data/lib/cli/commands/generate/templates/binary_package/build/resources/Gemfile.tt +4 -0
  50. data/lib/cli/commands/generate/templates/binary_package/build/resources/bundle/config +3 -0
  51. data/lib/cli/commands/generate/templates/binary_package/build/resources/wrapper.tt +13 -0
  52. data/lib/cli/commands/generate/templates/domain/%name%.gemspec.tt +12 -0
  53. data/lib/cli/commands/generate/templates/domain/Version +1 -0
  54. data/lib/cli/commands/generate/templates/domain/lib/%name%.rb.tt +21 -0
  55. data/lib/cli/commands/generate/templates/domain/spec/spec_helper.rb.tt +4 -0
  56. data/lib/cli/commands/generate/templates/lambda_package/handler.js.tt +12 -0
  57. data/lib/cli/commands/generate/templates/lambda_package/serverless.yml.tt +100 -0
  58. data/lib/cli/commands/generate/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +25 -0
  59. data/lib/cli/commands/generate/templates/resource_server/config.ru.tt +8 -0
  60. data/lib/cli/commands/generate/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +24 -0
  61. data/lib/cli/commands/package.rb +16 -0
  62. data/lib/cli/commands/test.rb +41 -0
  63. data/lib/console/commands.rb +9 -0
  64. data/lib/console/console.rb +24 -0
  65. data/lib/domain_builder/attribute.rb +33 -0
  66. data/lib/domain_builder/domain.rb +17 -0
  67. data/lib/domain_builder/domain_builder.rb +35 -0
  68. data/lib/domain_builder/domain_module.rb +26 -0
  69. data/lib/domain_builder/domain_object.rb +37 -0
  70. data/lib/domain_builder/head.rb +6 -0
  71. data/lib/domain_builder/reference.rb +17 -0
  72. data/lib/domain_builder/value.rb +6 -0
  73. data/lib/hecks.rb +7 -0
  74. metadata +229 -0
@@ -0,0 +1,5 @@
1
+ require_relative 'update'
2
+ require_relative 'create'
3
+ require_relative 'delete'
4
+ require_relative 'crud_handler'
5
+ require_relative 'runner'
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class Application
5
+ module Commands
6
+ class Create
7
+ attr_accessor :args, :id, :errors, :repository, :domain_module
8
+
9
+ def initialize(args:, repository: , domain_module: )
10
+ @repository = repository
11
+ @args = args
12
+ @errors = {}
13
+ @validator = Validator
14
+ @domain_module = domain_module
15
+ end
16
+
17
+ def call
18
+ validate
19
+ create
20
+ self
21
+ end
22
+
23
+ def to_h
24
+ { errors: errors, id: repository_result, args: args }
25
+ end
26
+
27
+ def name
28
+ self.class.to_s.split('::').last.underscore
29
+ end
30
+
31
+ def result
32
+ { id: id, success: !id.nil?, errors: errors, args: args }
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :repository_result
38
+
39
+ def create
40
+ return if @errors.count.positive?
41
+ @id = @repository_result = repository.create(args)
42
+ end
43
+
44
+ def validate
45
+ return if @validator.nil?
46
+ @errors = @validator.new(command: self).call.errors
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ class CRUDHandler
2
+ attr_reader :module_name, :application
3
+
4
+ def initialize(module_name:, application:)
5
+ @module_name = module_name
6
+ @application = application
7
+ end
8
+
9
+ def create(attributes)
10
+ application.call(
11
+ module_name: module_name,
12
+ command_name: :create,
13
+ args: attributes
14
+ )
15
+ end
16
+
17
+ def read(id)
18
+ application.query(
19
+ module_name: module_name,
20
+ query_name: :find_by_id,
21
+ args: {id: id}
22
+ )
23
+ end
24
+
25
+ def update(id, attributes)
26
+ application.call(
27
+ module_name: module_name,
28
+ command_name: :update,
29
+ args: attributes.merge(id: id)
30
+ )
31
+ end
32
+
33
+ def delete(id)
34
+ application.call(
35
+ module_name: module_name,
36
+ command_name: :delete,
37
+ args: {id: id}
38
+ )
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class Application
5
+ module Commands
6
+ class Delete
7
+ attr_accessor :args, :errors, :repository
8
+
9
+ def initialize(args: nil, repository:, domain_module:)
10
+ @args = args || chained_command.args
11
+ @repository = repository
12
+ @errors = { base: [] }
13
+ end
14
+
15
+ def call
16
+ delete
17
+ self
18
+ end
19
+
20
+ def name
21
+ self.class.to_s.split('::').last.underscore
22
+ end
23
+
24
+ def to_h
25
+ { errors: errors, args: args }
26
+ end
27
+
28
+ private
29
+
30
+ attr_accessor :command_result, :repository
31
+
32
+ def delete
33
+ @result = repository.delete(args[:id])
34
+ @errors[:base] << "cound not find #{args[:id]}" unless @result
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,48 @@
1
+ module Hecks
2
+ module Adapters
3
+ class Application
4
+ class Runner
5
+ attr_reader :module_name, :command
6
+
7
+ def initialize(command_name:, module_name:, args:, application:)
8
+ @command_name = command_name
9
+ @module_name = module_name
10
+ @args = args
11
+ @application = application
12
+ @domain_spec = application.domain_spec
13
+ end
14
+
15
+ def call()
16
+ fetch_command
17
+ run_command
18
+ broadcast
19
+ command
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :command_name, :args, :application, :domain_spec
25
+
26
+ def broadcast
27
+ application.events_port.send(command: command, module_name: module_name)
28
+ end
29
+
30
+ def fetch_command
31
+ @command = Commands.const_get(command_name.to_s.camelcase).new(
32
+ repository: application.database[module_name],
33
+ args: args,
34
+ domain_module: fetch_module
35
+ )
36
+ end
37
+
38
+ def fetch_module
39
+ domain_spec.domain_modules[module_name.to_s.camelize.to_sym]
40
+ end
41
+
42
+ def run_command
43
+ @command = command.call
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class Application
5
+ module Commands
6
+ class Update
7
+ attr_accessor :args, :errors, :id, :repository
8
+
9
+ def initialize(args: nil, repository: Repository, domain_module:)
10
+ @repository = repository
11
+ @args = args
12
+ @errors = []
13
+ @id = @args.delete(:id)
14
+ end
15
+
16
+ def name
17
+ self.class.to_s.split('::').last.underscore
18
+ end
19
+
20
+ def call
21
+ update
22
+ self
23
+ end
24
+
25
+ def to_h
26
+ { id: id, args: args }
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :repository_result
32
+
33
+ def update
34
+ return if @errors.count.positive?
35
+ @repository_result = repository.update(id, args)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class Application
5
+ module Queries
6
+ class FindById
7
+ def initialize(repository:)
8
+ @repository = repository
9
+ end
10
+
11
+ def call(params)
12
+ return unless params.keys == [:id]
13
+ @repository.read(params[:id])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'find_by_id'
2
+ require_relative 'query_runner'
@@ -0,0 +1,28 @@
1
+ module Hecks
2
+ module Adapters
3
+ class Application
4
+ class QueryRunner
5
+ def initialize(query_name:, application:, module_name:, args:)
6
+ @query_name = query_name
7
+ @application = application
8
+ @module_name = module_name
9
+ @args = args
10
+ end
11
+
12
+ def call()
13
+ fetch.new(repository: repository).call(@args)
14
+ end
15
+
16
+ private
17
+
18
+ def fetch
19
+ Queries.const_get(@query_name.to_s.camelcase)
20
+ end
21
+
22
+ def repository
23
+ @application.database[@module_name]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'active_support/inflector'
3
+ require_relative 'command_runner'
4
+ require_relative 'commands'
5
+
6
+ module Hecks
7
+ class CLI < Thor
8
+ package_name 'hecks'
9
+
10
+ desc 'generate', 'generate'
11
+ subcommand('generate', Generate)
12
+
13
+ desc 'package', 'package'
14
+ subcommand('package', Package) if File.file?('HECKS')
15
+
16
+ long_desc 'Generate a domain'
17
+ method_option :dryrun,
18
+ aliases: '-d',
19
+ type: :boolean,
20
+ desc: 'Output commands without running'
21
+
22
+ register(New, 'new', 'new', 'Create a new Domain') if File.file?('HECKS')
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ class CommandRunner
3
+ def initialize(hexagon, name, dry_run = false)
4
+ @hexagon = hexagon
5
+ @dry_run = dry_run
6
+ @name = name
7
+ end
8
+
9
+ def call(command)
10
+ output = full_command(command)
11
+ unless File.directory?('tmp')
12
+ FileUtils.mkdir('tmp')
13
+ end
14
+ File.open('tmp/hecks', 'a') { |file| file.write(output + "\n") }
15
+ return if dry_run
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :hexagon, :dry_run, :name
21
+
22
+ def full_command(command)
23
+ (['hecks'] + command).join(' ')
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'commands/test' if File.file?('hecks.gemspec')
2
+ require_relative 'commands/generate'
3
+ require_relative 'commands/build' if File.file?('hecks.gemspec')
4
+ require_relative 'commands/console' if File.file?('HECKS')
5
+ require_relative 'commands/package'
@@ -0,0 +1,10 @@
1
+ module Hecks
2
+ class CLI < Thor
3
+ desc 'build','build and install the hecks gem'
4
+
5
+ def build
6
+ exec(['gem build hecks',
7
+ 'gem install hecks'].join("&&"))
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Hecks
2
+ class CLI < Thor
3
+ desc 'console','REPL with domain helpers'
4
+ def console
5
+ exec 'hecks_console'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'generate/new'
3
+ require_relative 'generate/generate_domain_object'
4
+ require_relative 'generate/generate_resource_server'
5
+ require_relative 'generate/builder'
6
+
7
+
8
+ class Generate < Thor
9
+ desc 'domain_objects', 'generate domain objects'
10
+ method_option :type,
11
+ aliases: '-t',
12
+ required: true,
13
+ desc: 'The type of the domain object you want to generate',
14
+ banner: '[OBJECT_TYPE]',
15
+ enum: %w(entity value_object aggregate reference)
16
+ register(GenerateDomainObject,
17
+ 'domain_object',
18
+ 'domain_object',
19
+ 'Generate Domain Objects') if File.file?('HECKS')
20
+
21
+ desc 'resource_server', 'generate resource_server'
22
+ register(GenerateResourceServer,
23
+ 'resource_server',
24
+ 'resource_server',
25
+ 'Generate A Resource Server for a domain') if File.file?('HECKS')
26
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
4
+ require_relative 'builder/value_object_command_line_builder'
5
+ require_relative 'builder/aggregate_command_line_builder'
6
+ require_relative 'builder/reference_command_line_builder'
7
+
8
+ module Hecks
9
+ class Builder
10
+ def initialize(hecks_file:, name:, dry_run: false)
11
+ @name = name
12
+ @domain = eval(hecks_file).domain
13
+ @dry_run = dry_run
14
+ @runner = CommandRunner.new(domain, name, dry_run)
15
+ end
16
+
17
+ def call
18
+ delete_tmpfile
19
+ puts "\n"
20
+ generate :domain
21
+ generate :modules
22
+ generate :value_objects
23
+ generate :references
24
+ execute_tmpfile && return unless @dry_run
25
+ print_tmpfile
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :runner, :name, :domain
31
+
32
+ def print_tmpfile
33
+ puts File.read('tmp/hecks')
34
+ end
35
+
36
+ def delete_tmpfile
37
+ return unless Pathname('tmp/hecks').exist?
38
+ FileUtils.rm('tmp/hecks')
39
+ end
40
+
41
+ def execute_tmpfile
42
+ exec('bash -x tmp/hecks')
43
+ end
44
+
45
+ def generate(command)
46
+ case command
47
+ when :references
48
+ ReferenceCommandLineBuilder.build(domain, runner)
49
+ when :domain
50
+ runner.call(['new', '-n', name])
51
+ when :modules
52
+ AggregateCommandLineBuilder.build(domain, runner)
53
+ when :value_objects
54
+ ValueObjectCommandLineBuilder.build(domain, runner)
55
+ else
56
+ raise "unrecognized command: #{command}"
57
+ end
58
+ end
59
+ end
60
+ end