hecks 0.0.8 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hecks +1 -0
  3. data/lib/cli.rb +28 -0
  4. data/lib/cli/build.rb +13 -0
  5. data/lib/cli/{commands/console.rb → console.rb} +0 -0
  6. data/lib/cli/generate.rb +35 -0
  7. data/lib/cli/{commands/package.rb → package.rb} +2 -5
  8. data/lib/cli/test.rb +56 -0
  9. data/lib/{console/console.rb → console.rb} +1 -2
  10. data/lib/console/commands.rb +1 -1
  11. data/lib/hecks.rb +6 -6
  12. data/lib/packager.rb +2 -0
  13. data/lib/packager/generate_binary_package.rb +146 -0
  14. data/lib/packager/generate_lambda_package.rb +26 -0
  15. data/lib/{cli/commands/generate/templates/binary_package/build/resources → packager/templates}/Gemfile.tt +1 -1
  16. data/lib/{cli/commands/generate → packager}/templates/binary_package/build/linux-x86_64/lib/app/hello.rb +0 -0
  17. data/lib/{cli/commands/generate → packager}/templates/binary_package/build/resources/%domain_name%.rb.tt +6 -2
  18. data/lib/packager/templates/binary_package/build/resources/Dockerfile.tt +14 -0
  19. data/lib/{cli/commands/generate → packager}/templates/binary_package/build/resources/bundle/config +0 -0
  20. data/lib/{cli/commands/generate → packager}/templates/binary_package/build/resources/wrapper.tt +0 -0
  21. data/lib/{cli/commands/generate → packager}/templates/lambda_package/handler.js.tt +0 -0
  22. data/lib/{cli/commands/generate → packager}/templates/lambda_package/serverless.yml.tt +0 -0
  23. metadata +45 -94
  24. data/lib/adapters/adapters.rb +0 -6
  25. data/lib/adapters/events/events.rb +0 -27
  26. data/lib/adapters/logger/logger.rb +0 -18
  27. data/lib/adapters/memory_database/memory_database.rb +0 -18
  28. data/lib/adapters/resource_server/methods.rb +0 -22
  29. data/lib/adapters/resource_server/methods/create.rb +0 -49
  30. data/lib/adapters/resource_server/methods/delete.rb +0 -45
  31. data/lib/adapters/resource_server/methods/read.rb +0 -44
  32. data/lib/adapters/resource_server/methods/update.rb +0 -50
  33. data/lib/adapters/resource_server/resource_server.rb +0 -52
  34. data/lib/adapters/validator/validator.rb +0 -33
  35. data/lib/application/application.rb +0 -45
  36. data/lib/application/commands/commands.rb +0 -5
  37. data/lib/application/commands/create.rb +0 -52
  38. data/lib/application/commands/crud_handler.rb +0 -40
  39. data/lib/application/commands/delete.rb +0 -40
  40. data/lib/application/commands/runner.rb +0 -48
  41. data/lib/application/commands/update.rb +0 -41
  42. data/lib/application/queries/find_by_id.rb +0 -19
  43. data/lib/application/queries/queries.rb +0 -2
  44. data/lib/application/queries/query_runner.rb +0 -28
  45. data/lib/cli/cli.rb +0 -24
  46. data/lib/cli/commands.rb +0 -5
  47. data/lib/cli/commands/build.rb +0 -10
  48. data/lib/cli/commands/generate.rb +0 -26
  49. data/lib/cli/commands/generate/builder.rb +0 -60
  50. data/lib/cli/commands/generate/builder/aggregate_command_line_builder.rb +0 -18
  51. data/lib/cli/commands/generate/builder/reference_command_line_builder.rb +0 -19
  52. data/lib/cli/commands/generate/builder/value_object_command_line_builder.rb +0 -19
  53. data/lib/cli/commands/generate/generate_aws_package.rb +0 -17
  54. data/lib/cli/commands/generate/generate_binary_package.rb +0 -92
  55. data/lib/cli/commands/generate/generate_domain_object.rb +0 -71
  56. data/lib/cli/commands/generate/generate_domain_object/assignment_template.rb +0 -36
  57. data/lib/cli/commands/generate/generate_domain_object/option_formatter.rb +0 -30
  58. data/lib/cli/commands/generate/generate_lambda_package.rb +0 -20
  59. data/lib/cli/commands/generate/generate_resource_server.rb +0 -17
  60. data/lib/cli/commands/generate/new.rb +0 -47
  61. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +0 -16
  62. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%name%.rb.tt +0 -9
  63. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/repository.rb.tt +0 -40
  64. data/lib/cli/commands/generate/templates/binary_package/build/resources/Dockerfile.tt +0 -8
  65. data/lib/cli/commands/generate/templates/domain/%name%.gemspec.tt +0 -12
  66. data/lib/cli/commands/generate/templates/domain/Version +0 -1
  67. data/lib/cli/commands/generate/templates/domain/lib/%name%.rb.tt +0 -21
  68. data/lib/cli/commands/generate/templates/domain/spec/spec_helper.rb.tt +0 -4
  69. data/lib/cli/commands/generate/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +0 -25
  70. data/lib/cli/commands/generate/templates/resource_server/config.ru.tt +0 -8
  71. data/lib/cli/commands/generate/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +0 -24
  72. data/lib/cli/commands/test.rb +0 -41
  73. data/lib/domain_builder/attribute.rb +0 -33
  74. data/lib/domain_builder/domain.rb +0 -17
  75. data/lib/domain_builder/domain_builder.rb +0 -35
  76. data/lib/domain_builder/domain_module.rb +0 -26
  77. data/lib/domain_builder/domain_object.rb +0 -37
  78. data/lib/domain_builder/head.rb +0 -6
  79. data/lib/domain_builder/reference.rb +0 -17
  80. data/lib/domain_builder/value.rb +0 -6
@@ -1,71 +0,0 @@
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
@@ -1,36 +0,0 @@
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
@@ -1,30 +0,0 @@
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
@@ -1,20 +0,0 @@
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
@@ -1,17 +0,0 @@
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
@@ -1,47 +0,0 @@
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
@@ -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,9 +0,0 @@
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
@@ -1,40 +0,0 @@
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
@@ -1,8 +0,0 @@
1
- FROM ruby:2.2
2
-
3
- COPY <%= domain_name %>-0.0.0.gem /usr/src/app/<%= domain_name %>-0.0.0.gem
4
- RUN gem install /usr/src/app/<%= domain_name %>-0.0.0.gem
5
- COPY Gemfile /usr/src/app/Gemfile
6
- RUN cd /usr/src/app/ && bundle package
7
- RUN cd /usr/src/app/ && bundle install --path vendor
8
- RUN ls /usr/src/app/
@@ -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/**/*"]
11
- s.license = 'MIT'
12
- end
@@ -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__) + '/../HECKS'
20
- end
21
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'simplecov'
3
- SimpleCov.start
4
- require_relative '../lib/<%= name %>'
@@ -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,8 +0,0 @@
1
- require_relative "lib/<%= domain %>.rb"
2
- require 'hecks'
3
-
4
- run Hecks::Adapters::ResourceServer.new(
5
- application_adapter: Hecks::Adapters::Application.new(
6
- domain: <%= domain.camelize %>
7
- )
8
- )
@@ -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,41 +0,0 @@
1
- module Hecks
2
- class CLI < Thor
3
- include Thor::Actions
4
-
5
- desc 'test','Regenerate the examples and run the specs'
6
- def test
7
- reset_example('pizza_builder')
8
- build_binary_package('pizza_builder')
9
- build_lambda_package('pizza_builder')
10
- generate_resource_server('pizza_builder')
11
- run('rspec -f d')
12
- end
13
-
14
- desc 'test_pizza_builder','Regenerate the examples and run the specs'
15
- def test_pizza_builder
16
- reset_example('pizza_builder')
17
- end
18
-
19
- private
20
-
21
- def reset_example(name)
22
- run("cd spec/examples/#{name} && rm -rf lib")
23
- run("cd spec/examples/#{name} && rm -rf spec")
24
- run("cd spec/examples/#{name} && hecks new")
25
- end
26
-
27
- def build_binary_package(name)
28
- run("cd spec/examples/#{name} && hecks package binary")
29
- end
30
-
31
- def build_lambda_package(name)
32
- run("cd spec/examples/#{name} && hecks package lambda")
33
- end
34
-
35
- def generate_resource_server(name)
36
- run("cd spec/examples/#{name} && rm -rf config.ru")
37
- run("cd spec/examples/#{name} && hecks generate resource_server")
38
- run("cd spec/examples/#{name} && cd ../../..")
39
- end
40
- end
41
- end