appjs 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e225413d7a2bee9f1d658052a73e56d688ae2c18
4
- data.tar.gz: c73a9df7362f592571b179ad76c4c796c0615bab
3
+ metadata.gz: be0a8f257901bb32bb81b7905ac61698404f6394
4
+ data.tar.gz: 1a397bee83db324c160e798e46d800d633a26ee5
5
5
  SHA512:
6
- metadata.gz: f06123d808e2d9c29cbefedcb0726d270630651eb86fe92ba7be3ea03ed35c8c8a7d254aa9c4a4809ff731ec0324b7335f6da84ab4d398c8899a0321d05fe032
7
- data.tar.gz: 377f816641f268fc61ed97058d57bab752831a61ff0da9beb8942b613e324e4608000b1d9f4b5c5c923289f5ee4be84392aca949636da7bff036d1d0a356553d
6
+ metadata.gz: f6c9a425aab15924dc20c5971fe80b77c06033650128609dc7b3001bcf99ed6aa7030de44e845d482c9508d64145d088b4f6628d76697e41bbb852791814fe15
7
+ data.tar.gz: 340ff2c1849a4a301a40a94bd17bfe1a63ca9bf9f3a367b40acad18ba86b534b8cd1b87849a9e6d5a88d6f4fc8d68470a3031bb9df301bee7a4d9f354edcfcd0
data/lib/appjs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Appjs
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -2,9 +2,10 @@ var App = function () {
2
2
  var app_instance;
3
3
 
4
4
  app_instance = function () {
5
- var app = {},
5
+ var app = {},
6
6
  definitions = {},
7
- constants = {};
7
+ constants = {},
8
+ overwrites = {};
8
9
 
9
10
  app.define = function (constant, definition) {
10
11
  if (definitions[constant] !== undefined) {
@@ -18,6 +19,10 @@ var App = function () {
18
19
  };
19
20
 
20
21
  app.require = function (constant) {
22
+ if (overwrites[constant]) {
23
+ return overwrites[constant]();
24
+ }
25
+
21
26
  if (constants[constant] === undefined) {
22
27
  if (definitions[constant] === undefined) {
23
28
  throw "Constant '" + constant + "' not defined."
@@ -28,6 +33,14 @@ var App = function () {
28
33
  return constants[constant];
29
34
  };
30
35
 
36
+ app.overwrite = function(constant, definition) {
37
+ overwrites[constant] = definition;
38
+ }
39
+
40
+ app.reset = function(constant) {
41
+ delete overwrites[constant];
42
+ }
43
+
31
44
  return app;
32
45
  }
33
46
 
@@ -124,4 +124,36 @@ describe('app', function () {
124
124
 
125
125
  });
126
126
 
127
+ describe('overwrite', function () {
128
+ var namespace;
129
+
130
+ beforeEach(function () {
131
+ namespace = {};
132
+ App.induce(namespace);
133
+ });
134
+
135
+ it('temporarilly overwrites the Result of require', function () {
136
+ namespace.app.define('test', function () {
137
+ return 123
138
+ });
139
+
140
+ assert.equal(namespace.app.require('test'), 123)
141
+
142
+ var count = 0;
143
+ namespace.app.overwrite('test', function () {
144
+ count += 1;
145
+ return count;
146
+ });
147
+
148
+
149
+ assert.equal(namespace.app.require('test'), 1)
150
+ assert.equal(namespace.app.require('test'), 2)
151
+ assert.equal(namespace.app.require('test'), 3)
152
+
153
+ namespace.app.reset('test')
154
+
155
+ assert.equal(namespace.app.require('test'), 123)
156
+ });
157
+ });
158
+
127
159
  });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Holderbaum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-19 00:00:00.000000000 Z
11
+ date: 2013-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler