activefacts-compositions 1.9.22 → 1.9.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/activefacts-compositions.gemspec +1 -1
- data/bin/schema_compositor +71 -27
- data/lib/activefacts/compositions/binary.rb +4 -0
- data/lib/activefacts/compositions/datavault.rb +4 -0
- data/lib/activefacts/compositions/relational.rb +4 -0
- data/lib/activefacts/compositions/staging.rb +4 -0
- data/lib/activefacts/compositions/version.rb +1 -1
- data/lib/activefacts/generator/doc/css/glossary-print.css +72 -0
- data/lib/activefacts/generator/doc/css/glossary.css +194 -0
- data/lib/activefacts/generator/doc/css/ldm.css +12 -17
- data/lib/activefacts/generator/doc/css/orm2-print.css +19 -0
- data/lib/activefacts/generator/doc/css/orm2.css +28 -0
- data/lib/activefacts/generator/doc/css/reset.css +18 -0
- data/lib/activefacts/generator/doc/css/treetable.css +83 -0
- data/lib/activefacts/generator/doc/cwm.rb +60 -54
- data/lib/activefacts/generator/doc/glossary.rb +261 -137
- data/lib/activefacts/generator/doc/graphviz.rb +6 -2
- data/lib/activefacts/generator/doc/ldm.rb +7 -3
- data/lib/activefacts/generator/etl/unidex.rb +7 -2
- data/lib/activefacts/generator/oo.rb +2 -1
- data/lib/activefacts/generator/population.rb +174 -0
- data/lib/activefacts/generator/rails/active_admin.rb +81 -0
- data/lib/activefacts/generator/rails/application_record_shell.rb +78 -0
- data/lib/activefacts/generator/rails/models.rb +31 -72
- data/lib/activefacts/generator/rails/ruby_folder_generator.rb +87 -0
- data/lib/activefacts/generator/rails/schema.rb +12 -4
- data/lib/activefacts/generator/ruby.rb +7 -3
- data/lib/activefacts/generator/sql.rb +2 -1
- data/lib/activefacts/generator/summary.rb +24 -19
- data/lib/activefacts/generator/traits/sql.rb +4 -0
- data/lib/activefacts/generator/transgen.rb +7 -1
- data/lib/activefacts/generator/validate.rb +10 -2
- metadata +15 -5
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# ActiveFacts Rails Models Generator
|
3
|
+
#
|
4
|
+
# Copyright (c) 2018 Daniel Heath. Read the LICENSE file.
|
5
|
+
#
|
6
|
+
require 'digest/sha1'
|
7
|
+
require 'activefacts/metamodel'
|
8
|
+
require 'activefacts/compositions'
|
9
|
+
require 'activefacts/generator'
|
10
|
+
require 'activefacts/compositions/traits/rails'
|
11
|
+
require 'fileutils'
|
12
|
+
|
13
|
+
module ActiveFacts
|
14
|
+
module Generators
|
15
|
+
module Rails
|
16
|
+
module RubyFolderGenerator
|
17
|
+
HEADER = "# Auto-generated (edits will be lost) using:"
|
18
|
+
|
19
|
+
def warn *a
|
20
|
+
$stderr.puts *a
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate
|
24
|
+
record_extant_files_to_remove
|
25
|
+
|
26
|
+
@ok = true
|
27
|
+
result = generate_files
|
28
|
+
|
29
|
+
warn "\# #{@composition.name} generated with errors" unless @ok
|
30
|
+
delete_old_generated_files if @option_output && !@option_keep
|
31
|
+
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def record_extant_files_to_remove
|
36
|
+
@preexisting_files = []
|
37
|
+
return if @option_keep
|
38
|
+
@preexisting_files = extant_files || []
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_old_generated_files
|
42
|
+
remaining = []
|
43
|
+
cleaned = 0
|
44
|
+
@preexisting_files.each do |pathname|
|
45
|
+
if generated_file_exists(pathname) == true
|
46
|
+
File.unlink(pathname)
|
47
|
+
cleaned += 1
|
48
|
+
else
|
49
|
+
remaining << pathname
|
50
|
+
end
|
51
|
+
end
|
52
|
+
$stderr.puts "Cleaned up #{cleaned} old generated files" if @preexisting_files.size > 0
|
53
|
+
$stderr.puts "Remaining non-generated files:\n\t#{remaining*"\n\t"}" if remaining.size > 0
|
54
|
+
end
|
55
|
+
|
56
|
+
def generated_file_exists pathname
|
57
|
+
File.open(pathname, 'r') do |existing|
|
58
|
+
first_lines = existing.read(1024) # Make it possible to pass over a magic charset comment
|
59
|
+
if first_lines.length == 0 or first_lines =~ %r{^#{Regexp.quote HEADER}}
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
return false # File exists, but is not generated
|
64
|
+
rescue Errno::ENOENT
|
65
|
+
return nil # File does not exist
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_if_ok dir, filename
|
69
|
+
# Create a file in the output directory, being careful not to overwrite carelessly
|
70
|
+
out = $stdout
|
71
|
+
if dir
|
72
|
+
FileUtils.mkdir_p(dir)
|
73
|
+
pathname = (dir+'/'+filename).gsub(%r{//+}, '/')
|
74
|
+
@preexisting_files.reject!{|f| f == pathname } # Don't clean up this file
|
75
|
+
if generated_file_exists(pathname) == false
|
76
|
+
warn "not overwriting non-generated file #{pathname}"
|
77
|
+
@ok = false
|
78
|
+
return nil
|
79
|
+
end
|
80
|
+
out = File.open(pathname, 'w')
|
81
|
+
end
|
82
|
+
out
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -15,7 +15,7 @@ module ActiveFacts
|
|
15
15
|
module Rails
|
16
16
|
class Schema
|
17
17
|
MM = ActiveFacts::Metamodel unless const_defined?(:MM)
|
18
|
-
HEADER = "# Auto-generated
|
18
|
+
HEADER = "# Auto-generated (edits will be lost) using:"
|
19
19
|
def self.options
|
20
20
|
({
|
21
21
|
fks: ['Boolean', "Generate foreign key definitions"],
|
@@ -24,7 +24,13 @@ module ActiveFacts
|
|
24
24
|
})
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def self.compatibility
|
28
|
+
# REVISIT: We depend on the surrogate option being enabled if any PK is not Rails-friendly
|
29
|
+
[1, %i{relational}] # one relational composition
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize constellation, composition, options = {}
|
33
|
+
@constellation = constellation
|
28
34
|
@composition = composition
|
29
35
|
@options = options
|
30
36
|
@option_exclude_fks = [false, 'f', 'n', 'no'].include?(options.delete("fks"))
|
@@ -56,7 +62,8 @@ module ActiveFacts
|
|
56
62
|
header =
|
57
63
|
[
|
58
64
|
'#',
|
59
|
-
"#
|
65
|
+
"#{HEADER}",
|
66
|
+
"\# #{([File.basename($0)]+ARGV)*' '}",
|
60
67
|
'#',
|
61
68
|
'',
|
62
69
|
"ActiveRecord::Base.logger = Logger.new(STDOUT)",
|
@@ -205,11 +212,12 @@ module ActiveFacts
|
|
205
212
|
end
|
206
213
|
|
207
214
|
valid_parameters = MM::DataType::TypeParameters[type]
|
215
|
+
size_param = valid_parameters && valid_parameters.include?(:precision) ? :precision : :limit
|
208
216
|
length_ok = valid_parameters &&
|
209
217
|
![MM::DataType::TYPE_Real, MM::DataType::TYPE_Integer].include?(type) &&
|
210
218
|
(valid_parameters.include?(:length) || valid_parameters.include?(:precision))
|
211
219
|
scale_ok = length_ok && valid_parameters.include?(:scale)
|
212
|
-
length_option = length_ok && options[:length] ? ",
|
220
|
+
length_option = length_ok && options[:length] ? ", #{size_param}: #{options[:length]}" : ''
|
213
221
|
scale_option = scale_ok && options[:scale] ? ", scale: #{options[:scale]}" : ''
|
214
222
|
null_option = ", null: #{!options[:mandatory]}"
|
215
223
|
|
@@ -20,7 +20,11 @@ module ActiveFacts
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def self.compatibility
|
24
|
+
[1, %i{binary}]
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize constellation, composition, options = {}
|
24
28
|
super
|
25
29
|
@scope = options.delete('scope') || ''
|
26
30
|
@scope = @scope.split(/::/)
|
@@ -51,8 +55,8 @@ module ActiveFacts
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def class_prelude(object_type, supertype)
|
54
|
-
global_qualifier = object_type == supertype ? '::' :''
|
55
|
-
" class #{object_type.name.words.capcase}" + (supertype ? " < #{global_qualifier}#{supertype.name.words.capcase}" : '') + "\n"
|
58
|
+
global_qualifier = object_type == supertype ? ('::') : ''
|
59
|
+
" class #{object_type.name.words.capcase}" + (supertype ? (" < #{global_qualifier}#{supertype.name.words.capcase}") : '') + "\n"
|
56
60
|
end
|
57
61
|
|
58
62
|
def class_finale(object_type)
|
@@ -24,7 +24,8 @@ module ActiveFacts
|
|
24
24
|
include Traits::SQL
|
25
25
|
extend Traits::SQL
|
26
26
|
|
27
|
-
def initialize composition, options = {}
|
27
|
+
def initialize constellation, composition, options = {}
|
28
|
+
@constellation = constellation
|
28
29
|
@composition = composition
|
29
30
|
process_options options
|
30
31
|
end
|
@@ -9,6 +9,30 @@ require "activefacts/compositions/constraints"
|
|
9
9
|
require "activefacts/generator"
|
10
10
|
|
11
11
|
module ActiveFacts
|
12
|
+
module Generators
|
13
|
+
class Summary
|
14
|
+
def self.options
|
15
|
+
{
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.compatibility
|
20
|
+
[1, nil]
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize constellation, composition, options = {}
|
24
|
+
@constellation = constellation
|
25
|
+
@composition = composition
|
26
|
+
@options = options
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate
|
30
|
+
@composition.summary
|
31
|
+
end
|
32
|
+
end
|
33
|
+
publish_generator Summary, "Succinctly display the full structure of any composition"
|
34
|
+
end
|
35
|
+
|
12
36
|
module Metamodel
|
13
37
|
class Composition
|
14
38
|
def summary
|
@@ -98,23 +122,4 @@ module ActiveFacts
|
|
98
122
|
end
|
99
123
|
end
|
100
124
|
end
|
101
|
-
|
102
|
-
module Generators
|
103
|
-
class Summary
|
104
|
-
def self.options
|
105
|
-
{
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
def initialize composition, options = {}
|
110
|
-
@composition = composition
|
111
|
-
@options = options
|
112
|
-
end
|
113
|
-
|
114
|
-
def generate
|
115
|
-
@composition.summary
|
116
|
-
end
|
117
|
-
end
|
118
|
-
publish_generator Summary, "Succinctly display the full structure of any composition"
|
119
|
-
end
|
120
125
|
end
|
@@ -19,7 +19,13 @@ module ActiveFacts
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def self.compatibility
|
23
|
+
# REVISIT: This should accept 2 compositions
|
24
|
+
[1, %i{relational}]
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize constellation, composition, options = {}
|
28
|
+
@constellation = constellation
|
23
29
|
@composition = composition
|
24
30
|
@options = options
|
25
31
|
end
|
@@ -19,7 +19,12 @@ module ActiveFacts
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def self.compatibility
|
23
|
+
[nil, nil]
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize constellation, composition, options = {}
|
27
|
+
@constellation = constellation
|
23
28
|
@composition = composition
|
24
29
|
@options = options
|
25
30
|
end
|
@@ -34,7 +39,10 @@ module ActiveFacts
|
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
|
-
@composition.
|
42
|
+
Array(@composition).
|
43
|
+
each do |c|
|
44
|
+
c.validate(&report)
|
45
|
+
end
|
38
46
|
nil
|
39
47
|
end
|
40
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activefacts-compositions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clifford Heath
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -212,14 +212,24 @@ files:
|
|
212
212
|
- lib/activefacts/compositions/traits/rails.rb
|
213
213
|
- lib/activefacts/compositions/version.rb
|
214
214
|
- lib/activefacts/generator.rb
|
215
|
+
- lib/activefacts/generator/doc/css/glossary-print.css
|
216
|
+
- lib/activefacts/generator/doc/css/glossary.css
|
215
217
|
- lib/activefacts/generator/doc/css/ldm.css
|
218
|
+
- lib/activefacts/generator/doc/css/orm2-print.css
|
219
|
+
- lib/activefacts/generator/doc/css/orm2.css
|
220
|
+
- lib/activefacts/generator/doc/css/reset.css
|
221
|
+
- lib/activefacts/generator/doc/css/treetable.css
|
216
222
|
- lib/activefacts/generator/doc/cwm.rb
|
217
223
|
- lib/activefacts/generator/doc/glossary.rb
|
218
224
|
- lib/activefacts/generator/doc/graphviz.rb
|
219
225
|
- lib/activefacts/generator/doc/ldm.rb
|
220
226
|
- lib/activefacts/generator/etl/unidex.rb
|
221
227
|
- lib/activefacts/generator/oo.rb
|
228
|
+
- lib/activefacts/generator/population.rb
|
229
|
+
- lib/activefacts/generator/rails/active_admin.rb
|
230
|
+
- lib/activefacts/generator/rails/application_record_shell.rb
|
222
231
|
- lib/activefacts/generator/rails/models.rb
|
232
|
+
- lib/activefacts/generator/rails/ruby_folder_generator.rb
|
223
233
|
- lib/activefacts/generator/rails/schema.rb
|
224
234
|
- lib/activefacts/generator/ruby.rb
|
225
235
|
- lib/activefacts/generator/sql.rb
|
@@ -257,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
267
|
version: '0'
|
258
268
|
requirements: []
|
259
269
|
rubyforge_project:
|
260
|
-
rubygems_version: 2.6
|
270
|
+
rubygems_version: 2.7.6
|
261
271
|
signing_key:
|
262
272
|
specification_version: 4
|
263
273
|
summary: Create and represent composite schemas, schema transforms and data transforms
|