From ec184b600fa2f97552c42ab5cedaeb4fba8df185 Mon Sep 17 00:00:00 2001 From: ac360 Date: Thu, 18 Feb 2016 09:06:53 -0800 Subject: [PATCH] Serializer: add generic seriealize and deserliealize methods --- lib/Component.js | 1 + lib/Endpoint.js | 1 + lib/Event.js | 1 + lib/Function.js | 1 + lib/Plugin.js | 3 ++- lib/Project.js | 5 +++-- lib/Region.js | 1 + lib/Resources.js | 1 + lib/RuntimeBase.js | 4 ++-- lib/SerializerFileSystem.js | 8 ++++++++ lib/Stage.js | 1 + lib/Templates.js | 1 + lib/Variables.js | 4 ++-- 13 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/Component.js b/lib/Component.js index b4ca43cc5..189b71f2d 100644 --- a/lib/Component.js +++ b/lib/Component.js @@ -24,6 +24,7 @@ class ServerlessComponent extends SerializerFileSystem { let _this = this; _this._S = Serverless; + _this._class = 'Component'; _this._config = {}; _this._project = project; _this.updateConfig(config); diff --git a/lib/Endpoint.js b/lib/Endpoint.js index 54536253c..1f00cc401 100644 --- a/lib/Endpoint.js +++ b/lib/Endpoint.js @@ -28,6 +28,7 @@ class Endpoint extends SerializerFileSystem { // Private properties let _this = this; _this._S = Serverless; + _this._class = 'Endpoint'; _this._function = func; _this.updateConfig(config); diff --git a/lib/Event.js b/lib/Event.js index 85afc7363..5ca7ee426 100644 --- a/lib/Event.js +++ b/lib/Event.js @@ -28,6 +28,7 @@ class Event extends SerializerFileSystem { // Private properties let _this = this; _this._S = Serverless; + _this._class = 'Error'; _this._config = {}; _this._function = func; diff --git a/lib/Function.js b/lib/Function.js index f5dc042cd..65587f461 100644 --- a/lib/Function.js +++ b/lib/Function.js @@ -25,6 +25,7 @@ class Function extends SerializerFileSystem { let _this = this; _this._S = Serverless; + _this._class = 'Function'; _this._config = {}; _this._component = component; diff --git a/lib/Plugin.js b/lib/Plugin.js index c621be42a..90db04ad5 100644 --- a/lib/Plugin.js +++ b/lib/Plugin.js @@ -18,7 +18,8 @@ class ServerlessPlugin { */ constructor(S) { - this.S = S; + this.S = S; + this._class = 'Plugin'; } /** diff --git a/lib/Project.js b/lib/Project.js index fc2a9a573..d5ab95176 100644 --- a/lib/Project.js +++ b/lib/Project.js @@ -26,6 +26,7 @@ class Project extends SerializerFileSystem { let _this = this; _this._S = S; + _this._class = 'Project'; // Default properties _this.name = 'serverless' + SUtils.generateShortId(6); @@ -49,7 +50,7 @@ class Project extends SerializerFileSystem { */ load() { - return this.deserializeProject(this); + return this.deserialize(this); } /** @@ -58,7 +59,7 @@ class Project extends SerializerFileSystem { */ save(options) { - return this.serializeProject(this, options); + return this.serialize(this, options); } /** diff --git a/lib/Region.js b/lib/Region.js index a4805bd70..13ed2ac9d 100644 --- a/lib/Region.js +++ b/lib/Region.js @@ -10,6 +10,7 @@ class Region extends SerializerFileSystem { super(); this._S = S; + this._class = 'Region'; this._stage = stage; this._variables = new this._S.classes.Variables(); diff --git a/lib/Resources.js b/lib/Resources.js index b7c911209..931b95c7f 100644 --- a/lib/Resources.js +++ b/lib/Resources.js @@ -11,6 +11,7 @@ class Resources { constructor(S, config) { this._S = S; + this._class = 'Resources'; this._config = config; this._modules = []; } diff --git a/lib/RuntimeBase.js b/lib/RuntimeBase.js index ff8ba2226..45fb74eca 100644 --- a/lib/RuntimeBase.js +++ b/lib/RuntimeBase.js @@ -12,8 +12,8 @@ const SError = require('./Error'), class ServerlessRuntimeBase { constructor(S, name) { - this.S = S; - this.name = name; + this.S = S; + this.name = name; } populateComponentFolder( componentPath ) { diff --git a/lib/SerializerFileSystem.js b/lib/SerializerFileSystem.js index 4888ca978..66c99aa05 100644 --- a/lib/SerializerFileSystem.js +++ b/lib/SerializerFileSystem.js @@ -19,6 +19,14 @@ class SerializerFileSystem { this._projectPath = S.config.serializer.projectPath; } + serialize(asset) { + return this['serialize' + asset._class].apply(_.toArray(arguments)); + } + + deserialize(asset) { + return this['deserialize' + asset._class].apply(_.toArray(arguments)); + } + /** * Deserialize Project */ diff --git a/lib/Stage.js b/lib/Stage.js index 199ca52ea..a449ec228 100644 --- a/lib/Stage.js +++ b/lib/Stage.js @@ -11,6 +11,7 @@ class Stage extends SerializerFileSystem { super(); this._S = S; + this._class = 'Stage'; this._project = project; this._regions = {}; this._variables = new this._S.classes.Variables(this._S); diff --git a/lib/Templates.js b/lib/Templates.js index 2fb186e77..20661aab8 100644 --- a/lib/Templates.js +++ b/lib/Templates.js @@ -10,6 +10,7 @@ class Templates { constructor(S, config) { this._S = S; + this._class = 'Templates'; this._config = config; } } diff --git a/lib/Variables.js b/lib/Variables.js index 280b4b4af..13c72ba9d 100644 --- a/lib/Variables.js +++ b/lib/Variables.js @@ -11,8 +11,8 @@ class Variables extends SerializerFileSystem { constructor(S) { super(); - - this._S = S; + this._S = S; + this._class = 'Variables'; } load() {