blueprint-generators-rails 0.2.2 → 0.2.3
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 +148 -28
- 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: 311b2001ebd7c903b25ed94e3b98bde1f0e467e3
|
4
|
+
data.tar.gz: 1f8d4764036fca1b1939dacf9cd9a85808074f67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 116c2944679cfe618cdc79c0879f872b866de249c7f22ae8872004ed7c8cd9f20f2e921d1bbdb561f571f55c9dc3795b361219750852d425f4753b7a786b8fdc
|
7
|
+
data.tar.gz: eeb73a48dac594aa968e65dfa3dbf2cf7e9bf60c2f5ca8f0170dbdc0842399e502b2c284dd8d6f8f083d4711675b7c3435355fdab6f635177ea235e3efeea857
|
data/lib/tasks/blueprint.rake
CHANGED
@@ -10,11 +10,132 @@ namespace :blueprint do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
SEQUENCE_TAG_REGEX = /#[\s]*(:seq[_up|down]*\(.*\))/
|
14
|
+
CONCEPT_STATE_REGEX = /#[\s]*(:state*\(.*\))/
|
15
|
+
|
16
|
+
PARAMS_REGEX = /(.*)\((.*?)\)/
|
17
|
+
|
13
18
|
@debug = false
|
14
19
|
|
20
|
+
desc 'Generate Concept States diagrams for the current Rails project (requires use of semantic tags)'
|
21
|
+
task :states, :root_dir, :debug do |t, args|
|
22
|
+
root_dir = args[:root_dir] || '.'
|
23
|
+
@debug = args[:debug]
|
24
|
+
|
25
|
+
if @debug
|
26
|
+
puts "Debug mode #{@debug}"
|
27
|
+
puts "Root directory for analysis is: #{root_dir}"
|
28
|
+
end
|
29
|
+
|
30
|
+
# check that this is actually a Rails projects
|
31
|
+
unless File.exist?(root_dir + '/Gemfile')
|
32
|
+
puts 'No Gemfile found. Is this a Rails project?'
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
36
|
+
# if we get here than all base sanity checks are passed
|
37
|
+
|
38
|
+
# for debugging purposes
|
39
|
+
step_count = 1
|
40
|
+
|
41
|
+
# find the remote git repository name (so that we can link to it directly in our diagrams)
|
42
|
+
repo_url = determine_remote_repository root_dir
|
43
|
+
remote_origin_found = repo_url.present?
|
44
|
+
|
45
|
+
print_debug step_count, remote_origin_found ? "Remote repository URL is #{repo_url}" : 'No remote repository URL found'
|
46
|
+
step_count += 1
|
47
|
+
|
48
|
+
model = { }
|
49
|
+
|
50
|
+
# otherwise continue analysis
|
51
|
+
Dir.chdir(root_dir) do
|
52
|
+
# list all files in the directory - we scan everything (but maybe we shouldn't)
|
53
|
+
Dir.glob('**/*.{rb,js,coffee}').each { |f|
|
54
|
+
file = File.stat f
|
55
|
+
|
56
|
+
if file.file?
|
57
|
+
line_no = 1
|
58
|
+
|
59
|
+
File.open(f).each do |line|
|
60
|
+
|
61
|
+
# we are scanning for things like this:
|
62
|
+
# # :state(diagram, debit, state == DR)
|
63
|
+
# # :state(diagram, high value transaction, amount > 1000)
|
64
|
+
|
65
|
+
tag = line.match(CONCEPT_STATE_REGEX).try(:captures).try(:first)
|
66
|
+
|
67
|
+
if tag
|
68
|
+
print_debug step_count, "Found named concept state tag: '#{tag}'"
|
69
|
+
step_count += 1
|
70
|
+
|
71
|
+
# extract the tag type and parameters
|
72
|
+
type, parameters = tag.match(PARAMS_REGEX).try(:captures)
|
73
|
+
|
74
|
+
case type
|
75
|
+
when ':state'
|
76
|
+
concept, name, condition = parameters.split(',').map(&:strip)
|
77
|
+
model[concept] ||= [ ]
|
78
|
+
|
79
|
+
if remote_origin_found
|
80
|
+
model[concept].push(
|
81
|
+
{
|
82
|
+
:name => name,
|
83
|
+
:condition => condition,
|
84
|
+
:at => "#{repo_url}/blob/master/#{f}#L#{line_no}"
|
85
|
+
}
|
86
|
+
)
|
87
|
+
else
|
88
|
+
model[concept].push(
|
89
|
+
{
|
90
|
+
:name => name,
|
91
|
+
:condition => condition
|
92
|
+
}
|
93
|
+
)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
raise "Tag type #{type} not recognised when generating concept state diagram."
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
line_no += 1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
}
|
104
|
+
|
105
|
+
# now generate the PogoScript - there may be more than one
|
106
|
+
pogos = [ ]
|
107
|
+
|
108
|
+
model.each { |key, value|
|
109
|
+
pogo = "states for \"#{key}\"\n"
|
110
|
+
|
111
|
+
value.each { |x|
|
112
|
+
pogo += " is a \"#{x[:name]}\" when \"#{x[:condition]}\"\n"
|
113
|
+
pogo += " at \"#{x[:at]}\"\n" if x[:at].present?
|
114
|
+
pogo += "\n"
|
115
|
+
}
|
116
|
+
|
117
|
+
pogos << pogo.strip
|
118
|
+
}
|
119
|
+
|
120
|
+
puts ''
|
121
|
+
puts 'Navigate to the link below and paste the provided script into the editor found at:'
|
122
|
+
puts ''
|
123
|
+
puts ' http://anaxim.io/#/scratchpad'
|
124
|
+
puts ''
|
125
|
+
puts '----'
|
126
|
+
puts '~~~~'
|
127
|
+
pogos.each { |pogo|
|
128
|
+
puts pogo
|
129
|
+
puts '~~~~'
|
130
|
+
}
|
131
|
+
puts '----'
|
132
|
+
puts ''
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
15
137
|
desc 'Generate Sequence diagrams for the current Rails project (requires use of semantic tags)'
|
16
138
|
task :seq, :root_dir, :debug do |t, args|
|
17
|
-
|
18
139
|
root_dir = args[:root_dir] || '.'
|
19
140
|
@debug = args[:debug]
|
20
141
|
|
@@ -43,34 +164,33 @@ namespace :blueprint do
|
|
43
164
|
file = File.stat f
|
44
165
|
|
45
166
|
if file.file?
|
46
|
-
|
47
167
|
File.open(f).each do |line|
|
48
168
|
|
49
169
|
# we are scanning for things like this:
|
50
|
-
# #
|
51
|
-
# #
|
52
|
-
# #
|
170
|
+
# # :seq(test, a b)
|
171
|
+
# # :seq_up(test, a b, foo bar)
|
172
|
+
# # :seq_down(test, b a, bar foo)
|
53
173
|
|
54
|
-
tag = line.match(
|
174
|
+
tag = line.match(SEQUENCE_TAG_REGEX).try(:captures).try(:first)
|
55
175
|
|
56
176
|
if tag
|
57
177
|
print_debug step_count, "Found sequence start tag: '#{tag}'"
|
58
178
|
step_count += 1
|
59
179
|
|
60
180
|
# extract the tag type and parameters
|
61
|
-
type, parameters = tag.match(
|
181
|
+
type, parameters = tag.match(PARAMS_REGEX).try(:captures)
|
62
182
|
|
63
183
|
case type
|
64
|
-
when '
|
184
|
+
when ':seq'
|
65
185
|
name, lanes = parameters.split(',').map(&:strip)
|
66
186
|
model[name] ||= { }
|
67
187
|
model[name][:lanes] ||= lanes.split(' ')
|
68
188
|
|
69
|
-
when '
|
189
|
+
when ':seq_up'
|
70
190
|
name, action = parameters.split(',').map(&:strip)
|
71
191
|
(model[name][:movements] ||= [ ]) << { :direction => :up, :action => action }
|
72
192
|
|
73
|
-
when '
|
193
|
+
when ':seq_down'
|
74
194
|
name, action = parameters.split(',').map(&:strip)
|
75
195
|
(model[name][:movements] ||= [ ]) << { :direction => :down, :action => action }
|
76
196
|
|
@@ -121,7 +241,6 @@ namespace :blueprint do
|
|
121
241
|
puts ''
|
122
242
|
|
123
243
|
end
|
124
|
-
|
125
244
|
end
|
126
245
|
|
127
246
|
desc 'Alias for the \'seq\' task'
|
@@ -189,24 +308,11 @@ namespace :blueprint do
|
|
189
308
|
end
|
190
309
|
|
191
310
|
# find the remote git repository name (so that we can link to it directly in our diagrams)
|
192
|
-
|
193
|
-
|
311
|
+
repo_url = determine_remote_repository root_dir
|
312
|
+
remote_origin_found = repo_url.present?
|
194
313
|
|
195
|
-
|
196
|
-
|
197
|
-
repo_url = git_remotes.match(/Fetch URL: (.*).git/).try(:captures)
|
198
|
-
|
199
|
-
remote_origin_found = !repo_url.empty?
|
200
|
-
|
201
|
-
if remote_origin_found
|
202
|
-
repo_url = repo_url[0]
|
203
|
-
print_debug step_count, "Remote repository URL is #{repo_url}"
|
204
|
-
else
|
205
|
-
print_debug step_count, 'No remote repository URL found'
|
206
|
-
end
|
207
|
-
|
208
|
-
step_count += 1
|
209
|
-
end
|
314
|
+
print_debug step_count, remote_origin_found ? "Remote repository URL is #{repo_url}" : 'No remote repository URL found'
|
315
|
+
step_count += 1
|
210
316
|
|
211
317
|
# otherwise continue analysis
|
212
318
|
Dir.chdir(root_dir + '/app/models') do
|
@@ -376,4 +482,18 @@ namespace :blueprint do
|
|
376
482
|
end
|
377
483
|
end
|
378
484
|
|
485
|
+
def self.determine_remote_repository(root_dir)
|
486
|
+
Dir.chdir(root_dir) do
|
487
|
+
git_remotes = `git remote show origin | grep 'Fetch URL: ' 2>&1`
|
488
|
+
repo_url = git_remotes.match(/Fetch URL: (.*).git/).try(:captures)
|
489
|
+
|
490
|
+
if !repo_url.empty?
|
491
|
+
repo_url = repo_url[0]
|
492
|
+
repo_url
|
493
|
+
else
|
494
|
+
nil
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
379
499
|
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- benjii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|