1 | <!DOCTYPE html>
|
2 | <html lang="en">
|
3 | <head>
|
4 | <meta charset="utf-8">
|
5 | <title>JSDoc: Source: lib/model/Container.js</title>
|
6 |
|
7 | <script src="scripts/prettify/prettify.js"> </script>
|
8 | <script src="scripts/prettify/lang-css.js"> </script>
|
9 | |
10 |
|
11 |
|
12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
14 | </head>
|
15 |
|
16 | <body>
|
17 |
|
18 | <div id="main">
|
19 |
|
20 | <h1 class="page-title">Source: lib/model/Container.js</h1>
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | <section>
|
28 | <article>
|
29 | <pre class="prettyprint source linenums"><code>var _ = require("lodash");
|
30 |
|
31 | /**
|
32 | * Abstract parent class with common methods
|
33 | * @abstract
|
34 | */
|
35 | var Container = function () {
|
36 |
|
37 | this.container = null;
|
38 | this.serviceObject = null;
|
39 |
|
40 | this.data = {};
|
41 |
|
42 | };
|
43 |
|
44 | /**
|
45 | * Exposes setter and getter for a class from the `data` field
|
46 | */
|
47 | Container.prototype.exportProperties = function () {
|
48 | var me = this;
|
49 | _.forEach(this.data, function (value, key) {
|
50 | Object.defineProperty(me, key, {
|
51 | get: function () {
|
52 | return me.data[key];
|
53 | },
|
54 | set: function (value) {
|
55 | me.data[key] = value;
|
56 | },
|
57 | });
|
58 | });
|
59 | };
|
60 |
|
61 | /**
|
62 | * Return the client reference
|
63 | * @return {Client} client
|
64 | */
|
65 | Container.prototype.getClient = function () {
|
66 | return this.container && this.container.client;
|
67 | };
|
68 |
|
69 | /**
|
70 | * Return the Raptor instance wrapper
|
71 | * @return {Raptor} container Raptor instance reference
|
72 | */
|
73 | Container.prototype.getContainer = function () {
|
74 | return this.container;
|
75 | };
|
76 |
|
77 | /**
|
78 | * @param {Raptor} container reference to Raptor instance wrapper
|
79 | */
|
80 | Container.prototype.setContainer = function (c) {
|
81 | this.container = c;
|
82 | };
|
83 |
|
84 | /**
|
85 | * Set a reference to the parent object
|
86 | * @param {ServiceObject} object reference to the parent object
|
87 | */
|
88 | Container.prototype.setServiceObject = function (s) {
|
89 | this.serviceObject = s;
|
90 | if(s && s.getContainer) {
|
91 | this.setContainer(s.getContainer());
|
92 | }
|
93 | };
|
94 |
|
95 | /**
|
96 | * @return {ServiceObject} object return the object reference if any
|
97 | */
|
98 | Container.prototype.getObject = Container.prototype.getServiceObject = function () {
|
99 | return this.serviceObject;
|
100 | };
|
101 |
|
102 | /**
|
103 | * Validate the object and throw an exception if fails
|
104 | * @return {void}
|
105 | */
|
106 | Container.prototype.validate = function () {
|
107 | throw new Error("Not implemented");
|
108 | };
|
109 |
|
110 | /**
|
111 | * Convert the instance to a js object
|
112 | * @return {Object} Plain js object
|
113 | */
|
114 | Container.prototype.toJSON = function () {
|
115 |
|
116 | var recurse = function (obj) {
|
117 | var json = {};
|
118 |
|
119 | _.forEach(obj, function (value, key) {
|
120 |
|
121 | if(!value) {
|
122 | json[key] = value;
|
123 | return json;
|
124 | }
|
125 |
|
126 | if(value.toJSON) {
|
127 | json[key] = value.toJSON();
|
128 | } else if(value instanceof Array) {
|
129 | json[key] = recurse(value);
|
130 | } else if(typeof value === 'object') {
|
131 | json[key] = recurse(value);
|
132 | } else
|
133 | json[key] = value;
|
134 |
|
135 | });
|
136 |
|
137 | return json;
|
138 | };
|
139 |
|
140 | return recurse(this.data);
|
141 | };
|
142 |
|
143 | /**
|
144 | * Return a JSON string of this object
|
145 | * @return {String} json stringified JSON
|
146 | */
|
147 | Container.prototype.toString = function () {
|
148 | return JSON.stringify(this.toJSON());
|
149 | };
|
150 |
|
151 | /**
|
152 | * Parse a plain object and populate the corresponding fields in the current instance
|
153 | * @param {Object} raw the json object
|
154 | */
|
155 | Container.prototype.parseJSON = function (raw) {
|
156 |
|
157 | if(!raw) return;
|
158 |
|
159 | if(typeof raw === 'string') {
|
160 | try {
|
161 | raw = JSON.parse(raw)
|
162 | } catch(e) {
|
163 | // not JSON
|
164 | }
|
165 | }
|
166 |
|
167 | var me = this;
|
168 |
|
169 | this.data = this.data || {};
|
170 | _.forEach(this.data, function (value, key) {
|
171 | if(raw[key] !== undefined) {
|
172 | me.data[key] = raw[key];
|
173 | }
|
174 | });
|
175 |
|
176 | };
|
177 |
|
178 | module.exports = Container;
|
179 | </code></pre>
|
180 | </article>
|
181 | </section>
|
182 |
|
183 |
|
184 |
|
185 |
|
186 | </div>
|
187 |
|
188 | <nav>
|
189 | <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Action.html">Action</a></li><li><a href="Channel.html">Channel</a></li><li><a href="Client.html">Client</a></li><li><a href="Raptor.html">Raptor</a></li><li><a href="RecordSet.html">RecordSet</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="ServiceObject.html">ServiceObject</a></li><li><a href="Stream.html">Stream</a></li><li><a href="User.html">User</a></li></ul><h3>Global</h3><ul><li><a href="global.html#Container">Container</a></li></ul>
|
190 | </nav>
|
191 |
|
192 | <br class="clear">
|
193 |
|
194 | <footer>
|
195 | Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.2</a> on Wed Nov 02 2016 11:15:06 GMT+0100 (CET)
|
196 | </footer>
|
197 |
|
198 | <script> prettyPrint(); </script>
|
199 | <script src="scripts/linenumber.js"> </script>
|
200 | </body>
|
201 | </html>
|