Module: Files::Dependencies
- Defined in:
- lib/specss/files.rb
Class Method Summary collapse
-
.get_dependencies(file) ⇒ Object
Takes in a file and returns all files that are dependents as an array of files without extension.
Class Method Details
.get_dependencies(file) ⇒ Object
Takes in a file and returns all files that are dependents as an array of files without extension
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/specss/files.rb', line 33 def self.get_dependencies(file) dependents = [] # Get file name without extension and convert to camel case basename = File.basename(file, ".*") basename = basename.gsub(/(?:^|_)([a-z])/) do $1.upcase end # Get rubrowser output and parse for the relation data output = %x|rubrowser &| data = output.match(/var\s+data\s+=\s+(.*?);/m)[1].split('</script>')[0] data_hash = JSON.parse(data) relations = data_hash['relations'] # Return dependents of input file dependents_data = relations.select { |i| i['resolved_namespace'] == basename } dependents_data.each do |d| filename = d['file'] basename = File.basename(filename, ".*") next if basename.include? '_spec' dependents.push(basename) unless dependents.include? basename end dependents end |