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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d8f08fc6a6a16a012f97f982ce8242f8910ff19
4
- data.tar.gz: b0d2f3ada82b8565ad8cf11a455ddf5293a9df60
3
+ metadata.gz: 18a23084533dcc625ff392693ca1a0b41f3652a8
4
+ data.tar.gz: ca5f2d2ccba38944e6007137de9c69568c593691
5
5
  SHA512:
6
- metadata.gz: 1752120fbf82f5c3dc59aa472af6353888b624d632850929e09d5fc6e7ecebdafee092d55228f30939fd5301eda79061d6b0209a7614440e7b1cd2b7961956c0
7
- data.tar.gz: 53024cf284cbbc36d52179fd59cdb52c57296a4b0301bf11465edcf166cc155edbb8dfdad68b1a0c6dc23c3f95e087c915be04734f8894f7eee92b4c583c0099
6
+ metadata.gz: 764c8bf1203f279cd57a830d975e094760397175ca94c2c8e610f09417b3e6e0ada0c5175eae64ba137559eae11a71d1a51de448c7e1b937611b7705d0dc439e
7
+ data.tar.gz: 929979c8e821eeba1c1d8948439dfa60991c6e9c4398ba4e527da09f4cd4a7e718e25e0e62d03996b69a4b098789d81d04121334195552ecf4209b901e349582
@@ -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 *Controller)
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.gsub!(/_/, ' ').titleize
121
+ path.match(/(\w+_controller).rb/); $1
101
122
  }.reject { |clazz|
102
- clazz.eql?('Application Controller') # ignore the ApplicationController superclass
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
- # send the controllers to Blueprint
108
- controllers.each { |c|
109
- self.element(c) # register the element
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,
@@ -1,7 +1,7 @@
1
1
  module Blueprint
2
2
  module Api
3
3
  module Rails
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.5'
5
5
  end
6
6
  end
7
7
  end
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.3
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-04 00:00:00.000000000 Z
11
+ date: 2016-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler