goodguide-gibbon 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module GoodGuide
2
2
  module Gibbon
3
3
  def self.version
4
- '0.4.1'
4
+ '0.4.2'
5
5
  end
6
6
  end
7
7
  end
@@ -116,6 +116,14 @@ module GoodGuide
116
116
  def initialize(type, id, annotations)
117
117
  @query_type, @id, @annotations = type, id, annotations
118
118
  end
119
+
120
+ def equals(other)
121
+ [
122
+ query_type == other.query_type,
123
+ id == other.id,
124
+ annotations == other.annotations
125
+ ].all?
126
+ end
119
127
  end
120
128
 
121
129
  class Program
@@ -169,7 +177,7 @@ module GoodGuide
169
177
  @queries ||= {}
170
178
  end
171
179
 
172
- def self.query(type, &impl)
180
+ def self.query(type, opts={}, &impl)
173
181
  queries[type.to_s] = impl
174
182
  end
175
183
 
@@ -205,6 +213,20 @@ module GoodGuide
205
213
  raise QueryError.new(*a)
206
214
  end
207
215
 
216
+ def self.query(type, opts={}, &impl)
217
+ arity = opts.fetch(:arity, 1)
218
+ super type, opts do |input, args, builder|
219
+ if args.size != arity
220
+ query_error!(
221
+ "wrong number of arguments: " +
222
+ "#{args.size} for #{arity} (in .#{type} #{args.join(' ')})"
223
+ )
224
+ end
225
+
226
+ self.instance_exec(input, *args, builder, &impl)
227
+ end
228
+ end
229
+
208
230
  def analyze_query(input_id, query, t)
209
231
  query_impl = get_query(query.type)
210
232
  analysis = instance_exec(input_id, obj_to_ruby(query.args), t, &query_impl)
@@ -1110,7 +1110,6 @@ parse = Gibbon.parse = (function() {
1110
1110
  return AST.string(s);
1111
1111
  });
1112
1112
  accessorExpr = accessor.map(function(name) {
1113
- debugger;
1114
1113
  return AST.query('access', [name]);
1115
1114
  });
1116
1115
  queryExpr = query.then(function(q) {
@@ -2366,10 +2365,12 @@ Value = Gibbon.Value = Value = (function(_super) {
2366
2365
  });
2367
2366
  },
2368
2367
  pair: function(eFirst, eSecond) {
2369
- return Promise.combine([eFirst, eSecond]).then(function(first, second) {
2370
- return Promise.combine([f(first), f(second)]).map(function(_arg) {
2368
+ return Promise.combine([eFirst, eSecond]).then(function(_arg) {
2369
+ var first, second;
2370
+ first = _arg[0], second = _arg[1];
2371
+ return Promise.combine([f(first), f(second)]).map(function(_arg1) {
2371
2372
  var mFirst, mSecond;
2372
- mFirst = _arg[0], mSecond = _arg[1];
2373
+ mFirst = _arg1[0], mSecond = _arg1[1];
2373
2374
  return Value.pair(mFirst, mSecond);
2374
2375
  });
2375
2376
  });
@@ -2626,7 +2627,7 @@ Gibbon.Dependency = Dependency = (function(_super) {
2626
2627
  eval_ = Gibbon["eval"] = (function() {
2627
2628
  var evalAll;
2628
2629
  evalAll = function(semantics, entity, client) {
2629
- var evalFlow, globalPromise, resultThunks, results;
2630
+ var evalFlow, globalPromise, resultThunks, results, toForce;
2630
2631
  results = new Hash;
2631
2632
  globalPromise = Promise.unit(entity);
2632
2633
  resultThunks = new Hash;
@@ -2634,11 +2635,6 @@ eval_ = Gibbon["eval"] = (function() {
2634
2635
  return resultThunks.set(key, Promise.lazy(function() {
2635
2636
  return evalFlow(definition.flow, globalPromise).then(function(val) {
2636
2637
  return val.resolve();
2637
- }).after(function(val, deps) {
2638
- deps = uniq(deps, function(x, y) {
2639
- return x.equals(y);
2640
- });
2641
- return results.set(key, [val, deps]);
2642
2638
  });
2643
2639
  }));
2644
2640
  });
@@ -2728,7 +2724,20 @@ eval_ = Gibbon["eval"] = (function() {
2728
2724
  }
2729
2725
  });
2730
2726
  };
2731
- return Promise.combine(resultThunks.values()).map(function() {
2727
+ toForce = [];
2728
+ resultThunks.each(function(key, thunk) {
2729
+ return toForce.push(thunk.rescue(function(failure) {
2730
+ results.set(key, [null, [Dependency.failure(failure)]]);
2731
+ resultThunks.set(key, Promise.fail(failure));
2732
+ return Promise.unit(null);
2733
+ }).after(function(val, deps) {
2734
+ deps = uniq(deps, function(x, y) {
2735
+ return x.equals(y);
2736
+ });
2737
+ return results.set(key, [val, deps]);
2738
+ }));
2739
+ });
2740
+ return Promise.combine(toForce).map(function() {
2732
2741
  return results;
2733
2742
  });
2734
2743
  };
@@ -2749,7 +2758,13 @@ eval_ = Gibbon["eval"] = (function() {
2749
2758
  return finish(fail);
2750
2759
  };
2751
2760
  onSuccess = function(vals) {
2752
- return finish(null, vals);
2761
+ var deps, val, _ref4;
2762
+ _ref4 = vals.get('/'), val = _ref4[0], deps = _ref4[1];
2763
+ if (val) {
2764
+ return finish(null, vals);
2765
+ } else {
2766
+ return finish(deps[0].failure);
2767
+ }
2753
2768
  };
2754
2769
  return evalAll(semantics, entity, client).force(onFailure, onSuccess);
2755
2770
  };
@@ -3324,7 +3339,6 @@ stdlib = Gibbon.stdlib = (function() {
3324
3339
  "case-eq": {
3325
3340
  type: parse.type('case-eq [%a : %b] = %a -> %b'),
3326
3341
  impl: function(evalInput, evalList) {
3327
- debugger;
3328
3342
  return combine([evalInput, evalList]).then(function(_arg) {
3329
3343
  var input, list, out, step;
3330
3344
  input = _arg[0], list = _arg[1];
@@ -3455,7 +3469,6 @@ stdlib = Gibbon.stdlib = (function() {
3455
3469
  "include?": {
3456
3470
  type: parse.type('include? %a = [%a] -> bool'),
3457
3471
  impl: function(evalList, evalElement) {
3458
- debugger;
3459
3472
  return combine([evalElement, evalList]).then(function(_arg) {
3460
3473
  var booleans, el, list, p;
3461
3474
  el = _arg[0], list = _arg[1];
@@ -3729,24 +3742,16 @@ stdlib = Gibbon.stdlib = (function() {
3729
3742
  _results = [];
3730
3743
  for (_i = 0, _len = elements.length; _i < _len; _i++) {
3731
3744
  promise = elements[_i];
3732
- _results.push(promise.map(function(e) {
3733
- return [e];
3745
+ _results.push(promise.then(function(e) {
3746
+ return e.resolve().map(function(e) {
3747
+ return [e.promise()];
3748
+ });
3734
3749
  }).or(unit([])));
3735
3750
  }
3736
3751
  return _results;
3737
3752
  })();
3738
3753
  return combine(wrapped).map(function(lists) {
3739
- var e;
3740
- return Value.list((function() {
3741
- var _i, _len, _ref, _results;
3742
- _ref = catLists(lists);
3743
- _results = [];
3744
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3745
- e = _ref[_i];
3746
- _results.push(unit(e));
3747
- }
3748
- return _results;
3749
- })());
3754
+ return Value.list(catLists(lists));
3750
3755
  });
3751
3756
  });
3752
3757
  },
@@ -3920,7 +3925,6 @@ Gibbon.jsonConsumer = (function() {
3920
3925
  };
3921
3926
  return {
3922
3927
  analyzeQuery: function(id, query, t, callback) {
3923
- debugger;
3924
3928
  switch (query.type) {
3925
3929
  case 'access':
3926
3930
  return getType(id, query.args[0], t, callback);
@@ -1104,7 +1104,6 @@ parse = Gibbon.parse = (function() {
1104
1104
  return AST.string(s);
1105
1105
  });
1106
1106
  accessorExpr = accessor.map(function(name) {
1107
- debugger;
1108
1107
  return AST.query('access', [name]);
1109
1108
  });
1110
1109
  queryExpr = query.then(function(q) {
@@ -2338,10 +2337,12 @@ Value = Gibbon.Value = Value = (function(_super) {
2338
2337
  });
2339
2338
  },
2340
2339
  pair: function(eFirst, eSecond) {
2341
- return Promise.combine([eFirst, eSecond]).then(function(first, second) {
2342
- return Promise.combine([f(first), f(second)]).map(function(_arg) {
2340
+ return Promise.combine([eFirst, eSecond]).then(function(_arg) {
2341
+ var first, second;
2342
+ first = _arg[0], second = _arg[1];
2343
+ return Promise.combine([f(first), f(second)]).map(function(_arg1) {
2343
2344
  var mFirst, mSecond;
2344
- mFirst = _arg[0], mSecond = _arg[1];
2345
+ mFirst = _arg1[0], mSecond = _arg1[1];
2345
2346
  return Value.pair(mFirst, mSecond);
2346
2347
  });
2347
2348
  });
@@ -2598,7 +2599,7 @@ Gibbon.Dependency = Dependency = (function(_super) {
2598
2599
  eval_ = Gibbon["eval"] = (function() {
2599
2600
  var evalAll;
2600
2601
  evalAll = function(semantics, entity, client) {
2601
- var evalFlow, globalPromise, resultThunks, results;
2602
+ var evalFlow, globalPromise, resultThunks, results, toForce;
2602
2603
  results = new Hash;
2603
2604
  globalPromise = Promise.unit(entity);
2604
2605
  resultThunks = new Hash;
@@ -2606,11 +2607,6 @@ eval_ = Gibbon["eval"] = (function() {
2606
2607
  return resultThunks.set(key, Promise.lazy(function() {
2607
2608
  return evalFlow(definition.flow, globalPromise).then(function(val) {
2608
2609
  return val.resolve();
2609
- }).after(function(val, deps) {
2610
- deps = uniq(deps, function(x, y) {
2611
- return x.equals(y);
2612
- });
2613
- return results.set(key, [val, deps]);
2614
2610
  });
2615
2611
  }));
2616
2612
  });
@@ -2700,7 +2696,20 @@ eval_ = Gibbon["eval"] = (function() {
2700
2696
  }
2701
2697
  });
2702
2698
  };
2703
- return Promise.combine(resultThunks.values()).map(function() {
2699
+ toForce = [];
2700
+ resultThunks.each(function(key, thunk) {
2701
+ return toForce.push(thunk.rescue(function(failure) {
2702
+ results.set(key, [null, [Dependency.failure(failure)]]);
2703
+ resultThunks.set(key, Promise.fail(failure));
2704
+ return Promise.unit(null);
2705
+ }).after(function(val, deps) {
2706
+ deps = uniq(deps, function(x, y) {
2707
+ return x.equals(y);
2708
+ });
2709
+ return results.set(key, [val, deps]);
2710
+ }));
2711
+ });
2712
+ return Promise.combine(toForce).map(function() {
2704
2713
  return results;
2705
2714
  });
2706
2715
  };
@@ -2721,7 +2730,13 @@ eval_ = Gibbon["eval"] = (function() {
2721
2730
  return finish(fail);
2722
2731
  };
2723
2732
  onSuccess = function(vals) {
2724
- return finish(null, vals);
2733
+ var deps, val, _ref4;
2734
+ _ref4 = vals.get('/'), val = _ref4[0], deps = _ref4[1];
2735
+ if (val) {
2736
+ return finish(null, vals);
2737
+ } else {
2738
+ return finish(deps[0].failure);
2739
+ }
2725
2740
  };
2726
2741
  return evalAll(semantics, entity, client).force(onFailure, onSuccess);
2727
2742
  };
@@ -3296,7 +3311,6 @@ stdlib = Gibbon.stdlib = (function() {
3296
3311
  "case-eq": {
3297
3312
  type: parse.type('case-eq [%a : %b] = %a -> %b'),
3298
3313
  impl: function(evalInput, evalList) {
3299
- debugger;
3300
3314
  return combine([evalInput, evalList]).then(function(_arg) {
3301
3315
  var input, list, out, step;
3302
3316
  input = _arg[0], list = _arg[1];
@@ -3427,7 +3441,6 @@ stdlib = Gibbon.stdlib = (function() {
3427
3441
  "include?": {
3428
3442
  type: parse.type('include? %a = [%a] -> bool'),
3429
3443
  impl: function(evalList, evalElement) {
3430
- debugger;
3431
3444
  return combine([evalElement, evalList]).then(function(_arg) {
3432
3445
  var booleans, el, list, p;
3433
3446
  el = _arg[0], list = _arg[1];
@@ -3701,24 +3714,16 @@ stdlib = Gibbon.stdlib = (function() {
3701
3714
  _results = [];
3702
3715
  for (_i = 0, _len = elements.length; _i < _len; _i++) {
3703
3716
  promise = elements[_i];
3704
- _results.push(promise.map(function(e) {
3705
- return [e];
3717
+ _results.push(promise.then(function(e) {
3718
+ return e.resolve().map(function(e) {
3719
+ return [e.promise()];
3720
+ });
3706
3721
  }).or(unit([])));
3707
3722
  }
3708
3723
  return _results;
3709
3724
  })();
3710
3725
  return combine(wrapped).map(function(lists) {
3711
- var e;
3712
- return Value.list((function() {
3713
- var _i, _len, _ref, _results;
3714
- _ref = catLists(lists);
3715
- _results = [];
3716
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3717
- e = _ref[_i];
3718
- _results.push(unit(e));
3719
- }
3720
- return _results;
3721
- })());
3726
+ return Value.list(catLists(lists));
3722
3727
  });
3723
3728
  });
3724
3729
  },
@@ -3892,7 +3897,6 @@ Gibbon.jsonConsumer = (function() {
3892
3897
  };
3893
3898
  return {
3894
3899
  analyzeQuery: function(id, query, t, callback) {
3895
- debugger;
3896
3900
  switch (query.type) {
3897
3901
  case 'access':
3898
3902
  return getType(id, query.args[0], t, callback);
@@ -13,8 +13,7 @@
13
13
  "chai": "1.5.x",
14
14
  "coffee-script": "1.6.x",
15
15
  "supervisor": "0.5.x",
16
- "node-inspector": "0.2.x",
17
- "falafel": "0.2.x"
16
+ "node-inspector": "0.2.x"
18
17
  },
19
18
  "dependencies": {
20
19
  "parsimmon": "0.0.6",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goodguide-gibbon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-16 00:00:00.000000000 Z
12
+ date: 2013-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: therubyracer
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
55
  version: '0'
56
56
  segments:
57
57
  - 0
58
- hash: 970045023532317633
58
+ hash: 207982896115587216
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  none: false
61
61
  requirements:
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  segments:
66
66
  - 0
67
- hash: 970045023532317633
67
+ hash: 207982896115587216
68
68
  requirements: []
69
69
  rubyforge_project: goodguide-gibbon
70
70
  rubygems_version: 1.8.23