blueprint-generators-rails 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blueprint/generators/rails/version.rb +1 -1
- data/lib/tasks/blueprint.rake +81 -32
- 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: ed74bf88f68d1cf0892cd924c01c3867d5565520
|
4
|
+
data.tar.gz: a23b7c4d5e80b834dfc9105a48a61938dea4b23b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a78b4e02fe8544c9a7ed2e2e2d1a934255d047e6fde1d84eeafa5c29979189c07a9fbae7a1883c32455c607e3ad504430bc93c5953e6000028593d3c722e32c9
|
7
|
+
data.tar.gz: 5291415e66479f219ab46171baf0d3cedab1c3bc528b95f48bdc7629caf9c1c54b2ba29d26300f89ad67ca5d97d8ce9b4df93c265e4f03460721003dfca85e1b
|
data/lib/tasks/blueprint.rake
CHANGED
@@ -1,39 +1,46 @@
|
|
1
1
|
namespace :blueprint do
|
2
2
|
|
3
|
+
@debug = false
|
4
|
+
|
3
5
|
desc 'Generate a Conceptual Model diagram for the current Rails project'
|
4
6
|
task :cm, [:options] => :environment do |t, args|
|
5
7
|
Rails.application.eager_load!
|
6
8
|
|
9
|
+
# set the debug flag
|
10
|
+
@debug = args[:options] == 'debug'
|
11
|
+
|
12
|
+
# we store the detected model in a hash - which we later serialize to PogoScript
|
13
|
+
model = { }
|
14
|
+
|
7
15
|
# for debugging purposes
|
8
16
|
step_count = 1
|
9
17
|
|
18
|
+
# get the configured app name
|
10
19
|
app_name = Rails.application.class.parent_name
|
11
|
-
pogo = "conceptual model for \"" + app_name + "\""
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
step_count += 1
|
16
|
-
end
|
21
|
+
print_debug step_count, "Generating conceptual model PogoScript for " + app_name
|
22
|
+
step_count += 1
|
17
23
|
|
18
|
-
|
19
|
-
|
24
|
+
concepts = ActiveRecord::Base.descendants
|
25
|
+
concepts.each { |m|
|
26
|
+
next if m.name.starts_with?'HABTM' # we skip Rails 'special' HABTM model classes
|
20
27
|
|
21
28
|
concept_name = humanise(m.name)
|
22
|
-
pogo << "\n concept \"" + concept_name + "\"\n"
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
30
|
+
# add the concept to the model hash
|
31
|
+
model[concept_name] = [ ]
|
32
|
+
|
33
|
+
print_debug step_count, "Adding concept " + concept_name
|
34
|
+
step_count += 1
|
28
35
|
|
29
36
|
unless m.superclass.to_s == 'ActiveRecord::Base'
|
30
37
|
is_a_name = humanise(m.superclass.to_s.singularize.capitalize)
|
31
|
-
pogo << " is a \"" + is_a_name + "\"\n"
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
# add the node relationship to the concept
|
40
|
+
model[concept_name].push({ :type => 'is a', :name => is_a_name })
|
41
|
+
|
42
|
+
print_debug step_count, "Concept " + concept_name + " is a " + is_a_name
|
43
|
+
step_count += 1
|
37
44
|
end
|
38
45
|
|
39
46
|
associations = m.reflect_on_all_associations
|
@@ -45,36 +52,72 @@ namespace :blueprint do
|
|
45
52
|
case a.macro
|
46
53
|
when :belongs_to, :has_one
|
47
54
|
has_one_name = humanise(a.name.to_s.singularize.capitalize)
|
48
|
-
pogo << " has one \"" + has_one_name + "\"\n"
|
49
55
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
# add the node relationship to the concept
|
57
|
+
model[concept_name].push({ :type => 'has one', :name => has_one_name })
|
58
|
+
|
59
|
+
print_debug step_count, "Concept " + concept_name + " has one " + has_one_name
|
60
|
+
step_count += 1
|
54
61
|
|
55
62
|
when :has_many
|
56
63
|
has_many_name = humanise(a.name.to_s.singularize.capitalize)
|
57
|
-
pogo << " has many \"" + has_many_name + "\"\n"
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
# add the node relationship to the concept
|
66
|
+
model[concept_name].push({ :type => 'has many', :name => has_many_name })
|
67
|
+
|
68
|
+
print_debug step_count, "Concept " + concept_name + " has one " + has_many_name
|
69
|
+
step_count += 1
|
70
|
+
|
71
|
+
when :has_and_belongs_to_many
|
72
|
+
# this is a many-to-many, so we add two 'has many' relationships (one of each side)
|
73
|
+
has_many_name = humanise(a.name.to_s.singularize.capitalize)
|
74
|
+
|
75
|
+
# add the first side of the 'has many' if it does not already exist
|
76
|
+
if model[concept_name].find { |v| v[:type] == 'has many' && v[:name] == has_many_name }.nil?
|
77
|
+
model[concept_name].push({ :type => 'has many', :name => has_many_name })
|
62
78
|
end
|
63
79
|
|
64
|
-
|
65
|
-
|
80
|
+
# if the model hash doesn't have any entry for the many side of the relationship, create it
|
81
|
+
if model[has_many_name].nil?
|
82
|
+
model[has_many_name] = [ ]
|
83
|
+
end
|
66
84
|
|
67
|
-
|
68
|
-
|
69
|
-
|
85
|
+
# add the second side of the 'has many' if it does not already exist
|
86
|
+
if model[has_many_name].find { |v| v[:type] == 'has many' && v[:name] == concept_name }.nil?
|
87
|
+
model[has_many_name].push({ :type => 'has many', :name => concept_name })
|
70
88
|
end
|
71
89
|
|
72
|
-
|
90
|
+
print_debug step_count, "Concept " + concept_name + " has many-to-many with " + has_many_name
|
91
|
+
step_count += 1
|
92
|
+
|
93
|
+
else
|
94
|
+
print_debug step_count, "Did not recognise macro type: " + a.macro.to_s
|
95
|
+
step_count += 1
|
96
|
+
|
97
|
+
end
|
98
|
+
}
|
99
|
+
}
|
73
100
|
|
101
|
+
# now generate the PogoScript
|
102
|
+
pogo = "conceptual model for \"" + app_name + "\""
|
103
|
+
model.each { |name, relationships|
|
104
|
+
pogo << "\n concept \"" + name + "\"\n"
|
105
|
+
|
106
|
+
relationships.each { |r|
|
107
|
+
case r[:type]
|
108
|
+
when 'is a'
|
109
|
+
pogo << " is a \"" + r[:name] + "\"\n"
|
110
|
+
when 'has one'
|
111
|
+
pogo << " has one \"" + r[:name] + "\"\n"
|
112
|
+
when 'has many'
|
113
|
+
pogo << " has many \"" + r[:name] + "\"\n"
|
114
|
+
else
|
115
|
+
# TODO implement
|
74
116
|
end
|
75
117
|
}
|
76
118
|
}
|
77
119
|
|
120
|
+
# output the result
|
78
121
|
puts ''
|
79
122
|
puts 'Navigate to the link below and paste the provided script into the editor'
|
80
123
|
puts ''
|
@@ -110,4 +153,10 @@ namespace :blueprint do
|
|
110
153
|
str
|
111
154
|
end
|
112
155
|
|
156
|
+
def self.print_debug(step_count, str)
|
157
|
+
if @debug
|
158
|
+
puts "#{step_count}. " + str
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
113
162
|
end
|
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.0
|
4
|
+
version: 0.1.0
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|