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,18 @@
1
+ module Hecks
2
+ class Builder
3
+ module AggregateCommandLineBuilder
4
+ def self.build(domain, runner)
5
+ domain.domain_modules.values.each do |domain_module|
6
+ runner.call(
7
+ [
8
+ 'generate domain_object',
9
+ '-t', 'aggregate',
10
+ '-n', domain_module.name,
11
+ '--head_name', domain_module.head.name,
12
+ '-a', domain_module.head.attribute_string
13
+ ])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module Hecks
2
+ class Builder
3
+ module ReferenceCommandLineBuilder
4
+ def self.build(domain, runner)
5
+ domain.domain_modules.values.each do |domain_module|
6
+ domain_module.references.each do |reference|
7
+ runner.call([
8
+ 'generate domain_object',
9
+ '-t', 'reference',
10
+ '-n', reference.name,
11
+ '-m', domain_module.name,
12
+ '-r', reference.referenced_entity
13
+ ])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Hecks
2
+ class Builder
3
+ module ValueObjectCommandLineBuilder
4
+ def self.build(domain, runner)
5
+ domain.domain_modules.values.each do |domain_module|
6
+ (domain_module.objects - [domain_module.head]).each do |value_object|
7
+ runner.call([
8
+ 'generate domain_object',
9
+ '-t', 'value_object',
10
+ '-n', value_object.name,
11
+ '-m', domain_module.name,
12
+ '-a', value_object.attribute_string
13
+ ])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ class GenerateResourceServer < Thor::Group; end
2
+
3
+ class GeneratePackage
4
+ include Thor::Actions
5
+
6
+ def self.source_root
7
+ File.dirname(__FILE__) + '/templates/'
8
+ end
9
+
10
+ def create_package
11
+ directory('package', './packages/lambda')
12
+ end
13
+
14
+ def domain
15
+ File.basename(Dir.getwd)
16
+ end
17
+ end
@@ -0,0 +1,92 @@
1
+ class GenerateBinaryPackage < Thor::Group
2
+ include Thor::Actions
3
+
4
+ HOST = "http://d6r77u77i8pq3.cloudfront.net/releases"
5
+ OSX_BINARY = "traveling-ruby-20150715-2.2.2-osx.tar.gz"
6
+ LINUX_BINARY = 'traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz'
7
+ BUILD_DIR = 'packages/binary/build'
8
+ RESOURCES_DIR = BUILD_DIR + '/resources'
9
+ OSX_DIR = BUILD_DIR + '/osx'
10
+ OSX_LIB_DIR = OSX_DIR + '/lib'
11
+ OSX_APP_DIR = OSX_LIB_DIR + '/app'
12
+ LINUX_DIR = BUILD_DIR + '/linux-x86_64'
13
+ LINUX_LIB_DIR = LINUX_DIR + 'lib'
14
+ LINUX_APP_DIR = LINUX_LIB_DIR + '/app'
15
+
16
+ def self.source_root
17
+ File.dirname(__FILE__) + '/templates'
18
+ end
19
+
20
+ def create_package_folder
21
+ run("rm -rf packages/binary")
22
+ directory('binary_package', './packages/binary')
23
+ end
24
+
25
+ def domain_name
26
+ Dir.pwd.split('/').last
27
+ end
28
+
29
+ def build
30
+ package(OSX_APP_DIR, OSX_LIB_DIR, OSX_BINARY, OSX_DIR)
31
+ package(LINUX_APP_DIR, LINUX_LIB_DIR, LINUX_BINARY, LINUX_DIR)
32
+ end
33
+
34
+ private
35
+
36
+ def package(app_dir, lib_dir, binary, package_dir)
37
+ empty_directory(app_dir)
38
+ empty_directory(lib_dir + '/ruby')
39
+ download(binary, lib_dir)
40
+ copy_resources(app_dir, package_dir)
41
+ bundle_with_ruby_2_2_2(app_dir)
42
+ reduce_package_size(app_dir)
43
+ end
44
+
45
+ def reduce_package_size(app_dir)
46
+ files = %w(test tests spec features benchmark README* CHANGE* Change*
47
+ COPYING* LICENSE* MIT-LICENSE* TODO *.txt *.md *.rdoc doc docs example
48
+ examples sample doc-api
49
+ )
50
+ files.each do |file|
51
+ run("rm -rf #{app_dir}/vendor/ruby/*/gems/*/#{file}")
52
+ end
53
+
54
+ run("rm -rf #{app_dir}/vendor/*/*/cache/*")
55
+ %w(.gitignore .travis.yml).each do |file|
56
+ run("rm -rf #{app_dir}/vendor/ruby/*/gems/*/#{file}")
57
+ end
58
+
59
+ %w(MAKEfile */Makefile */tmp).each do |file|
60
+ run("rm -f #{app_dir}/vendor/ruby/*/gems/*/ext/#{file}")
61
+ end
62
+
63
+ %w(*.c *.cpp *.h *.rl *extconf.rb *.java *.class *.md).each do |file|
64
+ run("find #{app_dir}/vendor/ruby -name '#{file}' | xargs rm -f")
65
+ end
66
+
67
+ %w(*.0 *.so *.bundle).each do |file|
68
+ run("find #{app_dir}/vendor/ruby/*/gems -name '#{file}' | xargs rm -f")
69
+ end
70
+ end
71
+
72
+ def copy_resources(app_dir, package_dir)
73
+ run("cp #{RESOURCES_DIR}/Gemfile #{app_dir}")
74
+ run("cp -rf #{RESOURCES_DIR}/bundle #{app_dir}/.bundle")
75
+ run("cp -rf #{RESOURCES_DIR}/#{domain_name}.rb #{app_dir}/#{domain_name}.rb")
76
+ run("cp -rf #{RESOURCES_DIR}/wrapper #{package_dir}/#{domain_name}")
77
+ run("cd #{package_dir} && chmod 744 #{domain_name}")
78
+ end
79
+
80
+ def download(binary, lib_dir)
81
+ run("cd #{RESOURCES_DIR} && curl -O #{HOST}/#{binary}")
82
+ run("tar -xzf #{RESOURCES_DIR}/#{binary} -C #{lib_dir}/ruby")
83
+ end
84
+
85
+ def bundle_with_ruby_2_2_2(app_dir)
86
+ run("cp -rf #{RESOURCES_DIR}/Dockerfile #{app_dir}")
87
+ run("cp #{domain_name}-0.0.0.gem #{app_dir}" )
88
+ run("cd #{app_dir} && docker build -t #{domain_name} --no-cache .")
89
+ container = `docker create pizza_builder:latest`.gsub("\n", '')
90
+ run("docker cp #{container}:/usr/src/app/vendor #{app_dir}")
91
+ end
92
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GenerateDomainObject < Thor::Group; end
4
+
5
+ require_relative "generate_domain_object/assignment_template"
6
+ require_relative "generate_domain_object/option_formatter"
7
+
8
+ class GenerateDomainObject
9
+ include Thor::Actions
10
+
11
+ class_option :head_name, aliases: '-h', desc: 'the name of the aggregate head'
12
+ class_option :attributes, aliases: '-a', type: :array, desc: 'attributes for the aggregate head'
13
+ class_option :name, aliases: '-n', desc: 'attributes for the aggregate head'
14
+ class_option :type, aliases: '-t', desc: 'The type of domain object you want to create'
15
+ class_option :module_name, aliases: '-m', desc: 'Domain Module'
16
+ class_option :referenced_entity, aliases: '-r', desc: 'Referenced Entity'
17
+
18
+ def self.source_root
19
+ File.dirname(__FILE__) + '/templates'
20
+ end
21
+
22
+ def create_aggregate_folder
23
+ directory(options[:type].to_s, '.')
24
+ end
25
+
26
+ private
27
+
28
+ def assignment_template(attributes)
29
+ AssignmentTemplate.new(attributes).render
30
+ end
31
+
32
+ def option_format(format, include_id: false)
33
+ OptionFormatter.new(options[:attributes]).call(format, include_id: include_id)
34
+ end
35
+
36
+ def head_name
37
+ options[:head_name]
38
+ end
39
+
40
+ def name
41
+ options[:name]
42
+ end
43
+
44
+ def file_name
45
+ name.underscore
46
+ end
47
+
48
+ def attribute_names_without_id
49
+ attributes_without_id.map(&:name)
50
+ end
51
+
52
+ def module_name
53
+ options[:module_name]
54
+ end
55
+
56
+ def domain_name
57
+ Dir.pwd.split('/').last
58
+ end
59
+
60
+ def attributes_without_id_as_string
61
+ attributes_without_id.map { |attribute| ':' + Hecks::DomainBuilder::Attribute.new(attribute).name }.join ', '
62
+ end
63
+
64
+ def attributes
65
+ options[:attributes] + ['id:value']
66
+ end
67
+
68
+ def attributes_without_id
69
+ options[:attributes]
70
+ end
71
+ end
@@ -0,0 +1,36 @@
1
+ class GenerateDomainObject
2
+ class AssignmentTemplate
3
+ def initialize(attributes)
4
+ @attributes = attributes
5
+ end
6
+
7
+ def render
8
+ attributes.map do |attribute|
9
+ @attribute = Hecks::DomainBuilder::Attribute.new(attribute)
10
+ do_assignment
11
+ end.join("\n")
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :attributes, :attribute
17
+
18
+ def do_assignment
19
+ return value_assignment if @attribute.type == "Value"
20
+ return reference_factory_assignment if attribute.domain_module
21
+ return factory_assignment
22
+ end
23
+
24
+ def reference_factory_assignment
25
+ "@#{attribute.name} = #{attribute.type}Reference.factory(#{attribute.name})"
26
+ end
27
+
28
+ def factory_assignment
29
+ "@#{attribute.name} = #{attribute.type}.factory(#{attribute.name})"
30
+ end
31
+
32
+ def value_assignment
33
+ "@#{attribute.name} = #{attribute.name}"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ class GenerateDomainObject
2
+ class OptionFormatter
3
+ def initialize(attributes)
4
+ @attributes = attributes.map do |attribute|
5
+ Hecks::DomainBuilder::Attribute.new(attribute)
6
+ end
7
+ end
8
+
9
+ def call(format, include_id: false)
10
+ case format
11
+ when 'keys_and_values'
12
+ attributes(include_id).map { |attribute| (attribute.name + ': ' + attribute.name) }.join(', ')
13
+ when 'attribute_string'
14
+ attributes(include_id).map { |attribute| ':' + attribute.name }.join ', '
15
+ when 'param_names'
16
+ attributes(include_id).map { |attribute| attribute.name + ':' }.join ', '
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def attributes(include_id)
23
+ if include_id
24
+ @attributes + [Hecks::DomainBuilder::Attribute.new('id:value')]
25
+ else
26
+ @attributes
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ class GenerateLambdaPackage < Thor::Group
2
+ include Thor::Actions
3
+
4
+ def self.source_root
5
+ File.dirname(__FILE__) + '/templates'
6
+ end
7
+
8
+ def create_package_folder
9
+ directory('lambda_package', './packages/lambda')
10
+ end
11
+
12
+ def domain_name
13
+ Dir.pwd.split('/').last
14
+ end
15
+
16
+ def create_function
17
+ run("rm -rf packages/lambda/#{domain_name}")
18
+ run("cp -r packages/binary/build/osx packages/lambda/#{domain_name}")
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ class GenerateResourceServer < Thor::Group
2
+ include Thor::Actions
3
+
4
+ def self.source_root
5
+ File.dirname(__FILE__) + '/templates/'
6
+ end
7
+
8
+ def create_aggregate_folder
9
+ directory('resource_server', '.')
10
+ end
11
+
12
+ def domain
13
+ File.basename(Dir.getwd)
14
+ end
15
+
16
+ private
17
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hecks
4
+ class New < Thor::Group
5
+ namespace :hecks
6
+ include Thor::Actions
7
+
8
+ class_option :nobuilder, aliases: '-n', desc: 'load schema from builder'
9
+ class_option :dry_run, aliases: '-d', desc: 'Use when specifying a schema file to output the commands, without running them'
10
+
11
+ def self.source_root
12
+ File.dirname(__FILE__)
13
+ end
14
+
15
+ def load_from_builder
16
+ return if options[:nobuilder]
17
+ Hecks::Builder.new(
18
+ hecks_file: File.read('HECKS'),
19
+ name: File.basename(Dir.getwd),
20
+ dry_run: !options[:dry_run].nil?
21
+ ).call
22
+ end
23
+
24
+ def create_hexagon_folder
25
+ return unless options[:nobuilder]
26
+ directory('templates/domain', ".")
27
+ end
28
+
29
+ private
30
+
31
+ def name
32
+ File.basename(Dir.getwd)
33
+ end
34
+
35
+ def module_name
36
+ name.camelize
37
+ end
38
+
39
+ def domain_module_name
40
+ domain_name.camelize
41
+ end
42
+
43
+ def condensed_module_name
44
+ name.delete('_')
45
+ end
46
+ end
47
+ 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,9 @@
1
+ module <%= domain_name.camelize %>
2
+ module Domain
3
+ module <%= name.camelize %>
4
+ def self.head
5
+ <%= options[:head_name].camelize %>
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,40 @@
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
+ end
13
+
14
+ def self.update id, attributes
15
+ entity = read id
16
+
17
+ return unless entity
18
+ attributes.each do |field, value|
19
+ entity.send("#{field}=", value)
20
+ end
21
+
22
+ entity
23
+ end
24
+
25
+ def self.read id
26
+ @collection[id]
27
+ end
28
+
29
+ def self.delete(id)
30
+ @collection.delete(id)
31
+ end
32
+
33
+ def self.delete_all
34
+ @collection = {}
35
+ @last_id = 0
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end