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.62 lib/dependencies.rb
dev_tasks-0.0.61 lib/dependencies.rb
dev_tasks-0.0.60 lib/dependencies.rb
dev_tasks-0.0.59 lib/dependencies.rb
dev_tasks-0.0.58 lib/dependencies.rb
dev_tasks-0.0.57 lib/dependencies.rb
dev_tasks-0.0.56 lib/dependencies.rb
dev_tasks-0.0.55 lib/dependencies.rb
dev_tasks-0.0.54 lib/dependencies.rb
dev_tasks-0.0.53 lib/dependencies.rb
dev_tasks-0.0.52 lib/dependencies.rb
dev_tasks-0.0.51 lib/dependencies.rb
dev_tasks-0.0.50 lib/dependencies.rb
dev_tasks-0.0.49 lib/dependencies.rb
dev_tasks-0.0.48 lib/dependencies.rb
dev_tasks-0.0.47 lib/dependencies.rb
dev_tasks-0.0.46 lib/dependencies.rb
dev_tasks-0.0.45 lib/dependencies.rb
dev_tasks-0.0.44 lib/dependencies.rb