Sha256: a9c5121bb7014b0e823867fb0192b17e39d256911970a6e6782a82dc2701e7dd
Contents?: true
Size: 1.41 KB
Versions: 4
Compression:
Stored size: 1.41 KB
Contents
require 'active_support/inflector' require 'tsort' require 'pp' module Shhh module App module Commands class DependencyResolver < Hash include TSort alias tsort_each_node each_key def tsort_each_child(node, &block) fetch(node).each(&block) end end @dependency = DependencyResolver.new @commands = Set.new class << self attr_accessor :commands, :dependency def register(command_class) self.commands << command_class self.dependency[command_class.short_name] ||= [] end def order(command_class, after) self.dependency[command_class.short_name].unshift(after) if after self.dependency[command_class.short_name].flatten! end def dependencies @dependencies ||= self.dependency.tsort @dependencies end # Sort commands based on the #dependencies array, which itself is sorted # based on command dependencies. def sorted_commands @sorted_commands ||= self.commands.to_a.sort_by{|klass| dependencies.index(klass.short_name) } @sorted_commands end def find_command_class(opts) self.sorted_commands.each do |command_class| return command_class if command_class.options_satisfied_by?(opts.to_hash) end nil end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
shhh-1.5.4 | lib/shhh/app/commands.rb |
shhh-1.4.1 | lib/shhh/app/commands.rb |
shhh-1.4.0 | lib/shhh/app/commands.rb |
shhh-1.3.0 | lib/shhh/app/commands.rb |