hecks-domain 0.1.0 → 0.1.2.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/lib/adapters/adapters.rb +2 -0
  3. data/lib/adapters/resource_server/cli/cli.rb +1 -0
  4. data/lib/adapters/resource_server/cli/generate_resource_server.rb +25 -0
  5. data/lib/adapters/resource_server/cli/templates/resource_server/config.ru.tt +8 -0
  6. data/lib/adapters/resource_server/resource_server.rb +3 -0
  7. data/lib/adapters/sql_database/cli/cli.rb +3 -0
  8. data/lib/adapters/sql_database/cli/generate_domain_migrations.rb +33 -0
  9. data/lib/adapters/sql_database/cli/generate_sql_database.rb +35 -0
  10. data/lib/adapters/sql_database/cli/migration_builder.rb +51 -0
  11. data/lib/adapters/sql_database/cli/templates/migration.rb.tt +14 -0
  12. data/lib/adapters/sql_database/cli/templates/repository.rb.tt +24 -0
  13. data/lib/adapters/sql_database/cli/templates/sql_database/Rakefile +15 -0
  14. data/lib/adapters/sql_database/commands/read/fetch_references.rb +58 -0
  15. data/lib/adapters/sql_database/commands/update/delete_references.rb +45 -0
  16. data/lib/adapters/sql_database/commands/update/link_to_references.rb +45 -0
  17. data/lib/adapters/sql_database/sql_database.rb +1 -0
  18. data/lib/cli/builder/aggregate_command_line_builder.rb +22 -0
  19. data/lib/cli/builder/builder.rb +3 -0
  20. data/lib/cli/builder/reference_command_line_builder.rb +23 -0
  21. data/lib/cli/builder/value_object_command_line_builder.rb +23 -0
  22. data/lib/cli/cli.rb +8 -0
  23. data/lib/cli/command_builder.rb +60 -0
  24. data/lib/cli/domain_object/assignment_template.rb +43 -0
  25. data/lib/cli/domain_object/option_formatter.rb +36 -0
  26. data/lib/cli/generate_domain_object.rb +71 -0
  27. data/lib/cli/new.rb +50 -0
  28. data/lib/cli/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +16 -0
  29. data/lib/cli/templates/aggregate/lib/domain/%name%/%name%.rb.tt +9 -0
  30. data/lib/cli/templates/aggregate/lib/domain/%name%/repository.rb.tt +41 -0
  31. data/lib/cli/templates/domain/%name%.gemspec.tt +12 -0
  32. data/lib/cli/templates/domain/Version +1 -0
  33. data/lib/cli/templates/domain/lib/%name%.rb.tt +21 -0
  34. data/lib/cli/templates/domain/spec/spec_helper.rb.tt +4 -0
  35. data/lib/cli/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +25 -0
  36. data/lib/cli/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +24 -0
  37. data/lib/domain_builder/attribute.rb +60 -0
  38. data/lib/domain_builder/domain.rb +19 -0
  39. data/lib/domain_builder/domain_builder.rb +37 -0
  40. data/lib/domain_builder/domain_module.rb +28 -0
  41. data/lib/domain_builder/domain_object.rb +43 -0
  42. data/lib/domain_builder/head.rb +8 -0
  43. data/lib/domain_builder/reference.rb +19 -0
  44. data/lib/domain_builder/value.rb +8 -0
  45. data/lib/hecks-domain.rb +6 -0
  46. metadata +58 -101
  47. data/lib/hecks/domain/commands/generate.rb +0 -98
  48. data/lib/hecks/domain/commands.rb +0 -1
  49. data/lib/hecks/domain/generators/domain.rb +0 -21
  50. data/lib/hecks/domain/generators/domain_files.rb +0 -28
  51. data/lib/hecks/domain/generators/entity.rb +0 -30
  52. data/lib/hecks/domain/generators/operation.rb +0 -32
  53. data/lib/hecks/domain/generators/root.rb +0 -30
  54. data/lib/hecks/domain/generators/spec.rb +0 -30
  55. data/lib/hecks/domain/generators/value_object.rb +0 -30
  56. data/lib/hecks/domain/generators.rb +0 -7
  57. data/lib/hecks/domain/parser/aggregate.rb +0 -44
  58. data/lib/hecks/domain/parser/domain_object.rb +0 -123
  59. data/lib/hecks/domain/parser/entity_field.rb +0 -55
  60. data/lib/hecks/domain/parser/fields.rb +0 -16
  61. data/lib/hecks/domain/parser/list_field.rb +0 -13
  62. data/lib/hecks/domain/parser/operation.rb +0 -15
  63. data/lib/hecks/domain/parser/reference_field.rb +0 -12
  64. data/lib/hecks/domain/parser/spec_helper.rb +0 -0
  65. data/lib/hecks/domain/parser/value_field.rb +0 -48
  66. data/lib/hecks/domain/parser.rb +0 -95
  67. data/lib/hecks/domain/support/string.rb +0 -9
  68. data/lib/hecks/domain/support.rb +0 -1
  69. data/lib/hecks/domain/templates/%domain_name%.gemspec.tt +0 -12
  70. data/lib/hecks/domain/templates/%folder_name%/Domainfile.tt +0 -9
  71. data/lib/hecks/domain/templates/%folder_name%/events/command_will_run.rb.tt +0 -11
  72. data/lib/hecks/domain/templates/%folder_name%/spec/spec_helper.rb.tt +0 -1
  73. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/commands.rb.tt +0 -11
  74. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/events.rb.tt +0 -11
  75. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +0 -37
  76. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories.rb.tt +0 -11
  77. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/invariants.rb.tt +0 -11
  78. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/queries.rb.tt +0 -11
  79. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/repository.rb.tt +0 -68
  80. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/subscribers.rb.tt +0 -11
  81. data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%.rb.tt +0 -34
  82. data/lib/hecks/domain/templates/lib/%domain_name%.rb.tt +0 -9
  83. data/lib/hecks/domain/templates/lib/support/commands/command_loader.rb +0 -18
  84. data/lib/hecks/domain/templates/lib/support/commands/command_runner.rb +0 -17
  85. data/lib/hecks/domain/templates/lib/support/commands.rb +0 -2
  86. data/lib/hecks/domain/templates/lib/support/domain_object.rb +0 -25
  87. data/lib/hecks/domain/templates/lib/support/events/domain_event.rb +0 -14
  88. data/lib/hecks/domain/templates/lib/support/events/domain_event_publisher.rb +0 -34
  89. data/lib/hecks/domain/templates/lib/support/events.rb +0 -14
  90. data/lib/hecks/domain/templates/lib/support/factories/factory_loader.rb +0 -21
  91. data/lib/hecks/domain/templates/lib/support/factories.rb +0 -1
  92. data/lib/hecks/domain/templates/lib/support/invariants/invariant_loader.rb +0 -24
  93. data/lib/hecks/domain/templates/lib/support/queries/query_loader.rb +0 -18
  94. data/lib/hecks/domain/templates/lib/support/queries.rb +0 -1
  95. data/lib/hecks/domain/templates/lib/support/repositories/repository_loader.rb +0 -32
  96. data/lib/hecks/domain/templates/lib/support/root.rb +0 -27
  97. data/lib/hecks/domain/templates/lib/support/support/string.rb +0 -9
  98. data/lib/hecks/domain/templates/lib/support.rb +0 -11
  99. data/lib/hecks/domain/templates/operation/%aggregate_name%/%domain_object_name%/commands/%operation_name%.rb.tt +0 -21
  100. data/lib/hecks/domain/templates/root/%aggregate_name%/root.rb.tt +0 -14
  101. data/lib/hecks/domain/templates/spec/%aggregate_name%/%root_name%_spec.rb.tt +0 -12
  102. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +0 -37
  103. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories.rb.tt +0 -11
  104. data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%.rb.tt +0 -34
  105. data/lib/hecks/domain/top_level_methods.rb +0 -3
  106. data/lib/hecks/domain.rb +0 -22
@@ -1,17 +0,0 @@
1
- class Support
2
- module Commands
3
- module CommandRunner
4
- def self.run(command, &block)
5
- Events::DomainEventPublisher.emit(
6
- const_get(command.class.to_s.split('::')[0])::
7
- Events::CommandWillRun.new(command)
8
- )
9
-
10
- command.call
11
- command.root.test_invariants(command)
12
- Events::DomainEventPublisher.emit(command, &block)
13
- command
14
- end
15
- end
16
- end
17
- end
@@ -1,2 +0,0 @@
1
- require_relative 'commands/command_runner'
2
- require_relative 'commands/command_loader'
@@ -1,25 +0,0 @@
1
- class Support
2
- module DomainObject
3
- TYPES = %w[services invariants factories].freeze
4
-
5
- LOADERS = [
6
- Support::Factories::FactoryLoader, Support::Invariants::InvariantLoader
7
- ].freeze
8
-
9
- def self.included(base)
10
- path = [
11
- '../../domain',
12
- base.to_s.split('::')[-2].underscore.downcase,
13
- base.to_s.split('::')[-1].underscore.downcase
14
- ].join('/')
15
-
16
- TYPES.each do |name|
17
- Dir[File.dirname(__FILE__) + "/#{path}/" + name + '/*.rb'].each do |file|
18
- require_relative file
19
- end
20
- end
21
-
22
- LOADERS.each { |loader| base.include(loader) }
23
- end
24
- end
25
- end
@@ -1,14 +0,0 @@
1
- class Support
2
- module Events
3
- class DomainEvent
4
- attr_reader :type, :name, :command, :args, :root
5
- def initialize(command)
6
- @command = command
7
- @root = @command.root
8
- @type = @command.class
9
- @name = @type.to_s.underscore
10
- @args = command.args
11
- end
12
- end
13
- end
14
- end
@@ -1,34 +0,0 @@
1
- class Support
2
- module Events
3
- class DomainEventPublisher
4
- include Singleton
5
- attr_reader :subscribers
6
- def initialize
7
- @subscribers = []
8
- end
9
-
10
- def self.emit(command, &block)
11
- instance.emit(DomainEvent.new(command), &block)
12
- end
13
-
14
- def self.subscribe(subscriber)
15
- instance.subscribers << subscriber
16
- end
17
-
18
- def self.cancel_subscription(subscriber)
19
- instance.subscribers.delete(subscriber)
20
- end
21
-
22
- def emit(domain_event, &block)
23
- yield domain_event if block
24
- @subscribers.each do |subscriber|
25
- next unless subscriber.domain_event == '*' ||
26
- subscriber.domain_event == domain_event.type
27
-
28
- subscriber.notify(domain_event)
29
- end
30
- end
31
- end
32
- end
33
- end
34
-
@@ -1,14 +0,0 @@
1
- require_relative 'events/domain_event_publisher'
2
- require_relative 'events/domain_event'
3
-
4
- class Support
5
- module Events
6
- def self.subscribe(subscriber)
7
- DomainEventPublisher.subscribe(subscriber)
8
- end
9
-
10
- def self.cancel_subscription(subscriber)
11
- DomainEventPublisher.cancel_subscription(subscriber)
12
- end
13
- end
14
- end
@@ -1,21 +0,0 @@
1
- class Support
2
- module Factories
3
- module FactoryLoader
4
- def self.included(base)
5
- return unless base.constants.include?(:Factories)
6
- base::Factories.constants.each do |constant|
7
- base.class_eval "
8
- def #{constant.to_s.underscore}(*args)
9
- #{base}::Factories::#{constant}.factory(self, *args)
10
- end
11
- "
12
- base.instance_eval "
13
- def #{constant.to_s.underscore}(*args)
14
- #{base}::Factories::#{constant}.factory(*args)
15
- end
16
- "
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1 +0,0 @@
1
- require_relative 'factories/factory_loader'
@@ -1,24 +0,0 @@
1
- class Support
2
- module Invariants
3
- module InvariantLoader
4
- def self.included(base)
5
- return unless base.constants.include?(:Invariants)
6
- base::Invariants.constants.each do |invariant|
7
- base.include base::Invariants.const_get(invariant)
8
- end
9
- end
10
-
11
- def test_invariants(command = nil)
12
- return unless self.class.constants.include?(:Invariants)
13
- self.class::Invariants.constants.each do |invariant|
14
- invariant_class = self.class::Invariants.const_get(invariant)
15
- invariant_class.instance_methods(false).each do |method|
16
- raise "invariant methods must be prepended with \"invariant_test\". Try:\n" +
17
- "#{invariant_class}#invariant_test_#{method.to_s}" unless method.to_s =~ /^invariant.*/
18
- send(method, command)
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,18 +0,0 @@
1
- class Support
2
- module Queries
3
- module QueryLoader
4
- def self.included(base)
5
- return unless base.constants.include?(:Queries)
6
- base::Queries.constants.each do |constant|
7
- raise "Query name `#{constant}` not valid. Query classes must start with 'Find'" unless constant.to_s.underscore =~ /^find_.*/
8
-
9
- base.class_eval "
10
- def #{constant.to_s.underscore}(*args, &block)
11
- Queries::#{constant}.query(self, *args)
12
- end
13
- "
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1 +0,0 @@
1
- require_relative 'queries/query_loader'
@@ -1,32 +0,0 @@
1
- class Support
2
- module Repositories
3
- module RepositoryLoader
4
- def self.included(base)
5
- base.class_eval do
6
- def save
7
- test_invariants
8
- self.class::Repository.save(self)
9
- end
10
-
11
- def destroy
12
- self.class::Repository.destroy(self)
13
- end
14
- end
15
-
16
- base.instance_eval do
17
- def create(domain_object = nil)
18
- self::Repository.create(domain_object).tap(&:test_invariants)
19
- end
20
-
21
- def fetch(fetchable)
22
- self::Repository.fetch(fetchable)
23
- end
24
-
25
- def all
26
- self::Repository.all
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,27 +0,0 @@
1
- class Support
2
- module Root
3
- TYPES = %w[commands services invariants queries events subscribers].freeze
4
-
5
- LOADERS = [
6
- Support::Commands::CommandLoader, Support::Queries::QueryLoader,
7
- Support::Repositories::RepositoryLoader
8
- ].freeze
9
-
10
- def self.included(base)
11
- path = [
12
- '../../domain',
13
- base.to_s.split('::')[-2].underscore.downcase,
14
- base.to_s.split('::')[-1].underscore.downcase
15
- ].join('/')
16
-
17
- require_relative path + '/repository'
18
-
19
- TYPES.each do |name|
20
- Dir[File.dirname(__FILE__) + "/#{path}/" + name + '/*.rb']
21
- .each { |file| require_relative file }
22
- end
23
-
24
- LOADERS.each { |loader| base.include(loader) }
25
- end
26
- end
27
- end
@@ -1,9 +0,0 @@
1
- class String
2
- def underscore
3
- self.gsub(/::/, '/').
4
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
- tr("-", "_").
7
- downcase
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- require 'singleton'
2
- require_relative 'support/repositories/repository_loader'
3
- require_relative 'support/support/string'
4
- require_relative 'support/events'
5
- require_relative 'support/commands'
6
- require_relative 'support/queries'
7
- require_relative 'support/factories'
8
- require_relative 'support/invariants/invariant_loader'
9
- require_relative 'support/queries/query_loader'
10
- require_relative 'support/root'
11
- require_relative 'support/domain_object'
@@ -1,21 +0,0 @@
1
- module <%= @domain_object.aggregate.domain.name %>
2
- module Domain
3
- module <%= aggregate.name%>
4
- class <%= domain_object.name %>
5
- module Commands
6
- class <%= operation.name %>
7
- attr_reader :root, :args
8
-
9
- def initialize(root, args={})
10
- @root = root
11
- @args = args
12
- end
13
-
14
- def call
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,14 +0,0 @@
1
- require_relative '<%= root.name.to_s.underscore %>'
2
- <% root.aggregate.domain_objects.each do |domain_object| -%>
3
- <% next if domain_object.is_a?(HecksDomain::Parser::Root) -%>
4
- require_relative '<%= domain_object.name.to_s.underscore %>'
5
- <% end -%>
6
-
7
- module <%= domain.name %>
8
- module Domain
9
- module <%= aggregate.name %>
10
- class Root < <%= root.name %>
11
- end
12
- end
13
- end
14
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe <%= "#{domain.name}::Domain::#{aggregate.name}::#{root.name}" %> do
4
- subject { described_class.new }
5
-
6
- <% root.operations_get.each do |operation| -%>
7
- describe '#<%= operation.name.to_s.underscore %>' do
8
- xit 'should behave' do
9
- end
10
- end
11
- <% end -%>
12
- end
@@ -1,37 +0,0 @@
1
- module <%= @domain.name %>
2
- module Domain
3
- module <%= @aggregate.name%>
4
- class <%= @domain_object.name %>
5
- module Factories
6
- # Recursively build domain objects. Used in the domain as the primary
7
- # factory. The results of #build can be passed to any other build
8
- # factory in the domain. Takes a hash, or a list of hashes. If a list
9
- # is given, it will return a list of the instantiated objects
10
- class Build
11
- def self.factory(args=nil)
12
- return args if args.nil?
13
- return args unless args.is_a?(Hash)
14
-
15
- [args].flatten.map do |domain_object_args|
16
- new_domain_object(domain_object_args)
17
- end.tap do |result|
18
- return result.first unless args.is_a?(Array)
19
- end
20
- end
21
-
22
- def self.new_domain_object(args)
23
- <%= @domain_object.name %>.new(
24
- args.merge(
25
- <% @domain_object.fields.each do |field| -%>
26
- <% next unless (field.respond_to?(:module_name) && field.module_name) -%>
27
- <%= field.name.to_s%>: <%= field.module_name.is_a?(Hash) ? 'Domain::' + field.module_name.to_a.join('::').to_s : field.module_name.to_s %>.build(args[:<%= field.name.to_s%>]),
28
- <% end -%>
29
- )
30
- )
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,11 +0,0 @@
1
- Dir[File.dirname(__FILE__) + '/factories/*.rb'].each {|file| require_relative file }
2
- module <%= domain.name %>
3
- module Domain
4
- module <%= aggregate.name %>
5
- class <%= domain_object.name %>
6
- module Factories
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,34 +0,0 @@
1
- module <%= domain.name %>
2
- module Domain
3
- module <%= aggregate.name %>
4
- class <%= domain_object.name %>
5
- <%= 'include Support::Root' if domain_object.is_a?(HecksDomain::Parser::Root) %>
6
- include Support::DomainObject
7
-
8
- attr_reader <%= domain_object.public_accessors %>
9
-
10
- def initialize(<%= domain_object.initializer_attributes %>)
11
- <% domain_object.fields.each do |field| -%>
12
- <%= "@#{field.name} = #{field.initial_state}" %>
13
- <% end -%>
14
- end
15
- <% domain_object.boolean_accessors.each do |field| -%>
16
-
17
- def <%= field.name %>?
18
- @<%= field.name %>
19
- end
20
- <% end -%>
21
- <% domain_object.list_accessors.each do |field| -%>
22
-
23
- def <%= field.name %>
24
- @<%= field.name %>.clone.freeze
25
- end
26
- <% end -%>
27
-
28
- private
29
-
30
- attr_writer <%= domain_object.private_accessors %>
31
- end
32
- end
33
- end
34
- end
@@ -1,3 +0,0 @@
1
- def domain(name, &block)
2
- HecksDomain.parser(name, &block)
3
- end
data/lib/hecks/domain.rb DELETED
@@ -1,22 +0,0 @@
1
- require 'colorize'
2
- require 'singleton'
3
- require 'erubis'
4
- require 'thor'
5
- require 'fileutils'
6
-
7
- require_relative 'domain/top_level_methods'
8
- require_relative 'domain/support'
9
- require_relative 'domain/parser'
10
- require_relative 'domain/generators'
11
- require_relative 'domain/commands'
12
-
13
- class HecksDomain
14
- attr_reader :domain
15
- def initialize(name, &block)
16
- @domain = Parser.new(name, &block)
17
- end
18
-
19
- def self.parser(name, &block)
20
- new name, &block
21
- end
22
- end