blueprint-generators-rails 0.1.2 → 0.1.3
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 +4 -4
- data/lib/blueprint/generators/rails/version.rb +1 -1
- data/lib/tasks/blueprint.rake +81 -69
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d800389259cd4f2c7deb3ccee4d9b8fad2d547dd
|
4
|
+
data.tar.gz: 91e0960b4fd8af98abf10ddf4294f1072a6699b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c210d07d0afb8d16cf2b0c8508232cacc228504edbf0565b260eeceb9f7e7fffe2d107924753718d56d48d70fa3af6a19586be80db21fada2cfc68c6d65603e9
|
7
|
+
data.tar.gz: 70d7c70e613cd3a7dfdd175fdd87a4df79908b74518b22f0c0935af0f1821c5cc4e8eabce39ba01ad4b6556fde60ecd2cd10b25618e6b749fde575e681b1889e
|
data/lib/tasks/blueprint.rake
CHANGED
@@ -4,7 +4,7 @@ namespace :blueprint do
|
|
4
4
|
|
5
5
|
desc 'Generate a Conceptual Model diagram for the current Rails project'
|
6
6
|
task :cm, [:options] => :environment do |t, args|
|
7
|
-
Rails.application.eager_load!
|
7
|
+
# Rails.application.eager_load!
|
8
8
|
|
9
9
|
# set the debug flag
|
10
10
|
@debug = args[:options] == 'debug'
|
@@ -16,87 +16,112 @@ namespace :blueprint do
|
|
16
16
|
step_count = 1
|
17
17
|
|
18
18
|
# get the configured app name
|
19
|
-
app_name =
|
19
|
+
app_name = Dir.pwd.split('/').last.capitalize
|
20
|
+
# app_name = Rails.application.class.parent_name
|
20
21
|
|
21
|
-
print_debug step_count, "
|
22
|
+
print_debug step_count, "Application name is " + app_name
|
22
23
|
step_count += 1
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
unless Dir.exist?(Dir.pwd + '/app/models')
|
26
|
+
print_debug step_count, 'Could not find models directory. Stopping analysis.'
|
27
|
+
return 0
|
28
|
+
end
|
27
29
|
|
28
|
-
|
30
|
+
Dir.chdir(Dir.pwd + '/app/models') do
|
29
31
|
|
30
|
-
#
|
31
|
-
|
32
|
+
# list all files in the directory
|
33
|
+
Dir.foreach('.') { |f|
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
+
# only deal with files that have a '.rb' extension
|
36
|
+
if File.extname(f) == '.rb'
|
37
|
+
# puts "Found: #{f}"
|
35
38
|
|
36
|
-
|
37
|
-
|
39
|
+
# process each file
|
40
|
+
File.open(f) do |m|
|
41
|
+
concept_name = nil
|
38
42
|
|
39
|
-
|
40
|
-
|
43
|
+
# process each line of the file
|
44
|
+
m.each_line do |line|
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
46
|
+
# search for the class declaration line
|
47
|
+
clazz, super_clazz = line.match(/class ([^<]*) < (.*)/).try(:captures)
|
45
48
|
|
46
|
-
|
47
|
-
|
49
|
+
# if we find a class declaration line, add the new concept to the model
|
50
|
+
unless clazz.nil?
|
51
|
+
# puts "Parsed: #{clazz} : #{super_clazz}"
|
52
|
+
concept_name = clazz.pluralize
|
48
53
|
|
49
|
-
|
50
|
-
|
54
|
+
# add the concept to the model hash
|
55
|
+
model[concept_name] = [ ]
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
has_one_name = humanise(a.name.to_s.singularize.capitalize)
|
57
|
+
print_debug step_count, "Adding concept " + concept_name
|
58
|
+
step_count += 1
|
55
59
|
|
56
|
-
|
57
|
-
|
60
|
+
unless super_clazz == 'ActiveRecord::Base'
|
61
|
+
is_a_name = super_clazz.singularize
|
58
62
|
|
59
|
-
|
60
|
-
|
63
|
+
# add the node relationship to the concept
|
64
|
+
model[concept_name].push({ :type => 'is a', :name => is_a_name })
|
61
65
|
|
62
|
-
|
63
|
-
|
66
|
+
print_debug step_count, "Concept " + concept_name + " is a " + is_a_name
|
67
|
+
step_count += 1
|
68
|
+
end
|
69
|
+
end
|
64
70
|
|
65
|
-
|
66
|
-
|
71
|
+
# search for a 'has_one' or 'belongs_to' declaration
|
72
|
+
a, has_one_clazz = line.match(/(has_one|belongs_to) :([^,]+)/).try(:captures)
|
73
|
+
unless has_one_clazz.nil?
|
74
|
+
has_one_name = has_one_clazz.capitalize.singularize.strip
|
67
75
|
|
68
|
-
|
69
|
-
|
76
|
+
# add the node relationship to the concept
|
77
|
+
model[concept_name].push({ :type => 'has one', :name => has_one_name })
|
70
78
|
|
71
|
-
|
72
|
-
|
73
|
-
|
79
|
+
print_debug step_count, "Concept " + concept_name + " has one " + has_one_name
|
80
|
+
step_count += 1
|
81
|
+
end
|
74
82
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
83
|
+
# search for a 'has_many' declaration
|
84
|
+
b, has_many_clazz = line.match(/(has_many) :([^,]+)/).try(:captures)
|
85
|
+
unless has_many_clazz.nil?
|
86
|
+
has_many_name = has_many_clazz.capitalize.pluralize.strip
|
79
87
|
|
80
|
-
|
81
|
-
|
82
|
-
model[has_many_name] = [ ]
|
83
|
-
end
|
88
|
+
# add the node relationship to the concept
|
89
|
+
model[concept_name].push({ :type => 'has many', :name => has_many_name })
|
84
90
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
91
|
+
print_debug step_count, "Concept " + concept_name + " has one " + has_many_name
|
92
|
+
step_count += 1
|
93
|
+
end
|
89
94
|
|
90
|
-
|
91
|
-
|
95
|
+
# search for a 'has_many' declaration
|
96
|
+
c, habtm_clazz = line.match(/(has_and_belongs_to_many) :([^,]+)/).try(:captures)
|
97
|
+
unless habtm_clazz.nil?
|
98
|
+
# this is a many-to-many, so we add two 'has many' relationships (one of each side)
|
99
|
+
habtm_name = habtm_clazz.capitalize.pluralize.strip
|
92
100
|
|
93
|
-
|
94
|
-
|
95
|
-
|
101
|
+
# add the first side of the 'has many' if it does not already exist
|
102
|
+
if model[concept_name].find { |v| v[:type] == 'has many' && v[:name] == habtm_name }.nil?
|
103
|
+
model[concept_name].push({ :type => 'has many', :name => habtm_name })
|
104
|
+
end
|
105
|
+
|
106
|
+
# if the model hash doesn't have any entry for the many side of the relationship, create it
|
107
|
+
if model[habtm_name].nil?
|
108
|
+
model[habtm_name] = [ ]
|
109
|
+
end
|
110
|
+
|
111
|
+
# add the second side of the 'has many' if it does not already exist
|
112
|
+
if model[habtm_name].find { |v| v[:type] == 'has many' && v[:name] == concept_name }.nil?
|
113
|
+
model[habtm_name].push({ :type => 'has many', :name => concept_name })
|
114
|
+
end
|
115
|
+
|
116
|
+
print_debug step_count, "Concept " + concept_name + " has many-to-many with " + habtm_name
|
117
|
+
step_count += 1
|
118
|
+
end
|
96
119
|
|
120
|
+
end
|
121
|
+
end
|
97
122
|
end
|
98
123
|
}
|
99
|
-
|
124
|
+
end
|
100
125
|
|
101
126
|
# now generate the PogoScript
|
102
127
|
pogo = "conceptual model for \"" + app_name + "\""
|
@@ -140,19 +165,6 @@ namespace :blueprint do
|
|
140
165
|
|
141
166
|
private
|
142
167
|
|
143
|
-
def self.humanise(str)
|
144
|
-
# this block applies a naming clean-up by camel-casing any words after an underscore (e.g.: Invited_by => InvitedBy)
|
145
|
-
|
146
|
-
tokens = str.scan(/[_]+[\w]/)
|
147
|
-
unless tokens.empty?
|
148
|
-
tokens.each { |t|
|
149
|
-
str[t]= t[-1, 1].capitalize
|
150
|
-
}
|
151
|
-
end
|
152
|
-
|
153
|
-
str
|
154
|
-
end
|
155
|
-
|
156
168
|
def self.print_debug(step_count, str)
|
157
169
|
if @debug
|
158
170
|
puts "#{step_count}. " + str
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprint-generators-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- benjii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|