If a rule can be found that matches the task name, enhance the
 task with the prerequisites and actions from the rule.  Set the
 source attribute of the task appropriately for the rule.  Return
 the enhanced task or nil of no rule was found.
500334
def enhance_with_matching_rule(task_name, level=0)
      fail Rake::RuleRecursionOverflowError,
        "Rule Recursion Too Deep" if level >= 16
      @rules.each do |pattern, args, extensions, block|
        if pattern && pattern.match(task_name)
          task = attempt_rule(task_name, pattern, args, extensions, block, level)
          return task if task
        end
      end
      nil
    rescue Rake::RuleRecursionOverflowError => ex
      ex.add_target(task_name)
      fail ex
    end
630388
def clone(self, **kwargs):
        

        # First, create exact copy of the current Task object
        attr_copy = self.__dict__.copy()
        if attr_copy.get('grab_config') is not None:
            del attr_copy['url']
        if not attr_copy['priority_set_explicitly']:
            attr_copy['priority'] = None
        task = Task(**attr_copy)

        # Reset some task properties if they have not
        # been set explicitly in kwargs
        if 'network_try_count' not in kwargs:
            task.network_try_count = 0
        if 'task_try_count' not in kwargs:
            task.task_try_count = self.task_try_count + 1
        if 'refresh_cache' not in kwargs:
            task.refresh_cache = False
        if 'disable_cache' not in kwargs:
            task.disable_cache = False

        if kwargs.get('url') is not None and kwargs.get('grab') is not None:
            raise SpiderMisuseError('Options url and grab could not be '
                                    'used together')

        if (kwargs.get('url') is not None and
                kwargs.get('grab_config') is not None):
            raise SpiderMisuseError('Options url and grab_config could not '
                                    'be used together')

        if (kwargs.get('grab') is not None and
                kwargs.get('grab_config') is not None):
            raise SpiderMisuseError('Options grab and grab_config could not '
                                    'be used together')

        if kwargs.get('grab'):
            task.setup_grab_config(kwargs['grab'].dump_config())
            del kwargs['grab']
        elif kwargs.get('grab_config'):
            task.setup_grab_config(kwargs['grab_config'])
            del kwargs['grab_config']
        elif kwargs.get('url'):
            task.url = kwargs['url']
            if task.grab_config:
                task.grab_config['url'] = kwargs['url']
            del kwargs['url']

        for key, value in kwargs.items():
            setattr(task, key, value)

        task.process_delay_option(None)

        return task
1080316
def source_attr(attr_name):
    

    def source_attr(value, context, **_params):
        setattr(context["model"].source, attr_name, value)
        return _attr()

    return source_attr
789930
def task(name, options = {}, &block)
      name = name.to_s.downcase.to_sym
      task_re = /\A[a-z0-9.:-_]+\z/
      raise "Task already exists: #{name}" if $bot[:tasks].include?(name)
      raise "Task name does not match regexp #{task_re.to_s}" unless name.to_s.match(task_re)

      opts = {
        desc: ''
      }.merge(options)

      $bot[:tasks][name] ||= {
        block: block,
        desc: opts[:desc]
      }
    end
317196
def rule_expand(component, text):
    ''''''
    global rline_mpstate
    if component[0] == '<' and component[-1] == '>':
        return component[1:-1].split('|')
    if component in rline_mpstate.completion_functions:
        return rline_mpstate.completion_functions[component](text)
    return [component]
307467
def build_task_template
      b = binding
      ERB.new(Woro::TaskHelper.read_template_file).result(b)
    end
624365
def add_task_attribute(self, name, **attrs):
        
        return TaskAttributes(self.requester).create(
            self.id, name, **attrs
        )
380639
def extend(self, tasks):
        ''''''
        self._tasks.extend(tasks)
        for task in tasks:
            # We'll now go through all of our tasks and group them into
            # sub-shovels
            current = self.map
            modules = task.fullname.split('.')
            for module in modules[:-1]:
                if not isinstance(current[module], Shovel):
                    logger.warn('Overriding task %s with a module' %
                        current[module].file)
                    shovel = Shovel()
                    shovel.overrides = current[module]
                    current[module] = shovel
                current = current[module].map

            # Now we'll put the task in this particular sub-shovel
            name = modules[-1]
            if name in current:
                logger.warn('Overriding %s with %s' % (
                    '.'.join(modules), task.file))
                task.overrides = current[name]
            current[name] = task
387958
def with_rule(self, rule):
        
        self.rules = self.rules if self.rules != None else []
        self.rules.append(rule)
        return self
209549
def matches_conditions?(action, subject, attribute = nil, *extra_args)
      return call_block_with_all(action, subject, extra_args) if @match_all
      return matches_block_conditions(subject, attribute, *extra_args) if @block
      return matches_non_block_conditions(subject) unless conditions_empty?

      true
    end
1085509
def execute(self, env, args):
        

        task_name = args.task_name

        if not env.task.exists(task_name):
            raise errors.TaskNotFound(task_name)

        if env.task.active and task_name == env.task.name:
            raise errors.ActiveTask

        # open in task config in editor
        task_config = env.task.get_config_path(task_name)

        if not _edit_task_config(env, task_config, confirm=True):
            raise errors.FocusError(u'Could not open task config: {0}'
                                    .format(task_config))
1270928
def apply_extends(self, rules):
        
        # Game plan: for each rule that has an @extend, add its selectors to
        # every rule that matches that @extend.
        # First, rig a way to find arbitrary selectors quickly.  Most selectors
        # revolve around elements, classes, and IDs, so parse those out and use
        # them as a rough key.  Ignore order and duplication for now.
        key_to_selectors = defaultdict(set)
        selector_to_rules = defaultdict(set)
        rule_selector_order = {}
        order = 0
        for rule in rules:
            for selector in rule.selectors:
                for key in selector.lookup_key():
                    key_to_selectors[key].add(selector)
                selector_to_rules[selector].add(rule)
                rule_selector_order[rule, selector] = order
                order += 1

        # Now go through all the rules with an @extends and find their parent
        # rules.
        for rule in rules:
            for selector in rule.extends_selectors:
                # This is a little dirty.  intersection isn't a class method.
                # Don't think about it too much.
                candidates = set.intersection(*(
                    key_to_selectors[key] for key in selector.lookup_key()))
                extendable_selectors = [
                    candidate for candidate in candidates
                    if candidate.is_superset_of(selector)]

                if not extendable_selectors:
                    # TODO implement !optional
                    warn_deprecated(
                        rule,
                        "Can't find any matching rules to extend {0!r} -- this "
                        "will be fatal in 2.0, unless !optional is specified!"
                        .format(selector.render()))
                    continue

                # Armed with a set of selectors that this rule can extend, do
                # some substitution and modify the appropriate parent rules.
                # One tricky bit: it's possible we're extending two selectors
                # that both exist in the same parent rule, in which case we
                # want to extend in the order the original selectors appear in
                # that rule.
                known_parents = []
                for extendable_selector in extendable_selectors:
                    parent_rules = selector_to_rules[extendable_selector]
                    for parent_rule in parent_rules:
                        if parent_rule is rule:
                            # Don't extend oneself
                            continue
                        known_parents.append(
                            (parent_rule, extendable_selector))
                # This will put our parents back in their original order
                known_parents.sort(key=rule_selector_order.__getitem__)

                for parent_rule, extendable_selector in known_parents:
                    more_parent_selectors = []

                    for rule_selector in rule.selectors:
                        more_parent_selectors.extend(
                            extendable_selector.substitute(
                                selector, rule_selector))

                    for parent in more_parent_selectors:
                        # Update indices, in case later rules try to extend
                        # this one
                        for key in parent.lookup_key():
                            key_to_selectors[key].add(parent)
                        selector_to_rules[parent].add(parent_rule)
                        rule_selector_order[parent_rule, parent] = order
                        order += 1

                    parent_rule.ancestry = (
                        parent_rule.ancestry.with_more_selectors(
                            more_parent_selectors))

        # Remove placeholder-only rules
        return [rule for rule in rules if not rule.is_pure_placeholder]
11209
def [](task_name, scopes=nil)
      task_name = task_name.to_s
      self.lookup(task_name, scopes) or
        enhance_with_matching_rule(task_name) or
        synthesize_file_task(task_name) or
        fail "Don't know how to build task '#{task_name}'"
    end
543040
def relevant_rules_for_match(self, action, subject):
        """"""
        matches = []
        for rule in self.rules:
            rule.expanded_actions = self.expand_actions(rule.actions)
            if rule.is_relevant(action, subject):
                matches.append(rule)

        return self.optimize(matches[::-1])
1204503
def on_rule_prototype(node, compiled_grammar)
      name = process(node.children[0], compiled_grammar)

      return if compiled_grammar.has_rule?(name)

      rule = Rule.new(name, node.source_line)

      compiled_grammar.add_rule(rule)
    end
1272553
function extend(oTarget, oSource) {
			var sName;

			for (sName in oSource) {
				if (bPrivileged || !(sName in oTarget)) {
					oTarget[sName] = oSource[sName];
				}
			}
		}
253727
def _process_rule(self, rule: dict, context: dict):
        
        if not rule or not self._shall_proceed(rule):
            return
        self.context.update(context)
        self.context.update(rule.get('context', {}))
        self.path = rule.get('path', None)
        self.source = rule.get('source', None)
        for entry in rule.get('documents', []):
            target, source = self._resolve_rule_document(entry)
            self.write(target, source)
        for entry in rule.get('preserve', []):
            target, source = self._resolve_rule_document(entry)
            self.write(target, source, preserve=True)