hecks 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/hecks +6 -0
- data/bin/hecks_console +10 -0
- data/lib/adapters/adapters.rb +6 -0
- data/lib/adapters/events/events.rb +27 -0
- data/lib/adapters/logger/logger.rb +18 -0
- data/lib/adapters/memory_database/memory_database.rb +18 -0
- data/lib/adapters/resource_server/methods.rb +22 -0
- data/lib/adapters/resource_server/methods/create.rb +49 -0
- data/lib/adapters/resource_server/methods/delete.rb +45 -0
- data/lib/adapters/resource_server/methods/read.rb +44 -0
- data/lib/adapters/resource_server/methods/update.rb +50 -0
- data/lib/adapters/resource_server/resource_server.rb +52 -0
- data/lib/adapters/validator/validator.rb +33 -0
- data/lib/application/application.rb +45 -0
- data/lib/application/commands/commands.rb +5 -0
- data/lib/application/commands/create.rb +52 -0
- data/lib/application/commands/crud_handler.rb +40 -0
- data/lib/application/commands/delete.rb +40 -0
- data/lib/application/commands/runner.rb +48 -0
- data/lib/application/commands/update.rb +41 -0
- data/lib/application/queries/find_by_id.rb +19 -0
- data/lib/application/queries/queries.rb +2 -0
- data/lib/application/queries/query_runner.rb +28 -0
- data/lib/cli/cli.rb +24 -0
- data/lib/cli/command_runner.rb +25 -0
- data/lib/cli/commands.rb +5 -0
- data/lib/cli/commands/build.rb +10 -0
- data/lib/cli/commands/console.rb +8 -0
- data/lib/cli/commands/generate.rb +26 -0
- data/lib/cli/commands/generate/builder.rb +60 -0
- data/lib/cli/commands/generate/builder/aggregate_command_line_builder.rb +18 -0
- data/lib/cli/commands/generate/builder/reference_command_line_builder.rb +19 -0
- data/lib/cli/commands/generate/builder/value_object_command_line_builder.rb +19 -0
- data/lib/cli/commands/generate/generate_aws_package.rb +17 -0
- data/lib/cli/commands/generate/generate_binary_package.rb +92 -0
- data/lib/cli/commands/generate/generate_domain_object.rb +71 -0
- data/lib/cli/commands/generate/generate_domain_object/assignment_template.rb +36 -0
- data/lib/cli/commands/generate/generate_domain_object/option_formatter.rb +30 -0
- data/lib/cli/commands/generate/generate_lambda_package.rb +20 -0
- data/lib/cli/commands/generate/generate_resource_server.rb +17 -0
- data/lib/cli/commands/generate/new.rb +47 -0
- data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +16 -0
- data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%name%.rb.tt +9 -0
- data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/repository.rb.tt +40 -0
- data/lib/cli/commands/generate/templates/binary_package/build/linux-x86_64/lib/app/hello.rb +1 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/%domain_name%.rb.tt +17 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/Dockerfile.tt +8 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/Gemfile.tt +4 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/bundle/config +3 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/wrapper.tt +13 -0
- data/lib/cli/commands/generate/templates/domain/%name%.gemspec.tt +12 -0
- data/lib/cli/commands/generate/templates/domain/Version +1 -0
- data/lib/cli/commands/generate/templates/domain/lib/%name%.rb.tt +21 -0
- data/lib/cli/commands/generate/templates/domain/spec/spec_helper.rb.tt +4 -0
- data/lib/cli/commands/generate/templates/lambda_package/handler.js.tt +12 -0
- data/lib/cli/commands/generate/templates/lambda_package/serverless.yml.tt +100 -0
- data/lib/cli/commands/generate/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +25 -0
- data/lib/cli/commands/generate/templates/resource_server/config.ru.tt +8 -0
- data/lib/cli/commands/generate/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +24 -0
- data/lib/cli/commands/package.rb +16 -0
- data/lib/cli/commands/test.rb +41 -0
- data/lib/console/commands.rb +9 -0
- data/lib/console/console.rb +24 -0
- data/lib/domain_builder/attribute.rb +33 -0
- data/lib/domain_builder/domain.rb +17 -0
- data/lib/domain_builder/domain_builder.rb +35 -0
- data/lib/domain_builder/domain_module.rb +26 -0
- data/lib/domain_builder/domain_object.rb +37 -0
- data/lib/domain_builder/head.rb +6 -0
- data/lib/domain_builder/reference.rb +17 -0
- data/lib/domain_builder/value.rb +6 -0
- data/lib/hecks.rb +7 -0
- metadata +229 -0
@@ -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,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
|
data/lib/cli/cli.rb
ADDED
@@ -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
|
data/lib/cli/commands.rb
ADDED
@@ -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
|