Sha256: 56b445255a4ff01c63294e7b5369de9c0084c270dc2be22dcb46224771f1baec

Contents?: true

Size: 1.96 KB

Versions: 119

Compression:

Stored size: 1.96 KB

Contents

# 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(/<Reference Include="([\w\.-]+)"[\s]+\//).each{|m|
	  dep=m.first.to_s
	  deps << dep if(!deps.include?(dep))
	}
	deps
  end

  def self.csharp_file_dependencies source
    deps=Array.new
    source.scan(/<HintPath>([\w\.\\\s-]+)</).each{|m|
	  dep=m.first.to_s
	  deps << dep if(!deps.include?(dep))
	}
	deps
  end

  def show
    self.each do |key,array|
	  if(array.length > 0)
	    puts key
	    array.each {|v|
	      puts "  " + Color.green + v + Color.clear + " "
	    }
	  end
	end
	puts " "
  end
end

Version data entries

119 entries across 119 versions & 1 rubygems

Version Path
dev_tasks-0.0.163 lib/dependencies.rb
dev_tasks-0.0.162 lib/dependencies.rb
dev_tasks-0.0.161 lib/dependencies.rb
dev_tasks-0.0.160 lib/dependencies.rb
dev_tasks-0.0.159 lib/dependencies.rb
dev_tasks-0.0.158 lib/dependencies.rb
dev_tasks-0.0.157 lib/dependencies.rb
dev_tasks-0.0.156 lib/dependencies.rb
dev_tasks-0.0.155 lib/dependencies.rb
dev_tasks-0.0.154 lib/dependencies.rb
dev_tasks-0.0.153 lib/dependencies.rb
dev_tasks-0.0.152 lib/dependencies.rb
dev_tasks-0.0.151 lib/dependencies.rb
dev_tasks-0.0.150 lib/dependencies.rb
dev_tasks-0.0.149 lib/dependencies.rb
dev_tasks-0.0.148 lib/dependencies.rb
dev_tasks-0.0.147 lib/dependencies.rb
dev_tasks-0.0.146 lib/dependencies.rb
dev_tasks-0.0.145 lib/dependencies.rb
dev_tasks-0.0.144 lib/dependencies.rb