Class: Dependencies

Inherits:
Hash
  • Object
show all
Defined in:
lib/dependencies.rb

Overview

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=[‘json’,‘yaml’]

C# dependencies are returned as a hash, as they are seperated into two groups, :system and :file

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDependencies

Returns a new instance of Dependencies.



16
17
18
# File 'lib/dependencies.rb', line 16

def initialize
  discover
end

Class Method Details

.csharp_file_dependencies(source) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/dependencies.rb', line 60

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

.csharp_system_dependencies(source) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/dependencies.rb', line 51

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

.ruby_dependencies(source) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/dependencies.rb', line 42

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

Instance Method Details

#discoverObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dependencies.rb', line 20

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

#showObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dependencies.rb', line 69

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