// Generated by LiveScript 1.2.0
(function(){
  var util, flatten, Debugger, ManagedSubjectMatcher, SubjectMatcher, RuleMixin, RuleActionMatcher;
  util = require('../../../util');
  flatten = util.array.flatten;
  Debugger = util.Debugger;
  ManagedSubjectMatcher = require('./managed_subject_matcher');
  SubjectMatcher = require('./rule_subject_matcher');
  RuleMixin = require('../rule_mixin');
  module.exports = RuleActionMatcher = (function(){
    RuleActionMatcher.displayName = 'RuleActionMatcher';
    var prototype = RuleActionMatcher.prototype, constructor = RuleActionMatcher;
    importAll$(prototype, arguments[0]);
    importAll$(prototype, arguments[1]);
    function RuleActionMatcher(container, debugging){
      this.container = container;
      this.debugging = debugging;
      this.debug('@container', this.container);
    }
    prototype.match = function(subject){
      this.debug('match', subject);
      if (!subject) {
        return false;
      }
      return this.isManaged(subject);
    };
    prototype.isManaged = function(subject){
      if (this.matchSubject(subject)) {
        return true;
      }
      return this.matchesAllManageActions(subject);
    };
    prototype.matchesAllManageActions = function(subject){
      var i$, ref$, len$, subjects;
      for (i$ = 0, len$ = (ref$ = this.manageActionSubjects()).length; i$ < len$; ++i$) {
        subjects = ref$[i$];
        if (!this.matchSubject(subject, subjects || [])) {
          return false;
        }
      }
      return true;
    };
    prototype.managedSubjects = function(){
      return this._managedSubjects || (this._managedSubjects = this.container['manage'] || []);
    };
    prototype.matchSubject = function(subject, subjects){
      return this.subjectMatcher(subjects).match(subject);
    };
    prototype.subjectMatcher = function(subjects){
      subjects || (subjects = this.managedSubjects());
      return new SubjectMatcher(subjects);
    };
    prototype.manageActionSubjects = function(){
      var self;
      self = this;
      return this.manageActions.map(function(action){
        return self.container[action];
      });
    };
    return RuleActionMatcher;
  }(Debugger, RuleMixin));
  function importAll$(obj, src){
    for (var key in src) obj[key] = src[key];
    return obj;
  }
}).call(this);
