blueprint-api-rails 0.2.5 → 0.2.6
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/version.rb +1 -1
- data/lib/blueprint/api/rails.rb +53 -0
- 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: 785506963749b0ec9c534c6ae2a2f29b43d51531
|
4
|
+
data.tar.gz: 692c18d746600e1f399d54d25422c00e6bcb18c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dddbdc7efef2de303de2e3c8a84862d56e9c01044a89a640e336b9f7db88a638584ee3a2428eb8dccc8063d753463950cb4ba532aeba9db53c83e1990d89b8b8
|
7
|
+
data.tar.gz: 1288df1666ab966e2316b523827cc970540abc5680b8477f2428791f9c38953cb07f49c3942e2543799d356b5c6f7b9b3c6239f9892a1c83ea806b8f565954a7
|
data/lib/blueprint/api/rails.rb
CHANGED
@@ -9,6 +9,7 @@ module Blueprint
|
|
9
9
|
# TODO deprecate all of the branch stuff
|
10
10
|
# TODO limit messages that are lists to a maximum of 10 elements
|
11
11
|
# TODO add support for getting the current user (so we can analysis log messages per user)
|
12
|
+
# TODO only log messages to the Blueprint server if there is an API key (if there isn't we can still check rules locally)
|
12
13
|
|
13
14
|
STRUCTURE_NEW = 'start'
|
14
15
|
|
@@ -20,6 +21,9 @@ module Blueprint
|
|
20
21
|
|
21
22
|
CONTAINS = 'contains'
|
22
23
|
|
24
|
+
# the set of validation and verification rules for the system (executed locally)
|
25
|
+
RULES = { }
|
26
|
+
|
23
27
|
# allow users to set the API key
|
24
28
|
def self.set_api_key api_key
|
25
29
|
@api_key = api_key
|
@@ -84,6 +88,37 @@ module Blueprint
|
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
91
|
+
# checks that the action that the system just took does not violate any architectural rules
|
92
|
+
def check_rules(source, target, type)
|
93
|
+
# the list of violations for this action
|
94
|
+
violations = [ ]
|
95
|
+
|
96
|
+
unless type.nil?
|
97
|
+
# is the type restricted to a certain structural element?
|
98
|
+
|
99
|
+
unless RULES[type].nil? # are there any rules for this type?
|
100
|
+
|
101
|
+
if RULES[type].has_key?(:only) # do the rules for this type include an 'only' restriction?
|
102
|
+
allowed_element = RULES[type][:only]
|
103
|
+
|
104
|
+
unless allowed_element.eql?(source)
|
105
|
+
violations << "The type #{type} is allowed only within #{allowed_element} and it was used in #{source}."
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# output architectural violations
|
112
|
+
# TODO make this output more obvious (and configurable?)
|
113
|
+
unless violations.empty?
|
114
|
+
p '### Architectural violations found ###'
|
115
|
+
violations.each { |v|
|
116
|
+
p ' ' + v
|
117
|
+
}
|
118
|
+
p '### End of violations ###'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
87
122
|
end
|
88
123
|
|
89
124
|
##
|
@@ -184,6 +219,9 @@ module Blueprint
|
|
184
219
|
|
185
220
|
# logs a message between two nodes in the structure
|
186
221
|
def log(message = { }, extras = { }, type = nil, source = nil, target = nil)
|
222
|
+
# always check the logged message for architectural rules violations
|
223
|
+
check_rules(source, target, type)
|
224
|
+
|
187
225
|
properties = Hash.new.tap do |h|
|
188
226
|
h[:source] = source unless source.blank?
|
189
227
|
h[:target] = target unless target.blank?
|
@@ -335,6 +373,15 @@ module Blueprint
|
|
335
373
|
self
|
336
374
|
end
|
337
375
|
|
376
|
+
# verification methods
|
377
|
+
def only(element)
|
378
|
+
unless RULES.has_key?(@name)
|
379
|
+
RULES[@name] = { }
|
380
|
+
end
|
381
|
+
|
382
|
+
RULES[@name][:only] = element
|
383
|
+
end
|
384
|
+
|
338
385
|
end
|
339
386
|
|
340
387
|
##
|
@@ -387,6 +434,9 @@ module Blueprint
|
|
387
434
|
|
388
435
|
|
389
436
|
def log(message = { }, extras = { }, type = nil, source = nil, target = nil)
|
437
|
+
# always check the logged message for architectural rules violations
|
438
|
+
check_rules(source, target, type)
|
439
|
+
|
390
440
|
properties = Hash.new.tap do |h|
|
391
441
|
h[:instance_id] = @activity_ctx.instance_id
|
392
442
|
h[:activity] = @activity_ctx.name
|
@@ -431,6 +481,9 @@ module Blueprint
|
|
431
481
|
|
432
482
|
# logs a message between two nodes in the structure
|
433
483
|
def log(message = { }, extras = { }, type = nil)
|
484
|
+
# always check the logged message for architectural rules violations
|
485
|
+
check_rules(@source, @target, type)
|
486
|
+
|
434
487
|
properties = Hash.new.tap do |h|
|
435
488
|
h[:source] = @source unless @source.blank?
|
436
489
|
h[:target] = @target unless @target.blank?
|
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.6
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|