Module: Bibliothecary::Analyser::ClassMethods

Defined in:
lib/bibliothecary/analyser.rb

Instance Method Summary collapse

Instance Method Details

#analyse(folder_path, file_list) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/bibliothecary/analyser.rb', line 24

def analyse(folder_path, file_list)
  file_list.map do |path|
    filename = path.gsub(folder_path, '').gsub(/^\//, '')
    contents = File.open(path).read
    analyse_contents(filename, contents)
  end.compact
end

#analyse_contents(filename, contents) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bibliothecary/analyser.rb', line 32

def analyse_contents(filename, contents)
  begin
    dependencies = parse_file(filename, contents)
    if dependencies && dependencies.any?
      {
        platform: platform_name,
        path: filename,
        dependencies: dependencies,
        kind: determine_kind(filename)
      }
    else
      nil
    end
  rescue
    nil
  end
end

#determine_kind(filename) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/bibliothecary/analyser.rb', line 50

def determine_kind(filename)
  mapping.each do |regex, details|
    if filename.match(regex)
      return details[:kind]
    end
  end
  return []
end

#match?(filename) ⇒ Boolean

Returns:

  • (Boolean)


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

def match?(filename)
  mapping.keys.any?{|regex| filename.match(regex) }
end

#parse_file(filename, contents) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/bibliothecary/analyser.rb', line 7

def parse_file(filename, contents)
  mapping.each do |regex, details|
    if filename.match(regex)
      return send(details[:parser], contents)
    end
  end
  return []
end

#parse_ruby_manifest(manifest) ⇒ Object



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

def parse_ruby_manifest(manifest)
  manifest.dependencies.inject([]) do |deps, dep|
    deps.push({
      name: dep.name,
      requirement: dep.requirement.to_s,
      type: dep.type
    })
  end.uniq
end

#platform_nameObject



20
21
22
# File 'lib/bibliothecary/analyser.rb', line 20

def platform_name
  self.name.to_s.split('::').last.downcase
end