# The discover method defines the following keys as appropriate: # :ruby a string array of discovered require statements # for example, # given rb file containing # require 'json' # require 'yaml' # the resulting dependies would be # dep[:ruby]=['json','yaml'] # # C# dependencies are returned as a hash, as they are seperated into # two groups, :system and :file # # class Dependencies < Hash def initialize discover end def discover ruby_deps=Array.new cs_system_deps=Array.new cs_file_deps=Array.new Dir.glob("**/*.rb").each{|f| text=File.read(f) ruby_deps=ruby_deps|Dependencies.ruby_dependencies(text) } Dir.glob("*.csproj").each{|f| text=File.read(f) cs_system_deps=cs_system_deps|Dependencies.csharp_system_dependencies(text) cs_file_deps=cs_file_deps|Dependencies.csharp_file_dependencies(text) } self[:ruby]=ruby_deps.sort if(ruby_deps.length>0) if(cs_system_deps.length > 0 || cs_file_deps.length > 0) self["C#"]=Hash.new self["C#"][:system]=cs_system_deps.sort if(cs_system_deps.length > 0) self["C#"][:file]=cs_file_deps.sort if(cs_file_deps.length > 0) end end def self.ruby_dependencies source result=Array.new source.scan(/require '([\w\/]+)/).each{|m| dep=m.first.to_s result << dep if(!result.include?(dep)) } return result end def self.csharp_system_dependencies source deps=Array.new source.scan(/([\w\.\\\s-]+) 0) puts key array.each {|v| puts " " + Color.green + v + Color.clear + " " } end end puts " " end end