schemadoc 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cb6784e134252acacb2dd68891aca5dba7edcaf
4
- data.tar.gz: c8ff27fa4cae9bd3bcf56f6630ff8a6c2ff0ce72
3
+ metadata.gz: 4cacde4f0b3b4f232bd4f0550af241286b658e89
4
+ data.tar.gz: 22f4a46c61f170f65bbc34caf94c825f3018c5d7
5
5
  SHA512:
6
- metadata.gz: 5c5b67fc7dc6e00ce69ecda54fe0a0619ebd0274fd8b16a3fdfc5c8abbfa737ad3a300086d3deba9eacc3bfd4b8a68fe5162457332a6748c6d70208564adc3c3
7
- data.tar.gz: 9b4b0d83a6ea9fe82a5cbe2d37d187509d6a31c186b0038433657560c16342c169102f7cdfa3c5655a91648bdbfa23cdb729bcc30af19018cf45a4d1181f18ed
6
+ metadata.gz: 933310973794c021b4351996d879e37b599991dbf510124102fe0cf745fd91eddd0673d4ea1af270e8da706676f98a4f791aac9ec4375a2979c47656322ca7db
7
+ data.tar.gz: a33e66989fc88c0d4e17e6cb8e500b96c850e882fe951aff1d77bf4fa3952e0d203f15449506425f8fdabbadb715559684545cb80c0637f011377bf3d76df65f
@@ -8,5 +8,11 @@ lib/schemadoc/cli/opts.rb
8
8
  lib/schemadoc/cli/runner.rb
9
9
  lib/schemadoc/version.rb
10
10
  lib/schemadoc/worker.rb
11
+ test/config/beer.rb
11
12
  test/config/beer.yml
13
+ test/config/beer.yuml
14
+ test/config/feed.yuml
12
15
  test/config/football.yml
16
+ test/config/football.yuml
17
+ test/config/pluto.yuml
18
+ test/config/world.yuml
@@ -65,9 +65,30 @@ EOS
65
65
 
66
66
  arg = args[0] || './schemadoc.yml'
67
67
  config = YAML.load_file( arg )
68
- pp config
68
+ pp config
69
+
70
+ ## check for .rb file w/ same name but .rb extension
71
+ ## require/load if present
72
+ boot_path = arg.sub( '.yml', '.rb' )
73
+ if File.exists?( boot_path )
74
+ puts "try to boot (load) '#{boot_path}'..."
75
+
76
+ ## note: for now always add ./ current workdir
77
+ ## fix - check if path is absolute; if not only add ./ current if not absolute
78
+ require "./#{boot_path}"
79
+ puts 'ok'
80
+ end
81
+
82
+ if defined?(MODELS)
83
+ models = MODELS
84
+ models.each do |model| # double check model classes if present (loaded)
85
+ puts "#{model.name}... ok"
86
+ end
87
+ else
88
+ models = []
89
+ end
69
90
 
70
- worker = Worker.new( config ).run
91
+ worker = Worker.new( config, models ).run
71
92
 
72
93
  puts 'Done.'
73
94
 
@@ -3,8 +3,8 @@
3
3
  module SchemaDoc
4
4
 
5
5
  MAJOR = 1
6
- MINOR = 0
7
- PATCH = 2
6
+ MINOR = 1
7
+ PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -11,10 +11,10 @@ module SchemaDoc
11
11
 
12
12
  class Worker
13
13
 
14
- def initialize( config )
14
+ def initialize( config, models=[] )
15
15
  ## split into db config (for connection) and
16
16
  ## schemadoc config
17
-
17
+
18
18
  @config = {}
19
19
  @db_config = {}
20
20
 
@@ -28,11 +28,16 @@ class Worker
28
28
 
29
29
  puts "database connection spec:"
30
30
  pp @db_config
31
+
32
+ @models = models
31
33
  end
32
34
 
33
35
 
34
36
  def connect
35
- @con = AbstractModel.connection_for( @db_config )
37
+ ##@con = AbstractModel.connection_for( @db_config )
38
+
39
+ ActiveRecord::Base.establish_connection( @db_config )
40
+ @con = ActiveRecord::Base.connection
36
41
  end
37
42
 
38
43
  def dump_schema
@@ -52,6 +57,7 @@ class Worker
52
57
  end
53
58
  end
54
59
 
60
+
55
61
  def build_schema
56
62
  ####
57
63
  # build schema hash
@@ -93,6 +99,73 @@ class Worker
93
99
  end
94
100
 
95
101
 
102
+ def dump_models
103
+ @models.each do |model|
104
+ ## pp model
105
+
106
+ puts model.name
107
+ puts "=" * model.name.size
108
+ puts " table_name: #{model.table_name}"
109
+ pp model.columns
110
+
111
+ ## check assocs
112
+ assocs = model.reflections.values
113
+ ## pp assocs
114
+ assocs.each do |assoc|
115
+ puts "#{assoc.macro} #{assoc.name}"
116
+ puts "options:"
117
+ pp assoc.options
118
+ end
119
+ end
120
+ end
121
+
122
+
123
+ def build_models
124
+ #########################
125
+ # build models hash
126
+
127
+ models = []
128
+
129
+ @models.each do |model|
130
+
131
+ puts model.name
132
+ puts "=" * model.name.size
133
+
134
+ m = {
135
+ name: model.name, ## todo: split into name and module/package name ??
136
+ table_name: model.table_name,
137
+ columns: [],
138
+ assocs: [],
139
+ }
140
+
141
+ model.columns.each do |column|
142
+ c = {
143
+ name: column.name,
144
+ null: column.null,
145
+ default: column.default,
146
+ sql_type: column.sql_type,
147
+ cast_type: column.cast_type.class.name,
148
+ }
149
+ m[:columns] << c
150
+ end
151
+
152
+ ## check assocs
153
+ assocs = model.reflections.values
154
+ assocs.each do |assoc|
155
+ a = {
156
+ macro: assoc.macro, ## rename to rel or something - why, why not??
157
+ name: assoc.name,
158
+ options: assoc.options ## filter options - why, why not??
159
+ }
160
+ m[:assocs] << a
161
+ end
162
+
163
+ models << m
164
+ end # each model
165
+ models
166
+ end # method build_models
167
+
168
+
96
169
  def build_index
97
170
  ####
98
171
  # build symbol index hash
@@ -148,9 +221,47 @@ class Worker
148
221
  end
149
222
 
150
223
 
224
+ def models_to_yuml( models )
225
+
226
+ ## todo: move to script !!!
227
+ ## check
228
+ ## how to deal w/ singular,plural,
229
+ ## add to model
230
+ ## singular,plural - to keep it simple???
231
+ ## use name and full_name and module ??
232
+ ## e.g. BeerDb::Model::Brewery ???
233
+
234
+ buf = ''
235
+ models.each do |model|
236
+
237
+ assocs = model[:assocs]
238
+ if assocs.empty?
239
+ buf << "// skipping #{model[:name]}; no assocs found/n"
240
+ next
241
+ end
242
+
243
+ assocs.each do |assoc|
244
+ ## skip assocs w/ option through for now
245
+ if assoc[:options][:through]
246
+ buf << "// skipping assoc #{assoc[:macro]} #{assoc[:name]} w/ option through\n"
247
+ next
248
+ end
249
+
250
+ buf << "[#{model[:name]}] - [#{assoc[:name]}]\n"
251
+ end
252
+ end
253
+
254
+ buf
255
+ end
256
+
257
+
151
258
  def run( opts={} )
152
259
  connect()
153
260
  dump_schema()
261
+ dump_models()
262
+
263
+ models = build_models()
264
+ pp models
154
265
 
155
266
  schema = build_schema()
156
267
  index = build_index()
@@ -161,6 +272,15 @@ class Worker
161
272
  f.write JSON.pretty_generate( schema )
162
273
  end
163
274
 
275
+ File.open( 'models.json', 'w') do |f|
276
+ f.write JSON.pretty_generate( models )
277
+ end
278
+
279
+ ### fix: move to script !!!
280
+ File.open( 'models.yuml', 'w' ) do |f|
281
+ f.write models_to_yuml( models )
282
+ end
283
+
164
284
  File.open( 'symbols.json', 'w') do |f|
165
285
  f.write JSON.pretty_generate( index )
166
286
  end
@@ -169,6 +289,10 @@ class Worker
169
289
 
170
290
  private
171
291
 
292
+ ###
293
+ ## fix: not really needed - remove ???
294
+ ## just use ActiveRecord::Base.establish_connection() directly ??
295
+
172
296
  class AbstractModel < ActiveRecord::Base
173
297
  self.abstract_class = true # no table; class just used for getting db connection
174
298
 
@@ -0,0 +1,28 @@
1
+
2
+
3
+ puts '[boot] hello from beer.rb'
4
+
5
+ ## get all beer.db models
6
+ require 'beerdb'
7
+
8
+
9
+ ### use Schemadoc::MODELS ???
10
+
11
+ ## configure all models to document
12
+
13
+ MODELS = [
14
+ BeerDb::Model::Beer,
15
+ BeerDb::Model::Brand,
16
+ BeerDb::Model::Brewery,
17
+
18
+ WorldDb::Model::Continent,
19
+ WorldDb::Model::Country,
20
+ WorldDb::Model::Region,
21
+ WorldDb::Model::City,
22
+
23
+ TagDb::Model::Tag, ### check - is TaxoDb ??
24
+ TagDb::Model::Tagging,
25
+ ]
26
+
27
+ ### needs an established connection
28
+ # pp MODELS
@@ -0,0 +1,10 @@
1
+ ////////
2
+ // yuml.me model class diagram (yuml.me/diagram/scruffy/class/draw)
3
+
4
+
5
+ [Brewery|key;name;address;web] -> [Brand|key;name]
6
+ [Brand] -> [Beer|key;name;abv;og]
7
+ [Brewery] -> [Beer]
8
+
9
+ [Beer] - [note: Use tags for styles e.g. ale lager stout lambic and more {bg:wheat}]
10
+
@@ -0,0 +1,6 @@
1
+ ////////
2
+ // yuml.me model class diagram (yuml.me/diagram/scruffy/class/draw)
3
+
4
+
5
+ [Feed|format;title;url;summary;updated;published;generator] -> [Item|guid;title;url;summary;content;updated;published]
6
+
@@ -12,6 +12,7 @@ database:
12
12
  football:
13
13
  name: Football
14
14
 
15
+ ### add football stats section!!!!
15
16
 
16
17
  ############
17
18
  # world tables
@@ -0,0 +1,30 @@
1
+ ////////
2
+ // yuml.me model class diagram (yuml.me/diagram/scruffy/class/draw)
3
+
4
+ // note: use small size
5
+
6
+
7
+ [Season|key;title] -> [Competition|key;title;start_at;end_at;num]
8
+
9
+ [League|key;title] -> [Competition]
10
+
11
+ [Competition] -> [Team|key;title;code;address;web]
12
+
13
+ [Competition] -> [Round|title;start_at;end_at;num]
14
+
15
+ [Competition] -> [Group|title;num]
16
+
17
+ [Round] -> [Match|num;play_at;knockout;home;score1;score2;score1et;score2et;score1p;score2p;winner]
18
+
19
+ [Group] -> [Match]
20
+
21
+ [Team] -> [Match]
22
+
23
+ [Match] -> [Goal|minute;offset;penalty;owngoal]
24
+
25
+ [Goal] <- [Player|name]
26
+
27
+ [Team] -> [Squad|num;pos]
28
+
29
+ [Squad] <- [Player]
30
+
@@ -0,0 +1,8 @@
1
+ ////////
2
+ // yuml.me model class diagram (yuml.me/diagram/scruffy/class/draw)
3
+
4
+
5
+ [Site|key;title;author;updated;url;fetched;] -> [Subscription]
6
+ [Subscription] <- [Feed|key;encoding;format;title;url;feed_url;generator;summary;updated;published;author;fetched]
7
+ [Feed] -> [Item|guid;url;title;summary;content;updated;published;fetched]
8
+
@@ -0,0 +1,25 @@
1
+
2
+ ////////
3
+ // yuml.me model class diagram (yuml.me/diagram/scruffy/class/draw)
4
+
5
+ ////
6
+ // Everything is a place. use inheritance w/ ^
7
+
8
+ [Place|name;lat;lng;type] ^ [City Town Village]
9
+ [Place] ^ [State Province]
10
+ [Place] ^ [Country Territory]
11
+ [Place] ^ [Continent]
12
+
13
+ ////
14
+ // [Place] -> [Name|name;lang]
15
+
16
+ ///////
17
+
18
+ [Continent|key;name;area;pop] -> [Country|key;name;area;pop]
19
+ [Country] -> [State|key;name;area;pop]
20
+ [State] -> [City|key;name;area;pop]
21
+
22
+ ////
23
+ //[Country] -> [Country Codes|name;type]
24
+
25
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemadoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logutils
@@ -87,8 +87,14 @@ files:
87
87
  - lib/schemadoc/cli/runner.rb
88
88
  - lib/schemadoc/version.rb
89
89
  - lib/schemadoc/worker.rb
90
+ - test/config/beer.rb
90
91
  - test/config/beer.yml
92
+ - test/config/beer.yuml
93
+ - test/config/feed.yuml
91
94
  - test/config/football.yml
95
+ - test/config/football.yuml
96
+ - test/config/pluto.yuml
97
+ - test/config/world.yuml
92
98
  homepage: https://github.com/rubylibs/schemadoc
93
99
  licenses:
94
100
  - Public Domain