blueprint-api-rails 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blueprint/api/rails.rb +96 -12
- data/lib/blueprint/api/rails/version.rb +1 -1
- 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: 18a23084533dcc625ff392693ca1a0b41f3652a8
|
4
|
+
data.tar.gz: ca5f2d2ccba38944e6007137de9c69568c593691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 764c8bf1203f279cd57a830d975e094760397175ca94c2c8e610f09417b3e6e0ada0c5175eae64ba137559eae11a71d1a51de448c7e1b937611b7705d0dc439e
|
7
|
+
data.tar.gz: 929979c8e821eeba1c1d8948439dfa60991c6e9c4398ba4e527da09f4cd4a7e718e25e0e62d03996b69a4b098789d81d04121334195552ecf4209b901e349582
|
data/lib/blueprint/api/rails.rb
CHANGED
@@ -69,6 +69,21 @@ module Blueprint
|
|
69
69
|
self
|
70
70
|
end
|
71
71
|
|
72
|
+
# figures out (and returns) the remote origin for a local git repository
|
73
|
+
def determine_remote_repository(root_dir)
|
74
|
+
Dir.chdir(root_dir) do
|
75
|
+
git_remotes = `git remote show origin | grep 'Fetch URL: ' 2>&1`
|
76
|
+
repo_url = git_remotes.match(/Fetch URL: (.*).git/).try(:captures)
|
77
|
+
|
78
|
+
if !repo_url.empty?
|
79
|
+
repo_url = repo_url[0]
|
80
|
+
repo_url
|
81
|
+
else
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
72
87
|
end
|
73
88
|
|
74
89
|
##
|
@@ -91,25 +106,41 @@ module Blueprint
|
|
91
106
|
# performs an extract (that is, scans the code base for architectural elements)
|
92
107
|
# TODO this scan can be arbitrarily complex - we could scan for anything
|
93
108
|
# TODO add support of passing in custom scanners
|
94
|
-
def scan
|
109
|
+
def scan(repository_type)
|
110
|
+
repo_url = nil
|
111
|
+
|
112
|
+
if repository_type == :github
|
113
|
+
p 'GitHub has been specified as the remote repository store'
|
114
|
+
repo_url = determine_remote_repository '.'
|
115
|
+
end
|
95
116
|
|
96
117
|
p 'Scanning for controllers...'
|
97
118
|
|
98
|
-
# scan for all controllers (any file with the name *
|
119
|
+
# scan for all controllers (any file with the name *_controller.rb)
|
99
120
|
controllers = Dir[Rails.root.join('app/controllers/*_controller.rb')].map { |path|
|
100
|
-
path.match(/(\w+_controller).rb/); $1
|
121
|
+
path.match(/(\w+_controller).rb/); $1
|
101
122
|
}.reject { |clazz|
|
102
|
-
clazz.eql?('
|
123
|
+
clazz.eql?('application_controller') # ignore the ApplicationController superclass
|
103
124
|
}.compact
|
104
125
|
|
105
126
|
p "Found #{controllers.length} controllers - sending to Blueprint"
|
106
127
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
128
|
+
if repository_type == :github
|
129
|
+
controllers.each { |c|
|
130
|
+
pretty_name = c.gsub(/_/, ' ').titleize
|
131
|
+
self.element(pretty_name, "#{repo_url}/blob/master/app/controllers/#{c}.rb") # register the element
|
132
|
+
}
|
133
|
+
|
134
|
+
else
|
135
|
+
controllers.each { |c|
|
136
|
+
pretty_name = c.gsub(/_/, ' ').titleize
|
137
|
+
self.element(pretty_name) # register the element
|
138
|
+
}
|
139
|
+
|
140
|
+
end
|
111
141
|
|
112
142
|
# now scan for models
|
143
|
+
# TODO support code URLs for models too
|
113
144
|
models = Dir[Rails.root.join('app/models/*.rb')].map { |path|
|
114
145
|
path.match(/(\w+).rb/); $1.titleize
|
115
146
|
}.compact
|
@@ -123,8 +154,8 @@ module Blueprint
|
|
123
154
|
p 'Scan complete'
|
124
155
|
end
|
125
156
|
|
126
|
-
def element(name)
|
127
|
-
StructuralElementDesignContext.new(@api_key, @structure_id, name)
|
157
|
+
def element(name, code_url = nil)
|
158
|
+
StructuralElementDesignContext.new(@api_key, @structure_id, name, code_url)
|
128
159
|
end
|
129
160
|
|
130
161
|
def concept(name)
|
@@ -178,11 +209,12 @@ module Blueprint
|
|
178
209
|
|
179
210
|
class StructuralElementDesignContext < DesignContext
|
180
211
|
|
181
|
-
def initialize(api_key, structure_id, name)
|
212
|
+
def initialize(api_key, structure_id, name, code_url)
|
182
213
|
@api_key = api_key
|
183
214
|
@structure_id = structure_id
|
184
215
|
@instance_id = SecureRandom.uuid
|
185
216
|
@name = name
|
217
|
+
@code_url = code_url
|
186
218
|
|
187
219
|
# initialise faraday
|
188
220
|
@conn = Faraday.new(:url => BLUEPRINT_SERVER) do |faraday|
|
@@ -193,7 +225,8 @@ module Blueprint
|
|
193
225
|
# we register the structural element immediately (so that it appears on the structure even though it has no description / messages)
|
194
226
|
self.send DESCRIBE_ELEMENT,
|
195
227
|
{
|
196
|
-
:name => @name
|
228
|
+
:name => @name,
|
229
|
+
:code_url => @code_url
|
197
230
|
}
|
198
231
|
end
|
199
232
|
|
@@ -208,6 +241,15 @@ module Blueprint
|
|
208
241
|
self
|
209
242
|
end
|
210
243
|
|
244
|
+
def contains_with_pattern(pattern)
|
245
|
+
self.send CONTAINS,
|
246
|
+
{
|
247
|
+
:parent => @name,
|
248
|
+
:pattern => pattern
|
249
|
+
}
|
250
|
+
self
|
251
|
+
end
|
252
|
+
|
211
253
|
def contains(constituent)
|
212
254
|
self.send CONTAINS,
|
213
255
|
{
|
@@ -240,6 +282,48 @@ module Blueprint
|
|
240
282
|
}
|
241
283
|
end
|
242
284
|
|
285
|
+
def related_to(relation, other)
|
286
|
+
self.send DESCRIBE_CONCEPT,
|
287
|
+
{
|
288
|
+
:name => @name,
|
289
|
+
:relationship => {
|
290
|
+
:other => other,
|
291
|
+
:relation => relation
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
# return a design context for the 'other' concept (to support the fluent API)
|
296
|
+
ConceptDesignContext.new(@api_key, @structure_id, other)
|
297
|
+
end
|
298
|
+
|
299
|
+
def has_one(other)
|
300
|
+
self.send DESCRIBE_CONCEPT,
|
301
|
+
{
|
302
|
+
:name => @name,
|
303
|
+
:relationship => {
|
304
|
+
:relation => 'has one',
|
305
|
+
:other => other
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
# return a design context for the 'other' concept (to support the fluent API)
|
310
|
+
ConceptDesignContext.new(@api_key, @structure_id, other)
|
311
|
+
end
|
312
|
+
|
313
|
+
def has_many(other)
|
314
|
+
self.send DESCRIBE_CONCEPT,
|
315
|
+
{
|
316
|
+
:name => @name,
|
317
|
+
:relationship => {
|
318
|
+
:relation => 'has many',
|
319
|
+
:other => other
|
320
|
+
}
|
321
|
+
}
|
322
|
+
|
323
|
+
# return a design context for the 'other' concept (to support the fluent API)
|
324
|
+
ConceptDesignContext.new(@api_key, @structure_id, other)
|
325
|
+
end
|
326
|
+
|
243
327
|
# applies a description to the (conceptual) element
|
244
328
|
def describe(description = nil, stereotype = nil)
|
245
329
|
self.send DESCRIBE_CONCEPT,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprint-api-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- benjii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|