Skip to content
This repository
Newer
Older
100644 138 lines (106 sloc) 2.946 kb
5a31c5ef » qrush
2009-05-27 Adding in rubygems, versions, and dependencies
1 class Dependency < ActiveRecord::Base
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
2 LIMIT = 250
3
832307d8 » qrush
2009-06-10 Normalizing the dependencies by creating requirements
4 belongs_to :rubygem
c69f1422 » ddollar
2009-08-21 remove requirements join table
5 belongs_to :version
a714ce65 » qrush
2009-05-27 Basic associations between models
6
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
7 before_validation :use_gem_dependency,
8 :use_existing_rubygem,
9 :parse_gem_dependency
a316d254 » Matt Mongeau
2010-08-17 Move resolver queries into redis
10 after_create :push_on_to_list
11
f730865e » nickrivadeneira
2011-07-11 use rails 3 validation style
12 validates :requirements, :presence => true
13 validates :scope, :inclusion => {:in => %w(development runtime)}
9ea3f3b1 » ddollar
2009-08-21 add scope to dependencies
14
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
15 attr_accessor :gem_dependency
25c2fb41 » ddollar
2009-08-21 refactor how models get created from gem specs
16
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
17 def self.development
18 where(:scope => 'development')
fd2f5b6a » ddollar
2010-01-18 include dependencies in rubygems json
19 end
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
20
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
21 def self.runtime
22 where(:scope => 'runtime')
a316d254 » Matt Mongeau
2010-08-17 Move resolver queries into redis
23 end
24
25 def self.runtime_key(full_name)
26 "rd:#{full_name}"
27 end
28
fcaf22c2 » Matt Mongeau
2010-08-17 simple dependency endpoint without platforms
29 # rails,rack,bundler
30 def self.for(gem_list)
d3b915fe » qrush
2012-03-07 pipeline up the redis calls
31 versions = $redis.pipelined do
32 gem_list.each do |rubygem_name|
33 $redis.lrange(Rubygem.versions_key(rubygem_name), 0, -1)
fcaf22c2 » Matt Mongeau
2010-08-17 simple dependency endpoint without platforms
34 end
d3b915fe » qrush
2012-03-07 pipeline up the redis calls
35 end || []
36 versions.flatten!
37
38 return [] if versions.blank?
39
40 data = $redis.pipelined do
41 versions.each do |version|
42 $redis.hvals(Version.info_key(version))
43 $redis.lrange(Dependency.runtime_key(version), 0, -1)
44 end
45 end
46
47 data.in_groups_of(2).map do |(name, number, platform), deps|
48 {
49 :name => name,
50 :number => number,
51 :platform => platform,
52 :dependencies => deps.map { |dep| dep.split(" ", 2) }
53 }
54 end
fcaf22c2 » Matt Mongeau
2010-08-17 simple dependency endpoint without platforms
55 end
56
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
57 def name
34b78536 » evanphx
2012-01-18 Add ability for a dependency to reference an untracked gem
58 unresolved_name || rubygem.name
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
59 end
60
61 def payload
62 {
63 'name' => name,
000601a3 » evanphx
2011-06-02 Prune out Syck DefaultKey noise
64 'requirements' => clean_requirements
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
65 }
66 end
67
9d0ecc85 » sferik
2011-07-25 Add to_xml and to_yaml methods to models
68 def as_json(options={})
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
69 payload
70 end
71
9d0ecc85 » sferik
2011-07-25 Add to_xml and to_yaml methods to models
72 def to_xml(options={})
73 payload.to_xml(options.merge(:root => 'dependency'))
74 end
75
76 def to_yaml(*args)
77 payload.to_yaml(*args)
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
78 end
79
1c600889 » laserlemon
2011-09-29 Ensure that nested ActiveRecord objects are properly encoded as YAML
80 def encode_with(coder)
81 coder.tag, coder.implicit, coder.map = nil, true, payload
82 end
83
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
84 def to_s
000601a3 » evanphx
2011-06-02 Prune out Syck DefaultKey noise
85 "#{name} #{clean_requirements}"
86 end
87
88 def clean_requirements
d6a8e44e » cmeiklejohn
2011-08-04 Change to gsub in case there are multiple YAML/Syck parse failures.
89 requirements.gsub /#<YAML::Syck::DefaultKey[^>]*>/, "="
f84fb159 » qrush
2011-03-18 Banish scope for class methods, privatize when possible, add Rubygem#…
90 end
91
34b78536 » evanphx
2012-01-18 Add ability for a dependency to reference an untracked gem
92 def update_resolved(rubygem)
93 self.rubygem = rubygem
94 self.unresolved_name = nil
95 save!
96 end
97
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
98 private
99
100 def use_gem_dependency
34b78536 » evanphx
2012-01-18 Add ability for a dependency to reference an untracked gem
101 return if self.rubygem
102
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
103 if gem_dependency.class != Gem::Dependency
dbe5e781 » sferik
2011-07-15 Cleanup EOL whitespace
104 errors.add :rubygem, "Please use Gem::Dependency to specify dependencies."
02d04634 » evanphx
2012-01-18 Disallow a dependency with a blank name
105 return false
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
106 end
02d04634 » evanphx
2012-01-18 Disallow a dependency with a blank name
107
108 if gem_dependency.name.empty?
109 errors.add :rubygem, "Blank is not a valid dependency name"
110 return false
111 end
112
113 true
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
114 end
115
116 def use_existing_rubygem
34b78536 » evanphx
2012-01-18 Add ability for a dependency to reference an untracked gem
117 return if self.rubygem
118
52189353 » evanphx
2012-01-18 Minor style fixes
119 unless self.rubygem = Rubygem.find_by_name(gem_dependency.name)
34b78536 » evanphx
2012-01-18 Add ability for a dependency to reference an untracked gem
120 self.unresolved_name = gem_dependency.name
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
121 end
34b78536 » evanphx
2012-01-18 Add ability for a dependency to reference an untracked gem
122
123 true
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
124 end
125
126 def parse_gem_dependency
34b78536 » evanphx
2012-01-18 Add ability for a dependency to reference an untracked gem
127 return if self.requirements
128
000601a3 » evanphx
2011-06-02 Prune out Syck DefaultKey noise
129 reqs = gem_dependency.requirements_list.join(', ')
d6a8e44e » cmeiklejohn
2011-08-04 Change to gsub in case there are multiple YAML/Syck parse failures.
130 self.requirements = reqs.gsub(/#<YAML::Syck::DefaultKey[^>]*>/, "=")
000601a3 » evanphx
2011-06-02 Prune out Syck DefaultKey noise
131
0e5d4296 » qrush
2010-03-07 Pushed gems must specify dependencies that exist already
132 self.scope = gem_dependency.type.to_s
133 end
a316d254 » Matt Mongeau
2010-08-17 Move resolver queries into redis
134
135 def push_on_to_list
d4d3bc4b » hone
2011-06-01 bundler DO NOT WANT development dependencies
136 $redis.lpush(Dependency.runtime_key(self.version.full_name), self.to_s) if self.scope == 'runtime'
a316d254 » Matt Mongeau
2010-08-17 Move resolver queries into redis
137 end
5a31c5ef » qrush
2009-05-27 Adding in rubygems, versions, and dependencies
138 end
Something went wrong with that request. Please try again.