// Generated by IcedCoffeeScript 1.7.1-c
(function() {
  var GitPreset, GlobberPreset, PresetBase, constants, iced, path, __iced_k, __iced_k_noop,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  iced = require('iced-runtime').iced;
  __iced_k = __iced_k_noop = function() {};

  path = require('path');

  constants = require('../constants');

  PresetBase = require('./preset_base');

  GlobberPreset = require('./globber');

  GitPreset = (function(_super) {
    __extends(GitPreset, _super);

    function GitPreset() {
      this.globbers = {};
    }

    GitPreset.prototype.handle = function(root_dir, path_to_file, cb) {
      var globber, p, paths, res, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      paths = PresetBase.parent_paths(root_dir, path_to_file);
      res = constants.ignore_res.NONE;
      (function(_this) {
        return (function(__iced_k) {
          if (path.basename(path_to_file) === '.git') {
            return __iced_k(res = constants.ignore_res.IGNORE);
          } else {
            (function(__iced_k) {
              var _i, _len, _ref, _results, _while;
              _ref = paths;
              _len = _ref.length;
              _i = 0;
              _results = [];
              _while = function(__iced_k) {
                var _break, _continue, _next;
                _break = function() {
                  return __iced_k(_results);
                };
                _continue = function() {
                  return iced.trampoline(function() {
                    ++_i;
                    return _while(__iced_k);
                  });
                };
                _next = function(__iced_next_arg) {
                  _results.push(__iced_next_arg);
                  return _continue();
                };
                if (!(_i < _len)) {
                  return _break();
                } else {
                  p = _ref[_i];
                  (function(__iced_k) {
                    __iced_deferrals = new iced.Deferrals(__iced_k, {
                      parent: ___iced_passed_deferral,
                      filename: "/Users/max/src/keybase/codesign/src/preset/git.iced",
                      funcname: "GitPreset.handle"
                    });
                    _this.get_globber(p, __iced_deferrals.defer({
                      assign_fn: (function() {
                        return function() {
                          return globber = arguments[0];
                        };
                      })(),
                      lineno: 25
                    }));
                    __iced_deferrals._fulfill();
                  })(function() {
                    (function(__iced_k) {
                      __iced_deferrals = new iced.Deferrals(__iced_k, {
                        parent: ___iced_passed_deferral,
                        filename: "/Users/max/src/keybase/codesign/src/preset/git.iced",
                        funcname: "GitPreset.handle"
                      });
                      globber.handle(root_dir, path_to_file, __iced_deferrals.defer({
                        assign_fn: (function() {
                          return function() {
                            return res = arguments[0];
                          };
                        })(),
                        lineno: 26
                      }));
                      __iced_deferrals._fulfill();
                    })(function() {
                      (function(__iced_k) {
                        if (res !== constants.ignore_res.NONE) {
                          (function(__iced_k) {
_break()
                          })(__iced_k);
                        } else {
                          return __iced_k();
                        }
                      })(_next);
                    });
                  });
                }
              };
              _while(__iced_k);
            })(__iced_k);
          }
        });
      })(this)((function(_this) {
        return function() {
          return cb(res);
        };
      })(this));
    };

    GitPreset.prototype.get_globber = function(p, cb) {
      var fpath, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      (function(_this) {
        return (function(__iced_k) {
          if (_this.globbers[p] == null) {
            fpath = path.join(p, '.gitignore');
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/max/src/keybase/codesign/src/preset/git.iced",
                funcname: "GitPreset.get_globber"
              });
              GlobberPreset.from_file(fpath, __iced_deferrals.defer({
                assign_fn: (function(__slot_1, __slot_2) {
                  return function() {
                    return __slot_1[__slot_2] = arguments[0];
                  };
                })(_this.globbers, p),
                lineno: 36
              }));
              __iced_deferrals._fulfill();
            })(__iced_k);
          } else {
            return __iced_k();
          }
        });
      })(this)((function(_this) {
        return function() {
          return cb(_this.globbers[p]);
        };
      })(this));
    };

    return GitPreset;

  })(PresetBase);

  module.exports = GitPreset;

}).call(this);
