blueprint-api-rails 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/blueprint/api/rails/version.rb +1 -1
- data/lib/blueprint/api/rails.rb +226 -84
- 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: 67fc79456b463a6eb05d67efd1140268c5b35afc
|
4
|
+
data.tar.gz: aa3c1baa961ce4b425278719259e35319c17dcbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a902708353af1dcd9800f0f170be411bcfd91e99b533e006eedb2fdeaa5f6234584fc50d7a2611d4ec86a8dc8753abb35a8e9a10996bcadb389cd26214eb661
|
7
|
+
data.tar.gz: 45352ac51e430b72b193c174f1bf057ba3d3519dd2b370d2b35e2e9b72f949dd50c97d6dfd8054d8763b60f130b7dc3afba948eba511250d14fcb9dd8ef69379
|
data/lib/blueprint/api/rails.rb
CHANGED
@@ -8,9 +8,16 @@ module Blueprint
|
|
8
8
|
|
9
9
|
|
10
10
|
STRUCTURE_NEW = 'start'
|
11
|
+
|
11
12
|
MESSAGE = 'message'
|
12
13
|
CLASSIFIER_NEW = 'classifier-new'
|
13
14
|
|
15
|
+
ACTIVITY_NEW = 'activity-new'
|
16
|
+
ACTIVITY_PERFORM = 'activity-perform'
|
17
|
+
ACTIVITY_DECIDE = 'activity-decide'
|
18
|
+
ACTIVITY_OUTCOME = 'activity-outcome'
|
19
|
+
ACTIVITY_END = 'activity-end'
|
20
|
+
|
14
21
|
# allow users to set the API key
|
15
22
|
def self.set_api_key api_key
|
16
23
|
@api_key = api_key
|
@@ -22,6 +29,10 @@ module Blueprint
|
|
22
29
|
end
|
23
30
|
|
24
31
|
|
32
|
+
##
|
33
|
+
# The default design context for logging messages, etc. Also implements uitlity methods (like send())
|
34
|
+
##
|
35
|
+
|
25
36
|
class DesignContext
|
26
37
|
|
27
38
|
def initialize(api_key, structure_id)
|
@@ -52,6 +63,17 @@ module Blueprint
|
|
52
63
|
nil
|
53
64
|
end
|
54
65
|
|
66
|
+
def activity(component, name, start_state)
|
67
|
+
self.send ACTIVITY_NEW,
|
68
|
+
{
|
69
|
+
:component => component,
|
70
|
+
:name => name,
|
71
|
+
:state => start_state
|
72
|
+
}
|
73
|
+
|
74
|
+
ActivityDesignContext.new(@api_key, @structure_id, component, name)
|
75
|
+
end
|
76
|
+
|
55
77
|
# logs a message between two nodes in the structure
|
56
78
|
def log(source, target, type, message = { }, extras = { })
|
57
79
|
self.send MESSAGE,
|
@@ -99,6 +121,209 @@ module Blueprint
|
|
99
121
|
|
100
122
|
end
|
101
123
|
|
124
|
+
##
|
125
|
+
# Design context for activities
|
126
|
+
##
|
127
|
+
|
128
|
+
class ActivityDesignContext < DesignContext
|
129
|
+
|
130
|
+
def initialize(api_key, structure_id, component_name, activity_name)
|
131
|
+
@api_key = api_key
|
132
|
+
@structure_id = structure_id
|
133
|
+
@component_name = component_name
|
134
|
+
@activity_name = activity_name
|
135
|
+
@branch = `git rev-parse --abbrev-ref HEAD 2>&1`.strip! || 'master'
|
136
|
+
|
137
|
+
# initialise faraday
|
138
|
+
@conn = Faraday.new(:url => BLUEPRINT_SERVER) do |faraday|
|
139
|
+
faraday.response :logger # log requests to STDOUT
|
140
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def perform(description)
|
145
|
+
self.send ACTIVITY_PERFORM,
|
146
|
+
{
|
147
|
+
:component => @component_name,
|
148
|
+
:activity => @activity_name,
|
149
|
+
:description => description
|
150
|
+
}
|
151
|
+
|
152
|
+
self
|
153
|
+
end
|
154
|
+
|
155
|
+
def decide(description)
|
156
|
+
self.send ACTIVITY_DECIDE,
|
157
|
+
{
|
158
|
+
:component => @component_name,
|
159
|
+
:activity => @activity_name,
|
160
|
+
:description => description
|
161
|
+
}
|
162
|
+
|
163
|
+
ActivityDecisionDesignContext.new(@api_key, @structure_id, @component_name, @activity_name, description)
|
164
|
+
end
|
165
|
+
|
166
|
+
def end(description)
|
167
|
+
self.send ACTIVITY_END,
|
168
|
+
{
|
169
|
+
:component => @component_name,
|
170
|
+
:activity => @activity_name,
|
171
|
+
:description => description
|
172
|
+
}
|
173
|
+
|
174
|
+
ActivityEndDesignContext.new(@api_key, @structure_id, @activity_name)
|
175
|
+
end
|
176
|
+
|
177
|
+
def log(source, target, type, message = { }, extras = { })
|
178
|
+
self.send MESSAGE,
|
179
|
+
{
|
180
|
+
:source => source,
|
181
|
+
:target => target,
|
182
|
+
:input_for => @activity_name
|
183
|
+
},
|
184
|
+
{
|
185
|
+
:type => type,
|
186
|
+
:payload => {
|
187
|
+
:message => message, # the message that was sent
|
188
|
+
:extras => extras # extra details about the message that can aid classification
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
self
|
193
|
+
end
|
194
|
+
|
195
|
+
##
|
196
|
+
# Design context for activity decisions
|
197
|
+
##
|
198
|
+
|
199
|
+
class ActivityDecisionDesignContext < DesignContext
|
200
|
+
|
201
|
+
def initialize(api_key, structure_id, component_name, activity_name, parent = nil)
|
202
|
+
@api_key = api_key
|
203
|
+
@structure_id = structure_id
|
204
|
+
@component_name = component_name
|
205
|
+
@activity_name = activity_name
|
206
|
+
@parent = parent
|
207
|
+
@branch = `git rev-parse --abbrev-ref HEAD 2>&1`.strip! || 'master'
|
208
|
+
|
209
|
+
# initialise faraday
|
210
|
+
@conn = Faraday.new(:url => BLUEPRINT_SERVER) do |faraday|
|
211
|
+
faraday.response :logger # log requests to STDOUT
|
212
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def yes
|
217
|
+
OutcomeDesignContext.new @api_key, @structure_id, @component_name, @activity_name, @parent
|
218
|
+
end
|
219
|
+
|
220
|
+
def no
|
221
|
+
OutcomeDesignContext.new @api_key, @structure_id, @component_name, @activity_name, @parent, false
|
222
|
+
end
|
223
|
+
|
224
|
+
##
|
225
|
+
# Design context for decision outcomes (only possible after an activity decision)
|
226
|
+
##
|
227
|
+
|
228
|
+
class OutcomeDesignContext < DesignContext
|
229
|
+
|
230
|
+
def initialize(api_key, structure_id, component_name, activity_name, parent = nil, positive = true)
|
231
|
+
@api_key = api_key
|
232
|
+
@structure_id = structure_id
|
233
|
+
@component_name = component_name
|
234
|
+
@activity_name = activity_name
|
235
|
+
@parent = parent
|
236
|
+
@positive = positive
|
237
|
+
@branch = `git rev-parse --abbrev-ref HEAD 2>&1`.strip! || 'master'
|
238
|
+
|
239
|
+
# initialise faraday
|
240
|
+
@conn = Faraday.new(:url => BLUEPRINT_SERVER) do |faraday|
|
241
|
+
faraday.response :logger # log requests to STDOUT
|
242
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def perform(description)
|
247
|
+
self.send ACTIVITY_PERFORM,
|
248
|
+
{
|
249
|
+
:component => @component_name,
|
250
|
+
:activity => @activity_name,
|
251
|
+
:parent => @parent,
|
252
|
+
:description => description,
|
253
|
+
:positive => @positive
|
254
|
+
}
|
255
|
+
|
256
|
+
self
|
257
|
+
end
|
258
|
+
|
259
|
+
def decide(description)
|
260
|
+
self.send ACTIVITY_DECIDE,
|
261
|
+
{
|
262
|
+
:component => @component_name,
|
263
|
+
:activity => @activity_name,
|
264
|
+
:parent => @parent,
|
265
|
+
:description => description,
|
266
|
+
:positive => @positive
|
267
|
+
}
|
268
|
+
|
269
|
+
ActivityDecisionDesignContext.new(@api_key, @structure_id, @component_name, @activity_name, description)
|
270
|
+
end
|
271
|
+
|
272
|
+
def end(description)
|
273
|
+
self.send ACTIVITY_END,
|
274
|
+
{
|
275
|
+
:component => @component_name,
|
276
|
+
:activity => @activity_name,
|
277
|
+
:parent => @parent,
|
278
|
+
:description => description,
|
279
|
+
:positive => @positive
|
280
|
+
}
|
281
|
+
|
282
|
+
ActivityEndDesignContext.new(@api_key, @structure_id, @activity_name)
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
##
|
291
|
+
# Design context for the end of an activity
|
292
|
+
##
|
293
|
+
class ActivityEndDesignContext < DesignContext
|
294
|
+
|
295
|
+
def initialize(api_key, structure_id, activity_name)
|
296
|
+
@api_key = api_key
|
297
|
+
@structure_id = structure_id
|
298
|
+
@activity_name = activity_name
|
299
|
+
@branch = `git rev-parse --abbrev-ref HEAD 2>&1`.strip! || 'master'
|
300
|
+
|
301
|
+
# initialise faraday
|
302
|
+
@conn = Faraday.new(:url => BLUEPRINT_SERVER) do |faraday|
|
303
|
+
faraday.response :logger # log requests to STDOUT
|
304
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
def log(source, target, type, message = { }, extras = { })
|
309
|
+
self.send MESSAGE,
|
310
|
+
{
|
311
|
+
:source => source,
|
312
|
+
:target => target,
|
313
|
+
:output_for => @activity_name
|
314
|
+
},
|
315
|
+
{
|
316
|
+
:type => type,
|
317
|
+
:payload => {
|
318
|
+
:message => message, # the message that was sent
|
319
|
+
:extras => extras # extra details about the message that can aid classification
|
320
|
+
}
|
321
|
+
}
|
322
|
+
self
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
102
327
|
class LinkDesignContext < DesignContext
|
103
328
|
|
104
329
|
def initialize(api_key, structure_id, source, target)
|
@@ -135,87 +360,4 @@ module Blueprint
|
|
135
360
|
|
136
361
|
end
|
137
362
|
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
# # activity diagram event types
|
142
|
-
# ACTIVITY_START = 'activity-start'
|
143
|
-
# ACTIVITY_ACTION = 'activity-action'
|
144
|
-
# ACTIVITY_DECISION = 'activity-decision'
|
145
|
-
# ACTIVITY_DECISION_OUTCOME = 'activity-decision-outcome'
|
146
|
-
# ACTIVITY_OUTCOME = 'activity-outcome'
|
147
|
-
# ACTIVITY_END = 'activity-end'
|
148
|
-
|
149
|
-
# COMPONENTS_START = 'components-start'
|
150
|
-
# COMPONENTS_NEW = 'components-new'
|
151
|
-
# COMPONENTS_LINK = 'components-link'
|
152
|
-
#
|
153
|
-
# MESSAGE = 'message'
|
154
|
-
|
155
|
-
|
156
|
-
# # use this to create a new activity - returns a design context, which can be used for subsequent calls
|
157
|
-
# def self.start_activity(diagram, name, start_state)
|
158
|
-
# DesignContext.new(@api_key, diagram).send ACTIVITY_START, { :name => name, :state => start_state }
|
159
|
-
# end
|
160
|
-
|
161
|
-
# # use this to create a new set of system components - returns a design context, which can be used for subsequent calls
|
162
|
-
# def self.declare_system(diagram, name)
|
163
|
-
# DesignContext.new(@api_key, diagram).send COMPONENTS_START, { :name => name }
|
164
|
-
# end
|
165
|
-
|
166
|
-
# def self.log_message(diagram, identifier, type, message = { })
|
167
|
-
# DesignContext.new(@api_key, diagram, identifier, nil)
|
168
|
-
# .send MESSAGE, { :type => type, :message => message }
|
169
|
-
# nil
|
170
|
-
# end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
# # -----------------------------------------------------------------------
|
175
|
-
# # activity diagram API calls
|
176
|
-
#
|
177
|
-
# def decide(identifier, condition)
|
178
|
-
# # returns a new design context that represents the decision
|
179
|
-
# DesignContext.new(@api_key, @diagram, identifier, self)
|
180
|
-
# .send ACTIVITY_DECISION, { :condition => condition }
|
181
|
-
# end
|
182
|
-
#
|
183
|
-
# def positive(*args)
|
184
|
-
# if args.length == 1
|
185
|
-
# outcome 'positive', args[0]
|
186
|
-
# elsif args.length == 2
|
187
|
-
# decision_outcome args[0], 'positive', args[1]
|
188
|
-
# end
|
189
|
-
# end
|
190
|
-
#
|
191
|
-
# def negative(*args)
|
192
|
-
# if args.length == 1
|
193
|
-
# outcome 'negative', args[0]
|
194
|
-
# elsif args.length == 2
|
195
|
-
# decision_outcome args[0], 'negative', args[1]
|
196
|
-
# end
|
197
|
-
# end
|
198
|
-
#
|
199
|
-
# def decision_outcome(identifier, outcome, condition)
|
200
|
-
# # returns a new design context that represents the outcome
|
201
|
-
# DesignContext.new(@api_key, @diagram, identifier, self)
|
202
|
-
# .send ACTIVITY_DECISION_OUTCOME, { :outcome => outcome, :condition => condition }
|
203
|
-
# end
|
204
|
-
#
|
205
|
-
# def outcome(outcome, action)
|
206
|
-
# # returns a new design context that represents the outcome
|
207
|
-
# DesignContext.new(@api_key, @diagram, nil, self)
|
208
|
-
# .send ACTIVITY_OUTCOME, { :outcome => outcome, :action => action }
|
209
|
-
# end
|
210
|
-
#
|
211
|
-
# def action(identifier, action)
|
212
|
-
# # returns a new design context that represents the action
|
213
|
-
# DesignContext.new(@api_key, @diagram, identifier, self)
|
214
|
-
# .send ACTIVITY_ACTION, { :action => action }
|
215
|
-
# end
|
216
|
-
#
|
217
|
-
# def end(state)
|
218
|
-
# # returns a new design context that represents the end of the activity
|
219
|
-
# DesignContext.new(@api_key, @diagram, nil, self)
|
220
|
-
# .send ACTIVITY_END, { :state => state }
|
221
|
-
# end
|
363
|
+
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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- benjii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|