angoose
Version:
Angoose is a Remote Method Invocation module that comes with built-in mongoose/angular support. Now you can call server side module in browser just like you're in the server side!
145 lines (108 loc) • 5.74 kB
HTML
<html>
<head>
<title>Service.js</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<a class="source" href="Context.html">
Context.js
</a>
<a class="source" href="Model.html">
Model.js
</a>
<a class="source" href="Principal.html">
Principal.js
</a>
<a class="source" href="Remotable.html">
Remotable.js
</a>
<a class="source" href="Schema.html">
Schema.js
</a>
<a class="source" href="Service.html">
Service.js
</a>
<a class="source" href="angoose.html">
angoose.js
</a>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>Service.js</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
</div>
<div class="content"><div class='highlight'><pre><span class="keyword">var</span> logger = require(<span class="string">"log4js"</span>).getLogger(<span class="string">"angoose"</span>);
<span class="keyword">var</span> _ =require(<span class="string">"underscore"</span>);
<span class="keyword">var</span> Remotable = require(<span class="string">"./Remotable"</span>)</pre></div></div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<h2 id="angoose-service">angoose.Service</h2>
<p>Service is one of two main artifacts in Angoose. Service classes are used to define business operations that
are not necessarily tied to database models.</p>
<p>To create an angoose Service, you just need to extend from this class:</p>
<pre><code> var angoose = require("angoose");
var service = {
geoEncode: function(stringAddress){
/** call google API */
return coordinates
}
}
module.export = angoose.service('GeoService', service);</code></pre>
<p>The Service class file must be located under one of the <code>modelDir</code> or <code>serviceDir</code> directories.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="keyword">var</span> serviceProto = {
toJSON: <span class="function"><span class="keyword">function</span><span class="params">()</span>{</span>
<span class="keyword">return</span> {};
}
}
<span class="keyword">var</span> Service = Remotable.extend(serviceProto,{baseClass:<span class="string">'Service'</span>});
Service.getSchema = <span class="function"><span class="keyword">function</span><span class="params">()</span>{</span>
<span class="keyword">var</span> thisClass = <span class="keyword">this</span>;
<span class="keyword">var</span> schema = {statics: {} };
schema.methods = _.extend({}, thisClass.prototype)
<span class="keyword">for</span>(<span class="keyword">var</span> name <span class="keyword">in</span> schema.methods){
<span class="keyword">if</span>( filter(name) ) <span class="keyword">delete</span> schema.methods[name];
}
<span class="keyword">for</span>(<span class="keyword">var</span> name <span class="keyword">in</span> thisClass){
<span class="keyword">var</span> val = thisClass[name];
<span class="keyword">if</span>( filter(name) ) <span class="keyword">continue</span>;
<span class="keyword">if</span>(<span class="keyword">typeof</span> (val) != <span class="string">'function'</span>) <span class="keyword">continue</span>;
schema.statics[name] = val;
}
<span class="keyword">return</span> schema;
}
<span class="function"><span class="keyword">function</span> <span class="title">filter</span><span class="params">(methodName)</span>{</span>
<span class="keyword">if</span>(Remotable.isRemotableReserved(methodName)) <span class="keyword">return</span> <span class="literal">true</span>;
<span class="keyword">if</span>([<span class="string">'extend'</span>, <span class="string">'getContext'</span>, <span class="string">'getSchema'</span>,<span class="string">'toJSON'</span> ].indexOf(methodName)>=<span class="number">0</span>) <span class="keyword">return</span> <span class="literal">true</span>;
<span class="keyword">return</span> <span class="literal">false</span>;
}
module.exports = Service;</pre></div></div>
</li>
</ul>
</div>
</body>
</html>