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,17 @@
1
+ require 'hecks'
2
+ require '<%= domain_name %>'
3
+
4
+ app = Hecks::Adapters::Application.new(domain: <%= domain_name.camelcase %>)
5
+
6
+ # Ruby 2.2.2 doesn't support Fixnum#positive?, so monkey patch it.
7
+ class Fixnum
8
+ def positive?
9
+ self > 0
10
+ end
11
+ end
12
+
13
+ domain_module = ARGV[0].to_sym
14
+ method = ARGV[1]
15
+ data = JSON.parse(ARGV[2], symbolize_names: true)
16
+
17
+ puts app[domain_module].send(method, data).call.result.inspect
@@ -0,0 +1,8 @@
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/
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'hecks'
4
+ gem '<%= domain_name %>'
@@ -0,0 +1,3 @@
1
+ BUNDLE_PATH: ./vendor
2
+ BUNDLE_WITHOUT: development
3
+ BUNDLE_DISABLE_SHARED_GEMS: '1'
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Figure out where this script is located.
5
+ SELFDIR="`dirname \"$0\"`"
6
+ SELFDIR="`cd \"$SELFDIR\" && pwd`"
7
+
8
+ # Tell Bundler where the Gemfile and gems are.
9
+ export BUNDLE_GEMFILE="$SELFDIR/lib/app/Gemfile"
10
+ unset BUNDLE_IGNORE_CONFIG
11
+
12
+ # Run the actual app using the bundled Ruby interpreter, with Bundler activated.
13
+ exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/<%= domain_name %>.rb" "$@"
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ require_relative '../lib/<%= name %>'
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const spawn = require('child_process').spawn;
4
+
5
+ module.exports.<%= domain_name %> = (event, context, callback) => {
6
+ var app = '<%= domain_name %>/<%= domain_name %>'
7
+ var data = JSON.stringify(event['data'])
8
+ var command = app + ' ' + event['module'] + ' ' + event['method'] + ' ' + JSON.stringify(data)
9
+ const child = exec(command, (result) => {
10
+ context.done(result);
11
+ });
12
+ };
@@ -0,0 +1,100 @@
1
+ # Welcome to Serverless!
2
+ #
3
+ # This file is the main config file for your service.
4
+ # It's very minimal at this point and uses default values.
5
+ # You can always add more config options for more control.
6
+ # We've included some commented out config examples here.
7
+ # Just uncomment any of them to get that config option.
8
+ #
9
+ # For full config options, check the docs:
10
+ # docs.serverless.com
11
+ #
12
+ # Happy Coding!
13
+
14
+ service: lambda
15
+
16
+ # You can pin your service to only deploy with a specific Serverless version
17
+ # Check out our docs for more details
18
+ # frameworkVersion: "=X.X.X"
19
+
20
+ provider:
21
+ name: aws
22
+ runtime: nodejs4.3
23
+
24
+ # you can overwrite defaults here
25
+ # stage: dev
26
+ # region: us-east-1
27
+
28
+ # you can add statements to the Lambda function's IAM Role here
29
+ # iamRoleStatements:
30
+ # - Effect: "Allow"
31
+ # Action:
32
+ # - "s3:ListBucket"
33
+ # Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
34
+ # - Effect: "Allow"
35
+ # Action:
36
+ # - "s3:PutObject"
37
+ # Resource:
38
+ # Fn::Join:
39
+ # - ""
40
+ # - - "arn:aws:s3:::"
41
+ # - "Ref" : "ServerlessDeploymentBucket"
42
+
43
+ # you can define service wide environment variables here
44
+ # environment:
45
+ # variable1: value1
46
+
47
+ # you can add packaging information here
48
+ #package:
49
+ # include:
50
+ # - include-me.js
51
+ # - include-me-dir/**
52
+ # exclude:
53
+ # - exclude-me.js
54
+ # - exclude-me-dir/**
55
+
56
+ functions:
57
+ <%= domain_name %>:
58
+ handler: handler.<%= domain_name %>
59
+
60
+ # The following are a few example events you can configure
61
+ # NOTE: Please make sure to change your handler code to work with those events
62
+ # Check the event documentation for details
63
+ # events:
64
+ # - http:
65
+ # path: users/create
66
+ # method: get
67
+ # - s3: ${env:BUCKET}
68
+ # - schedule: rate(10 minutes)
69
+ # - sns: greeter-topic
70
+ # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
71
+ # - alexaSkill
72
+ # - iot:
73
+ # sql: "SELECT * FROM 'some_topic'"
74
+ # - cloudwatchEvent:
75
+ # event:
76
+ # source:
77
+ # - "aws.ec2"
78
+ # detail-type:
79
+ # - "EC2 Instance State-change Notification"
80
+ # detail:
81
+ # state:
82
+ # - pending
83
+
84
+ # Define function environment variables here
85
+ # environment:
86
+ # variable2: value2
87
+
88
+ # you can add CloudFormation resource templates here
89
+ #resources:
90
+ # Resources:
91
+ # NewResource:
92
+ # Type: AWS::S3::Bucket
93
+ # Properties:
94
+ # BucketName: my-new-bucket
95
+ # Outputs:
96
+ # NewOutput:
97
+ # Description: "Description for the output"
98
+ # Value: "Some output value"
99
+ Plugins:
100
+ - serverless-offline
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,8 @@
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
+ )
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,16 @@
1
+ require_relative 'generate/generate_lambda_package'
2
+ require_relative 'generate/generate_binary_package'
3
+
4
+ class Package < Thor
5
+ desc 'lambda', 'lambda'
6
+ register GenerateLambdaPackage,
7
+ 'lambda',
8
+ 'lambda',
9
+ 'Generate Lambda Package'
10
+
11
+ desc 'binary', 'binary'
12
+ register GenerateBinaryPackage,
13
+ 'binary',
14
+ 'binary',
15
+ 'Generate Binary Package'
16
+ end
@@ -0,0 +1,41 @@
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
@@ -0,0 +1,9 @@
1
+ module Hecks
2
+ module Console
3
+ module Commands
4
+ def app
5
+ @app ||= Hecks::Adapters::Application.new(domain: Hecks::Console.domain)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ require 'irb'
2
+ require "irb/completion"
3
+ require "hecks"
4
+ require_relative 'commands'
5
+
6
+ module Hecks
7
+ module Console
8
+ def self.file
9
+ Dir.pwd.split('/').last
10
+ end
11
+
12
+ def self.full_path
13
+ Dir.pwd + "/lib/" + file
14
+ end
15
+
16
+ def self.domain
17
+ file.camelize.constantize
18
+ end
19
+
20
+ def self.domain_name
21
+ domain.to_s
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ module Hecks
2
+ class DomainBuilder
3
+ class Attribute
4
+ def initialize(string)
5
+ @string = string
6
+ end
7
+
8
+ def list?
9
+ @string.include?("[")
10
+ end
11
+
12
+ def name
13
+ @string.split(":").first
14
+ end
15
+
16
+ def type
17
+ @string.split(":").last.delete("[").delete("]").camelize
18
+ end
19
+
20
+ def domain_module
21
+ return unless @string.include?("::")
22
+ @string.split("::").first.split(":").last.camelize
23
+ end
24
+
25
+ def ==(other)
26
+ return false if other.name != name
27
+ return false if other.type != type
28
+ return false if other.domain_module != domain_module
29
+ return true
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module Hecks
2
+ class DomainBuilder
3
+ class Domain
4
+ attr_reader :domain_modules, :name
5
+ def initialize(name:)
6
+ @name = name
7
+ @domain_modules = {}
8
+ end
9
+
10
+ def module(name, &block)
11
+ result = DomainModule.new(name: name)
12
+ @domain_modules[name.to_sym] = result
13
+ yield(result)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'domain'
2
+ require_relative 'domain_module'
3
+ require_relative 'domain_object'
4
+ require_relative 'value'
5
+ require_relative 'head'
6
+ require_relative 'attribute'
7
+ require_relative 'reference'
8
+
9
+ module Hecks
10
+ def self.specification=(value)
11
+ @specification = value
12
+ end
13
+
14
+ def self.specification
15
+ @specification
16
+ end
17
+
18
+ class DomainBuilder
19
+ attr_accessor :domain, :specification
20
+
21
+ def initialize(domain_name:, &block)
22
+ @domain = Domain.new(name: domain_name)
23
+ block.yield(@domain)
24
+ self
25
+ end
26
+
27
+ def domain_modules
28
+ @domain.domain_modules
29
+ end
30
+
31
+ def self.build(domain_name, &block)
32
+ Hecks.specification = new(domain_name: domain_name, &block)
33
+ end
34
+ end
35
+ end