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,60 +1,61 @@
1
- module Hecks
2
- module Domain
3
- class DomainBuilder
4
- class Attribute
5
- attr_writer :type
6
- attr_reader :object_name
7
-
8
- def initialize(string)
9
- @string = string
10
- @object_name = object_name
11
- end
12
-
13
- def list?
14
- @string.include?("[")
15
- end
16
-
17
- def name
18
- @string.split(":").first
19
- end
20
-
21
- def type
22
- return @type if @type
23
- @string.split(":").last.delete("[").delete("]").camelize
24
- end
25
-
26
- def domain_module
27
- return unless @string.include?("::")
28
- @string.split("::").first.split(":").last.camelize
29
- end
30
-
31
- def copy(new_values={})
32
- result = self.class.new(@string)
33
- result.type = new_values[:type] if new_values[:type]
34
- result
35
- end
36
-
37
- def reference?
38
- !primitive? && !list?
39
- end
40
-
41
- def referenced_object
42
- return unless reference?
43
- return @string.split("::").last if @string.include?("::")
44
- @string.split(":").last
45
- end
46
-
47
- def primitive?
48
- ['String', 'Integer', 'Currency'].include?(type)
49
- end
50
-
51
- def ==(other)
52
- return false if other.name != name
53
- return false if other.type != type
54
- return false if other.domain_module != domain_module
55
- return true
56
- end
57
- end
1
+ class HecksDomainBuilder
2
+ # A Domain Object attribute
3
+ class Attribute
4
+ attr_writer :type
5
+ attr_reader :object_name
6
+
7
+ def initialize(string)
8
+ @string = string
9
+ @object_name = object_name
10
+ end
11
+
12
+ def list?
13
+ @string.include?("[")
14
+ end
15
+
16
+ def name
17
+ @string.split(":").first
18
+ end
19
+
20
+ def type
21
+ return @type if @type
22
+ @string.split(":").last.delete("[").delete("]").camelize
23
+ end
24
+
25
+ def domain_module
26
+ return unless @string.include?("::")
27
+ @string.split("::").first.split(":").last.camelize
28
+ end
29
+
30
+ def copy(new_values={})
31
+ result = self.class.new(@string)
32
+ result.type = new_values[:type] if new_values[:type]
33
+ result
34
+ end
35
+
36
+ def reference?
37
+ !primitive? && !list?
38
+ end
39
+
40
+ def domain_reference?
41
+ @string.include?('::')
42
+ end
43
+
44
+ def referenced_object
45
+ return unless reference?
46
+ return @string.split("::").last if @string.include?("::")
47
+ @string.split(":").last
48
+ end
49
+
50
+ def primitive?
51
+ ['String', 'Integer', 'Currency'].include?(type)
52
+ end
53
+
54
+ def ==(other)
55
+ return false if other.name != name
56
+ return false if other.type != type
57
+ return false if other.domain_module != domain_module
58
+ return true
58
59
  end
59
60
  end
60
61
  end
@@ -1,19 +1,16 @@
1
- module Hecks
2
- module Domain
3
- class DomainBuilder
4
- class Domain
5
- attr_reader :domain_modules, :name
6
- def initialize(name:)
7
- @name = name
8
- @domain_modules = {}
9
- end
1
+ class HecksDomainBuilder
2
+ # A domain
3
+ class Domain
4
+ attr_reader :domain_modules, :name
5
+ def initialize(name:)
6
+ @name = name
7
+ @domain_modules = {}
8
+ end
10
9
 
11
- def module(name, &block)
12
- result = DomainModule.new(name: name)
13
- @domain_modules[name.to_sym] = result
14
- yield(result)
15
- end
16
- end
10
+ def module(name, &block)
11
+ result = DomainModule.new(name: name)
12
+ @domain_modules[name.to_sym] = result
13
+ yield(result)
17
14
  end
18
15
  end
19
16
  end
@@ -1,28 +1,32 @@
1
- module Hecks
2
- module Domain
3
- class DomainBuilder
4
- class DomainModule
5
- attr_reader :objects, :name, :references
1
+ class HecksDomainBuilder
2
+ # A domain module
3
+ class DomainModule
4
+ attr_reader :objects, :name, :references
6
5
 
7
- def initialize(name:)
8
- @name = name
9
- @objects = []
10
- @references = []
11
- end
6
+ def initialize(name:)
7
+ @name = name
8
+ @objects = []
9
+ @references = []
10
+ end
12
11
 
13
- def head(name=nil)
14
- return (@objects << Head.new(name: name)).last if name
15
- objects.find{ |o| o.is_a?(Head) }
16
- end
12
+ def head(name=nil)
13
+ return (@objects << Head.new(name: name)).last if name
14
+ objects.find{ |o| o.is_a?(Head) }
15
+ end
17
16
 
18
- def value(name)
19
- (@objects << Value.new(name: name)).last
20
- end
17
+ def value(name)
18
+ (@objects << Value.new(name: name)).last
19
+ end
20
+
21
+ def reference(name)
22
+ (@references << Reference.new(name)).last
23
+ end
21
24
 
22
- def reference(name)
23
- (@references << Reference.new(name)).last
24
- end
25
+ def find(name)
26
+ @objects.each do |object|
27
+ return object if object.name.downcase == name.downcase
25
28
  end
29
+ return nil
26
30
  end
27
31
  end
28
32
  end
@@ -1,43 +1,44 @@
1
- module Hecks
2
- module Domain
3
- class DomainBuilder
4
- class DomainObject
5
- attr_reader :name, :attributes
6
-
7
- def initialize(name:)
8
- @name = name
9
- end
10
-
11
- def attributes(*values)
12
- return @attributes if @attributes
13
- @attributes = values.map { |value| Hecks::Domain::DomainBuilder::Attribute.new(value) }
14
- end
15
-
16
- def attribute_hash
17
- attributes.map do |attribute|
18
- [attribute.name.to_sym, type_with_domain_module(attribute)]
19
- end.to_h
20
- end
21
-
22
- def attribute_string
23
- attributes.map do |attribute|
24
- [attribute.name, type_with_domain_module(attribute)].join(':')
25
- end
26
- end
27
-
28
- def references
29
- @attributes.reject(&:primitive?)
30
- end
31
-
32
- private
33
-
34
- def type_with_domain_module(attribute)
35
- type = DomainBuilder::Types.values.include?(attribute.type) ? "Value" : attribute.type
36
- type = '[' + type + ']' if attribute.list?
37
- return type unless attribute.domain_module
38
- [attribute.domain_module, type].join("::")
39
- end
1
+ class HecksDomainBuilder
2
+ # A Domain Object
3
+ class DomainObject
4
+ attr_reader :name, :attributes
5
+
6
+ def initialize(name:)
7
+ @name = name
8
+ end
9
+
10
+ def attributes(*values)
11
+ return @attributes if @attributes
12
+ @attributes = values.map { |value| Attribute.new(value) }
13
+ end
14
+
15
+ def attribute_hash
16
+ attributes.map do |attribute|
17
+ [attribute.name.to_sym, type_with_domain_module(attribute)]
18
+ end.to_h
19
+ end
20
+
21
+ def attribute_string
22
+ attributes.map do |attribute|
23
+ [attribute.name, type_with_domain_module(attribute)].join(':')
40
24
  end
41
25
  end
26
+
27
+ def references
28
+ @attributes.reject(&:primitive?)
29
+ end
30
+
31
+ def domain_references
32
+ @attributes.select(&:domain_reference?)
33
+ end
34
+
35
+ private
36
+
37
+ def type_with_domain_module(attribute)
38
+ type = Types.values.include?(attribute.type) ? "Value" : attribute.type
39
+ type = '[' + type + ']' if attribute.list?
40
+ return type unless attribute.domain_module
41
+ [attribute.domain_module, type].join("::")
42
+ end
42
43
  end
43
44
  end
@@ -1,8 +1,5 @@
1
- module Hecks
2
- module Domain
3
- class DomainBuilder
4
- class Head < DomainObject
5
- end
6
- end
1
+ class HecksDomainBuilder
2
+ # Points to the head object of a domain module
3
+ class Head < DomainObject
7
4
  end
8
5
  end
@@ -0,0 +1,37 @@
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
+ # Represents information about your domain
10
+ class HecksDomainBuilder
11
+ Types ||= {
12
+ string: 'String',
13
+ integer: 'Integer',
14
+ currency: 'Currency'
15
+ }
16
+
17
+ attr_accessor :domain, :specification, :name
18
+
19
+ def initialize(domain_name:, &block)
20
+ @name = domain_name
21
+ @domain = Domain.new(name: domain_name)
22
+ block.yield(@domain)
23
+ self
24
+ end
25
+
26
+ def domain_modules
27
+ @domain.domain_modules
28
+ end
29
+
30
+ def [](module_name)
31
+ domain_modules[module_name]
32
+ end
33
+
34
+ def self.build(domain_name, &block)
35
+ new(domain_name: domain_name, &block)
36
+ end
37
+ end
@@ -1,19 +1,16 @@
1
- module Hecks
2
- module Domain
3
- class DomainBuilder
4
- class Reference
5
- def initialize(reference)
6
- @reference = reference
7
- end
1
+ class HecksDomainBuilder
2
+ # Represents a reference object
3
+ class Reference
4
+ def initialize(reference)
5
+ @reference = reference
6
+ end
8
7
 
9
- def referenced_entity
10
- @reference.split("::").map(&:camelcase).join("::")
11
- end
8
+ def referenced_entity
9
+ @reference.split("::").map(&:camelcase).join("::")
10
+ end
12
11
 
13
- def name
14
- @reference.split("::").last.camelcase + "Reference"
15
- end
16
- end
12
+ def name
13
+ @reference.split("::").last.camelcase + "Reference"
17
14
  end
18
15
  end
19
16
  end
@@ -1,8 +1,5 @@
1
- module Hecks
2
- module Domain
3
- class DomainBuilder
4
- class Value < DomainObject
5
- end
6
- end
1
+ class HecksDomainBuilder
2
+ # A Value object
3
+ class Value < DomainObject
7
4
  end
8
5
  end
data/lib/hecks-domain.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require 'thor'
2
-
3
- require_relative 'adapters/adapters'
4
- require_relative 'domain_builder/domain_builder'
2
+ require_relative 'domain_builder/hecks-domain-builder'
5
3
  require_relative 'cli/cli'
6
4
  require 'active_support/inflector'
metadata CHANGED
@@ -1,65 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hecks-domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16.rc
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Young
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-15 00:00:00.000000000 Z
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.19'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.19'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activesupport
28
+ name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '0.19'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '0.19'
41
41
  description: Hecks Domain
42
42
  email: chris@example.com
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - lib/adapters/adapters.rb
48
- - lib/adapters/resource_server/cli/cli.rb
49
- - lib/adapters/resource_server/cli/generate_resource_server.rb
50
- - lib/adapters/resource_server/cli/templates/resource_server/config.ru.tt
51
- - lib/adapters/resource_server/resource_server.rb
52
- - lib/adapters/sql_database/cli/cli.rb
53
- - lib/adapters/sql_database/cli/generate_domain_migrations.rb
54
- - lib/adapters/sql_database/cli/generate_sql_database.rb
55
- - lib/adapters/sql_database/cli/migration_builder.rb
56
- - lib/adapters/sql_database/cli/templates/migration.rb.tt
57
- - lib/adapters/sql_database/cli/templates/repository.rb.tt
58
- - lib/adapters/sql_database/cli/templates/sql_database/Rakefile
59
- - lib/adapters/sql_database/commands/read/fetch_references.rb
60
- - lib/adapters/sql_database/commands/update/delete_references.rb
61
- - lib/adapters/sql_database/commands/update/link_to_references.rb
62
- - lib/adapters/sql_database/sql_database.rb
63
47
  - lib/cli/builder/aggregate_command_line_builder.rb
64
48
  - lib/cli/builder/builder.rb
65
49
  - lib/cli/builder/reference_command_line_builder.rb
@@ -81,10 +65,10 @@ files:
81
65
  - lib/cli/templates/value_object/lib/domain/%module_name%/%name%.rb.tt
82
66
  - lib/domain_builder/attribute.rb
83
67
  - lib/domain_builder/domain.rb
84
- - lib/domain_builder/domain_builder.rb
85
68
  - lib/domain_builder/domain_module.rb
86
69
  - lib/domain_builder/domain_object.rb
87
70
  - lib/domain_builder/head.rb
71
+ - lib/domain_builder/hecks-domain-builder.rb
88
72
  - lib/domain_builder/reference.rb
89
73
  - lib/domain_builder/value.rb
90
74
  - lib/hecks-domain.rb
@@ -103,9 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
87
  version: '0'
104
88
  required_rubygems_version: !ruby/object:Gem::Requirement
105
89
  requirements:
106
- - - ">"
90
+ - - ">="
107
91
  - !ruby/object:Gem::Version
108
- version: 1.3.1
92
+ version: '0'
109
93
  requirements: []
110
94
  rubyforge_project:
111
95
  rubygems_version: 2.6.10
@@ -1,2 +0,0 @@
1
- require_relative 'sql_database/sql_database'
2
- require_relative 'resource_server/resource_server'
@@ -1 +0,0 @@
1
- require_relative 'generate_resource_server'
@@ -1,25 +0,0 @@
1
- module Hecks
2
- module Domain
3
- module Adapters
4
- module ResourceServer
5
- module CLI
6
- class GenerateResourceServer < Thor::Group
7
- include Thor::Actions
8
-
9
- def self.source_root
10
- File.dirname(__FILE__) + '/templates/'
11
- end
12
-
13
- def create_aggregate_folder
14
- directory('resource_server', '.')
15
- end
16
-
17
- def domain
18
- File.basename(Dir.getwd)
19
- end
20
- end
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::Application.new(
6
- domain: <%= domain.camelize %>
7
- )
8
- )
@@ -1,3 +0,0 @@
1
- require_relative 'cli/cli'
2
- module Hecks
3
- end
@@ -1,3 +0,0 @@
1
- require_relative 'generate_domain_migrations'
2
- require_relative 'generate_sql_database'
3
- require_relative 'migration_builder'
@@ -1,33 +0,0 @@
1
- module Hecks
2
- module Domain
3
- module Adapters
4
- class SQLDatabase
5
- module CLI
6
- class GenerateDomainMigrations < Thor::Group
7
- include Thor::Actions
8
- attr_writer :migration_builder
9
-
10
- def load_domain_spec
11
- load('../../Domain')
12
- end
13
-
14
- def self.source_root
15
- File.dirname(__FILE__) + '/templates/'
16
- end
17
-
18
- def create_migration_file
19
- @migration_builder = MigrationBuilder.new(self, DOMAIN)
20
- @migration_builder.call
21
- end
22
-
23
- private
24
-
25
- def migration_builder
26
- @migration_builder
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,35 +0,0 @@
1
- module Hecks
2
- module Domain
3
- module Adapters
4
- class SQLDatabase
5
- module CLI
6
- class GenerateSQLDatabase < Thor::Group
7
- include Thor::Actions
8
-
9
- def self.source_root
10
- File.dirname(__FILE__) + '/templates/'
11
- end
12
-
13
- def create_sql_database_folder
14
- directory('sql_database', './adapters/sql_database')
15
- end
16
-
17
- def bundle
18
- run 'bundle'
19
- end
20
-
21
- private
22
-
23
- def class_name
24
- @class_name
25
- end
26
-
27
- def domain_module_name
28
- DOMAIN.name.camelize
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,51 +0,0 @@
1
- module Hecks
2
- module Domain
3
- module Adapters
4
- class SQLDatabase
5
- module CLI
6
- class MigrationBuilder
7
- def initialize(generator, specification)
8
- @generator = generator
9
- @schema = Hecks::Adapters::SQLDatabase::Schema.factory(specification)
10
- end
11
-
12
- def call
13
- generate_migrations
14
- self
15
- end
16
-
17
- def table_name
18
- @table.name
19
- end
20
-
21
- def columns
22
- @table.columns
23
- end
24
-
25
- def tables
26
- @schema.tables
27
- end
28
-
29
- private
30
-
31
- attr_reader :generator
32
-
33
- def file_name(index, object)
34
- "#{index}_create_#{table_name}.rb"
35
- end
36
-
37
- def generate_migrations
38
- tables.each.with_index(1) do |table, index|
39
- @table = table
40
- @generator.template(
41
- "migration.rb.tt",
42
- "db/migrate/" + file_name(index, table)
43
- )
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end