Skip to content

Commit 0c83fd2

Browse files
committed
Renaming input -> match.
1 parent 8a0192a commit 0c83fd2

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ URIs in the rest of this document start with `{baseuri}`. This is a placeholder
3737
"states": {
3838
"foo": {
3939
"transitions": [
40-
{ "input": "1|2|[a-bA-B]","nextState": "bar" },
41-
{ "input": "3","nextState": "baz" }
40+
{ "match": "1|2|[a-bA-B]","nextState": "bar" },
41+
{ "match": "3","nextState": "baz" }
4242
]
4343
},
4444
"bar": {
@@ -95,7 +95,7 @@ URIs in the rest of this document start with `{baseuri}`. This is a placeholder
9595

9696
#### State machine input
9797

98-
##### Inform the state machine of an input
98+
##### Provide input to the state machine
9999

100100
###### Request
101101

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var dbm = require('db-migrate');
2+
var type = dbm.dataType;
3+
4+
exports.up = function(db, callback) {
5+
db.renameColumn('transitions', 'input', 'match', callback)
6+
};
7+
8+
exports.down = function(db, callback) {
9+
db.renameColumn('transitions', 'match', 'input', callback)
10+
};

models/transition.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var sequelize = require('sequelize'),
33
State = require('./state.js')
44

55
var Transition = db.define('transitions', {
6-
input: { type: sequelize.STRING, notNull: true }
6+
match: { type: sequelize.STRING, notNull: true }
77
})
88

99
Transition.belongsTo(State, { as: 'State', foreignKey: 'state_id' })

restapi/resources/v1/state_machine_input.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var processInput = function(dbStateMachine, dbState, input, cb) {
5151
transitions,
5252
function(dbTransition, callback) {
5353

54-
var matches = input.match(new RegExp(dbTransition.input))
54+
var matches = input.match(new RegExp(dbTransition.match))
5555
if (matches) {
5656
dbTransition.getNextState()
5757
.success(function(dbns) { dbNextState = dbns; callback(true) })
@@ -80,7 +80,7 @@ var updateCurrentState = function(dbStateMachine, dbState, cb) {
8080
dbStateMachine.current_state_id = dbState.id
8181
dbStateMachine.save()
8282
.success(function() { cb(null, dbState) })
83-
.error(function(err) { console.error(err); cb(err) })
83+
.error(cb)
8484

8585
} // END function - updateCurrentState
8686

restapi/resources/v1/state_machines.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ var validateRequest = function(req, cb) {
2323
}
2424
var initialState = body.initialState
2525

26-
for (var state in states) {
27-
26+
for (var stateName in states) {
27+
28+
var state = states[stateName]
29+
2830
if (state.hasOwnProperty('transitions') && (state.transitions instanceof Array)) {
2931

30-
for (var tid in transitions) {
32+
for (var tid in state.transitions) {
3133

32-
var transition = transitions[tid]
34+
var transition = state.transitions[tid]
3335

34-
// Ensure transition has 'input' property present
35-
if (!transition.hasOwnProperty('input')) {
36-
cb({code: 400, message: 'Missing transition property \'input\''})
36+
// Ensure transition has 'match' property present
37+
if (!transition.hasOwnProperty('match')) {
38+
cb({code: 400, message: 'Missing transition property \'match\''})
3739
}
3840

39-
// Ensure transition has 'newState' property present
40-
if (!transition.hasOwnProperty('newState')) {
41-
cb({code: 400, message: 'Missing transition property \'newState\''})
41+
// Ensure transition has 'nextState' property present
42+
if (!transition.hasOwnProperty('nextState')) {
43+
cb({code: 400, message: 'Missing transition property \'nextState\''})
4244
}
4345

4446
} // END for - transitions
@@ -57,12 +59,12 @@ var validateRequest = function(req, cb) {
5759
for (var tid in state.transitions) {
5860

5961
var transition = state.transitions[tid]
60-
var input = transition.input
61-
var transitionState = transition.newState
62+
var match = transition.match
63+
var transitionState = transition.nextState
6264

6365
// Ensure transition state is one of the defined states
6466
if (!states.hasOwnProperty(transitionState)) {
65-
cb({code: 400, message: 'Transition state for state \'' + state + '\' and input \'' + input + '\' not found'})
67+
cb({code: 400, message: 'Transition state for state \'' + state + '\' and match \'' + match + '\' not found'})
6668
}
6769

6870
} // END for - transitions
@@ -90,7 +92,6 @@ var persistInitialState = function(stateMachine, dbStateMachine, cb) {
9092
dbStateMachine.current_state_id = state.id
9193
dbStateMachine.save()
9294
.success(function(dbsm) {
93-
console.log(dbsm.current_state_id)
9495
cb(null, stateMachine, dbsm)
9596
})
9697
.error(cb)
@@ -144,7 +145,7 @@ var persistTransitions = function(stateMachine, dbStateMachine, cb) {
144145

145146
models.transition.create({
146147
state_id: dbState.id,
147-
input: transition.input,
148+
match: transition.match,
148149
next_state_id: dbNextState.id
149150
})
150151
.success(function(t) { callback() })

0 commit comments

Comments
 (0)