Class: Gemstash::DB::Dependency

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/gemstash/db/dependency.rb

Overview

Sequel model for dependencies table.

Class Method Summary collapse

Class Method Details

.fetch(gems) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gemstash/db/dependency.rb', line 18

def self.fetch(gems)
  results = db["
    SELECT rubygem.name,
           version.number, version.platform,
           dependency.rubygem_name, dependency.requirements
    FROM rubygems rubygem
    JOIN versions version
      ON version.rubygem_id = rubygem.id
    LEFT JOIN dependencies dependency
      ON dependency.version_id = version.id
    WHERE rubygem.name IN ?
      AND version.indexed = ?", gems.to_a, true].to_a
  results.group_by {|r| r[:name] }.each do |gem, rows|
    requirements = rows.group_by {|r| [r[:number], r[:platform]] }

    value = requirements.map do |version, r|
      deps = r.map {|x| [x[:rubygem_name], x[:requirements]] }
      deps = [] if deps.size == 1 && deps.first.first.nil?

      {
        :name => gem,
        :number => version.first,
        :platform => version.last,
        :dependencies => deps
      }
    end

    yield(gem, value)
  end
end

.insert_by_spec(version_id, spec) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/gemstash/db/dependency.rb', line 7

def self.insert_by_spec(version_id, spec)
  spec.runtime_dependencies.each do |dep|
    requirements = dep.requirement.requirements
    requirements = requirements.map {|r| "#{r.first} #{r.last}" }
    requirements = requirements.join(", ")
    create(version_id: version_id,
           rubygem_name: dep.name,
           requirements: requirements)
  end
end