hecks-domain 0.1.16.rc → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cli/builder/aggregate_command_line_builder.rb +15 -16
  3. data/lib/cli/builder/reference_command_line_builder.rb +15 -16
  4. data/lib/cli/builder/value_object_command_line_builder.rb +15 -16
  5. data/lib/cli/command_builder.rb +50 -45
  6. data/lib/cli/domain_object/assignment_template.rb +30 -31
  7. data/lib/cli/domain_object/option_formatter.rb +24 -25
  8. data/lib/cli/generate_domain_object.rb +50 -51
  9. data/lib/cli/new.rb +44 -45
  10. data/lib/cli/templates/aggregate/lib/domain/%name%/repository.rb.tt +2 -5
  11. data/lib/domain_builder/attribute.rb +58 -57
  12. data/lib/domain_builder/domain.rb +12 -15
  13. data/lib/domain_builder/domain_module.rb +24 -20
  14. data/lib/domain_builder/domain_object.rb +40 -39
  15. data/lib/domain_builder/head.rb +3 -6
  16. data/lib/domain_builder/hecks-domain-builder.rb +37 -0
  17. data/lib/domain_builder/reference.rb +11 -14
  18. data/lib/domain_builder/value.rb +3 -6
  19. data/lib/hecks-domain.rb +1 -3
  20. metadata +11 -27
  21. data/lib/adapters/adapters.rb +0 -2
  22. data/lib/adapters/resource_server/cli/cli.rb +0 -1
  23. data/lib/adapters/resource_server/cli/generate_resource_server.rb +0 -25
  24. data/lib/adapters/resource_server/cli/templates/resource_server/config.ru.tt +0 -8
  25. data/lib/adapters/resource_server/resource_server.rb +0 -3
  26. data/lib/adapters/sql_database/cli/cli.rb +0 -3
  27. data/lib/adapters/sql_database/cli/generate_domain_migrations.rb +0 -33
  28. data/lib/adapters/sql_database/cli/generate_sql_database.rb +0 -35
  29. data/lib/adapters/sql_database/cli/migration_builder.rb +0 -51
  30. data/lib/adapters/sql_database/cli/templates/migration.rb.tt +0 -14
  31. data/lib/adapters/sql_database/cli/templates/repository.rb.tt +0 -24
  32. data/lib/adapters/sql_database/cli/templates/sql_database/Rakefile +0 -15
  33. data/lib/adapters/sql_database/commands/read/fetch_references.rb +0 -58
  34. data/lib/adapters/sql_database/commands/update/delete_references.rb +0 -45
  35. data/lib/adapters/sql_database/commands/update/link_to_references.rb +0 -45
  36. data/lib/adapters/sql_database/sql_database.rb +0 -1
  37. data/lib/domain_builder/domain_builder.rb +0 -37
@@ -1,14 +0,0 @@
1
- Sequel.migration do
2
- up do
3
- create_table(:<%= migration_builder.table_name %>) do
4
- primary_key :id
5
- <%- migration_builder.columns.each do |column| -%>
6
- <%= column.type.camelcase %> :<%= column.name.to_sym %>, :null=>false
7
- <%- end -%>
8
- end
9
- end
10
-
11
- down do
12
- drop_table(:<%= migration_builder.table_name %>)
13
- end
14
- end
@@ -1,24 +0,0 @@
1
- module <%= domain_module_name %>
2
- module Adapters
3
- class SQLDatabase
4
- module Repositories
5
- class <%= class_name %>
6
- def self.create attributes = {}
7
- end
8
-
9
- def self.update id, attributes
10
- end
11
-
12
- def self.read id
13
- end
14
-
15
- def self.delete id
16
- end
17
-
18
- def self.delete_all
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,15 +0,0 @@
1
- namespace :db do
2
- desc "Run migrations"
3
- task :migrate, [:version] do |t, args|
4
- require "sequel"
5
- Sequel.extension :migration
6
- db = Sequel.connect(ENV.fetch("DATABASE_URL"))
7
- if args[:version]
8
- puts "Migrating to version #{args[:version]}"
9
- Sequel::Migrator.run(db, "db/migrate", target: args[:version].to_i)
10
- else
11
- puts "Migrating to latest"
12
- Sequel::Migrator.run(db, "db/migrate")
13
- end
14
- end
15
- end
@@ -1,58 +0,0 @@
1
- module Hecks
2
- module Domain
3
- module Adapters
4
- class SQLDatabase
5
- module Commands
6
- class Read
7
- class FetchReferences
8
- attr_reader :reference_map
9
- def initialize(read_command)
10
- @head = read_command.head
11
- @reference_map = {}
12
- @entity = read_command.entity
13
- @table = read_command.table
14
- @id = read_command.id
15
- end
16
-
17
- def call
18
- @head.references.each do |reference|
19
- fetch_reference(reference)
20
- fetch_references(reference)
21
- end
22
- self
23
- end
24
-
25
- private
26
-
27
- def fetch_reference(reference)
28
- return if reference.list?
29
- column = Column.factory(reference)
30
- value = DB[column.to_table_name].first(id: @entity[column.to_foreign_key])
31
-
32
- @entity.delete(column.to_foreign_key)
33
- value.delete(:id)
34
- @reference_map[column.name.to_sym] = value
35
- end
36
-
37
- def fetch_references(reference)
38
- return unless reference.list?
39
-
40
- where_clause = {}
41
- where_clause[@table.to_foreign_key.to_sym] = @id
42
- column = Column.factory(reference)
43
-
44
- @reference_map[column.name.to_sym] ||= []
45
-
46
- DB[JoinTable(@table, reference).name.to_sym].where(where_clause).map do |record|
47
- value_object = DB[column.to_table_name].first(id: record[column.to_foreign_key])
48
- value_object.delete(:id)
49
- @reference_map[column.name.to_sym] << value_object
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,45 +0,0 @@
1
- module Hecks
2
- module Domain
3
- module Adapters
4
- class SQLDatabase
5
- module Commands
6
- class Update
7
- class DeleteReferences
8
- attr_reader :attributes
9
-
10
- def initialize(table:, attributes:, reference:)
11
- @table = table
12
- @attributes = attributes
13
- @reference = reference
14
- @where_clause = {}
15
- @dataset = DB[JoinTable.new(@table, @reference).name.to_sym]
16
- end
17
-
18
- def call
19
- build_where_clause
20
- delete_references
21
- remove_references_from_attributes
22
- self
23
- end
24
-
25
- private
26
-
27
- def build_where_clause
28
- DB[JoinTable.new(@table, @reference).name.to_sym]
29
- end
30
-
31
- def remove_references_from_attributes
32
- @attributes.delete(@reference.name.to_sym)
33
- end
34
-
35
- def delete_references
36
- return unless @reference.list?
37
- @dataset.where(@where_clause).delete
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,45 +0,0 @@
1
- module Hecks
2
- module Domain
3
- module Adapters
4
- class SQLDatabase
5
- module Commands
6
- class Update
7
- class LinkToReferences
8
- attr_reader :reference_ids
9
- def initialize(reference:, table:, reference_ids:, attributes:)
10
- @reference = reference
11
- @reference_ids = reference_ids
12
- @table = table
13
- @attributes = attributes
14
- @column = Column.factory(@reference)
15
- @record = {}
16
- end
17
-
18
- def call
19
- make_linking_records
20
- make_foreign_keys
21
- self
22
- end
23
-
24
- private
25
-
26
- def make_linking_records
27
- return unless @reference.list?
28
- @reference_ids[@reference.name.to_sym].each do |value|
29
- @record[@column.to_foreign_key] = value
30
- @record[@table.to_foreign_key] = @attributes[:id]
31
- DB[JoinTable.new(@table, @reference).name.to_sym].insert(@record)
32
- end
33
- end
34
-
35
- def make_foreign_keys
36
- return if @reference.list?
37
- @attributes[@column.to_foreign_key] = @reference_ids[@reference.name]
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1 +0,0 @@
1
- require_relative 'cli/cli'
@@ -1,37 +0,0 @@
1
- require_relative 'attribute'
2
- require_relative 'domain'
3
- require_relative 'domain_module'
4
- require_relative 'domain_object'
5
- require_relative 'value'
6
- require_relative 'head'
7
- require_relative 'reference'
8
-
9
- module Hecks
10
- module Domain
11
- class DomainBuilder
12
- Types = { string: 'String', integer: 'Integer', currency: 'Currency'}
13
-
14
- attr_accessor :domain, :specification, :name
15
-
16
- def initialize(domain_name:, &block)
17
- @name = domain_name
18
- @domain = Domain.new(name: domain_name)
19
- block.yield(@domain)
20
- self
21
- end
22
-
23
- def domain_modules
24
- @domain.domain_modules
25
- end
26
-
27
- def [](module_name)
28
- domain_modules[module_name]
29
- end
30
-
31
-
32
- def self.build(domain_name, &block)
33
- new(domain_name: domain_name, &block)
34
- end
35
- end
36
- end
37
- end