rubygems-update 1.6.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (40) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +0 -1
  3. data/History.txt +70 -4
  4. data/README.rdoc +3 -0
  5. data/Rakefile +76 -0
  6. data/lib/rubygems.rb +57 -27
  7. data/lib/rubygems/command.rb +6 -4
  8. data/lib/rubygems/commands/contents_command.rb +14 -11
  9. data/lib/rubygems/commands/fetch_command.rb +6 -3
  10. data/lib/rubygems/commands/outdated_command.rb +2 -1
  11. data/lib/rubygems/commands/pristine_command.rb +4 -3
  12. data/lib/rubygems/commands/unpack_command.rb +46 -4
  13. data/lib/rubygems/commands/update_command.rb +24 -10
  14. data/lib/rubygems/custom_require.rb +1 -2
  15. data/lib/rubygems/dependency_installer.rb +1 -1
  16. data/lib/rubygems/ext/rake_builder.rb +1 -1
  17. data/lib/rubygems/gem_runner.rb +1 -0
  18. data/lib/rubygems/mock_gem_ui.rb +2 -1
  19. data/lib/rubygems/package/tar_input.rb +1 -0
  20. data/lib/rubygems/remote_fetcher.rb +62 -39
  21. data/lib/rubygems/server.rb +1 -1
  22. data/lib/rubygems/source_index.rb +64 -43
  23. data/lib/rubygems/spec_fetcher.rb +5 -6
  24. data/lib/rubygems/specification.rb +375 -402
  25. data/lib/rubygems/test_case.rb +7 -8
  26. data/lib/rubygems/uninstaller.rb +2 -2
  27. data/lib/rubygems/user_interaction.rb +27 -31
  28. data/test/rubygems/test_gem.rb +2 -44
  29. data/test/rubygems/test_gem_commands_contents_command.rb +19 -30
  30. data/test/rubygems/test_gem_commands_unpack_command.rb +24 -0
  31. data/test/rubygems/test_gem_commands_update_command.rb +26 -1
  32. data/test/rubygems/test_gem_dependency_installer.rb +9 -5
  33. data/test/rubygems/test_gem_dependency_list.rb +2 -6
  34. data/test/rubygems/test_gem_gem_runner.rb +1 -4
  35. data/test/rubygems/test_gem_installer.rb +1 -2
  36. data/test/rubygems/test_gem_remote_fetcher.rb +131 -24
  37. data/test/rubygems/test_gem_source_index.rb +7 -192
  38. data/test/rubygems/test_gem_specification.rb +132 -103
  39. metadata +9 -9
  40. metadata.gz.sig +0 -0
@@ -251,13 +251,12 @@ class Gem::SpecFetcher
251
251
  loaded = false
252
252
 
253
253
  if File.exist? local_file then
254
- spec_dump = @fetcher.fetch_path spec_path, File.mtime(local_file)
254
+ spec_dump =
255
+ @fetcher.fetch_path(spec_path, File.mtime(local_file)) rescue nil
255
256
 
256
- if spec_dump.nil? then
257
- spec_dump = Gem.read_binary local_file
258
- else
259
- loaded = true
260
- end
257
+ loaded = true if spec_dump
258
+
259
+ spec_dump ||= Gem.read_binary local_file
261
260
  else
262
261
  spec_dump = @fetcher.fetch_path spec_path
263
262
  loaded = true
@@ -7,6 +7,7 @@
7
7
  require 'rubygems/version'
8
8
  require 'rubygems/requirement'
9
9
  require 'rubygems/platform'
10
+ require "rubygems/deprecate"
10
11
 
11
12
  # :stopdoc:
12
13
  class Date; end # for ruby_code if date.rb wasn't required
@@ -42,6 +43,17 @@ class Gem::Specification
42
43
  # The specification version applied to any new Specification instances
43
44
  # created. This should be bumped whenever something in the spec format
44
45
  # changes.
46
+ #
47
+ # Specification Version History:
48
+ #
49
+ # spec ruby
50
+ # ver ver yyyy-mm-dd description
51
+ # -1 <0.8.0 pre-spec-version-history
52
+ # 1 0.8.0 2004-08-01 Deprecated "test_suite_file" for "test_files"
53
+ # "test_file=x" is a shortcut for "test_files=[x]"
54
+ # 2 0.9.5 2007-10-01 Added "required_rubygems_version"
55
+ # Now forward-compatible with future versions
56
+ # 3 1.3.2 2009-01-03 Added Fixnum validation to specification_version
45
57
  #--
46
58
  # When updating this number, be sure to also update #to_ruby.
47
59
  #
@@ -49,82 +61,76 @@ class Gem::Specification
49
61
 
50
62
  CURRENT_SPECIFICATION_VERSION = 3
51
63
 
52
- ##
53
- # An informal list of changes to the specification. The highest-valued
54
- # key should be equal to the CURRENT_SPECIFICATION_VERSION.
55
-
56
- SPECIFICATION_VERSION_HISTORY = {
57
- -1 => ['(RubyGems versions up to and including 0.7 did not have versioned specifications)'],
58
- 1 => [
59
- 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"',
60
- '"test_file=x" is a shortcut for "test_files=[x]"'
61
- ],
62
- 2 => [
63
- 'Added "required_rubygems_version"',
64
- 'Now forward-compatible with future versions',
65
- ],
66
- 3 => [
67
- 'Added Fixnum validation to the specification_version'
68
- ]
69
- }
70
-
71
64
  # :stopdoc:
72
- MARSHAL_FIELDS = { -1 => 16, 1 => 16, 2 => 16, 3 => 17 }
73
65
 
74
- now = Time.at(Time.now.to_i)
75
- TODAY = now - ((now.to_i + now.gmt_offset) % 86400)
76
- # :startdoc:
66
+ # version => # of fields
67
+ MARSHAL_FIELDS = { -1 => 16, 1 => 16, 2 => 16, 3 => 17 }
77
68
 
78
- ##
79
- # Optional block used to gather newly defined instances.
69
+ today = Time.now.utc
70
+ TODAY = Time.utc(today.year, today.month, today.day)
80
71
 
81
- @@gather = nil
72
+ # :startdoc:
82
73
 
83
74
  ##
84
75
  # List of attribute names: [:name, :version, ...]
85
76
 
86
- @@required_attributes = []
87
-
88
- ##
89
- # List of _all_ attributes and default values:
90
- #
91
- # [[:name, nil],
92
- # [:bindir, 'bin'],
93
- # ...]
94
-
95
- @@attributes = []
96
-
97
- @@nil_attributes = []
98
- @@non_nil_attributes = [:@original_platform]
99
-
100
- ##
101
- # List of array attributes
102
-
103
- @@array_attributes = []
77
+ @@required_attributes = [:rubygems_version,
78
+ :specification_version,
79
+ :name,
80
+ :version,
81
+ :date,
82
+ :summary,
83
+ :require_paths]
104
84
 
105
85
  ##
106
86
  # Map of attribute names to default values.
107
87
 
108
- @@default_value = {}
88
+ @@default_value = {
89
+ :authors => [],
90
+ :autorequire => nil,
91
+ :bindir => "bin",
92
+ :cert_chain => [],
93
+ :date => TODAY,
94
+ :dependencies => [],
95
+ :description => nil,
96
+ :email => nil,
97
+ :executables => [],
98
+ :extensions => [],
99
+ :extra_rdoc_files => [],
100
+ :files => [],
101
+ :homepage => nil,
102
+ :licenses => [],
103
+ :name => nil,
104
+ :platform => Gem::Platform::RUBY,
105
+ :post_install_message => nil,
106
+ :rdoc_options => [],
107
+ :require_paths => ["lib"],
108
+ :required_ruby_version => Gem::Requirement.default,
109
+ :required_rubygems_version => Gem::Requirement.default,
110
+ :requirements => [],
111
+ :rubyforge_project => nil,
112
+ :rubygems_version => Gem::VERSION,
113
+ :signing_key => nil,
114
+ :specification_version => CURRENT_SPECIFICATION_VERSION,
115
+ :summary => nil,
116
+ :test_files => [],
117
+ :version => nil,
118
+ }
109
119
 
110
- ##
111
- # Names of all specification attributes
120
+ @@attributes = @@default_value.keys.sort_by { |s| s.to_s }
121
+ @@array_attributes = @@default_value.reject { |k,v| v != [] }.keys
122
+ @@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition { |k|
123
+ @@default_value[k].nil?
124
+ }
112
125
 
113
126
  def self.attribute_names
114
- @@attributes.map { |name, default| name }
115
- end
116
-
117
- ##
118
- # Default values for specification attributes
119
-
120
- def self.attribute_defaults
121
127
  @@attributes.dup
122
128
  end
123
129
 
124
130
  ##
125
131
  # The default value for specification attribute +name+
126
132
 
127
- def self.default_value(name)
133
+ def default_value(name)
128
134
  @@default_value[name]
129
135
  end
130
136
 
@@ -150,114 +156,17 @@ class Gem::Specification
150
156
  end
151
157
 
152
158
  ##
153
- # Specifies the +name+ and +default+ for a specification attribute, and
154
- # creates a reader and writer method like Module#attr_accessor.
155
- #
156
- # The reader method returns the default if the value hasn't been set.
157
-
158
- def self.attribute(name, default=nil)
159
- ivar_name = "@#{name}".intern
160
- if default.nil? then
161
- @@nil_attributes << ivar_name
162
- else
163
- @@non_nil_attributes << [ivar_name, default]
164
- end
165
-
166
- @@attributes << [name, default]
167
- @@default_value[name] = default
168
- attr_accessor(name)
169
- end
170
-
171
- ##
172
- # Same as :attribute, but ensures that values assigned to the attribute
173
- # are array values by applying :to_a to the value.
174
-
175
- def self.array_attribute(name)
176
- @@non_nil_attributes << ["@#{name}".intern, []]
177
-
178
- @@array_attributes << name
179
- @@attributes << [name, []]
180
- @@default_value[name] = []
181
- code = %{
182
- def #{name}
183
- @#{name} ||= []
184
- end
185
- def #{name}=(value)
186
- @#{name} = Array(value)
187
- end
188
- }
189
-
190
- module_eval code, __FILE__, __LINE__ - 9
191
- end
192
-
193
- ##
194
- # Same as attribute above, but also records this attribute as mandatory.
195
-
196
- def self.required_attribute(*args)
197
- @@required_attributes << args.first
198
- attribute(*args)
199
- end
200
-
201
- ##
202
- # Sometimes we don't want the world to use a setter method for a
203
- # particular attribute.
204
- #
205
- # +read_only+ makes it private so we can still use it internally.
159
+ # Specification attributes that must be non-nil
206
160
 
207
- def self.read_only(*names)
208
- names.each do |name|
209
- private "#{name}="
210
- end
211
- end
212
-
213
- # Shortcut for creating several attributes at once (each with a default
214
- # value of +nil+).
215
-
216
- def self.attributes(*args)
217
- args.each do |arg|
218
- attribute(arg, nil)
219
- end
220
- end
221
-
222
- ##
223
- # Some attributes require special behaviour when they are accessed. This
224
- # allows for that.
225
-
226
- def self.overwrite_accessor(name, &block)
227
- remove_method name
228
- define_method(name, &block)
229
- end
230
-
231
- ##
232
- # Defines a _singular_ version of an existing _plural_ attribute (i.e. one
233
- # whose value is expected to be an array). This means just creating a
234
- # helper method that takes a single value and appends it to the array.
235
- # These are created for convenience, so that in a spec, one can write
236
- #
237
- # s.require_path = 'mylib'
238
- #
239
- # instead of:
240
- #
241
- # s.require_paths = ['mylib']
242
- #
243
- # That above convenience is available courtesy of:
244
- #
245
- # attribute_alias_singular :require_path, :require_paths
246
-
247
- def self.attribute_alias_singular(singular, plural)
248
- define_method("#{singular}=") { |val|
249
- send("#{plural}=", [val])
250
- }
251
- define_method("#{singular}") {
252
- val = send("#{plural}")
253
- val.nil? ? nil : val.first
254
- }
161
+ def self.non_nil_attributes
162
+ @@non_nil_attributes.dup
255
163
  end
256
164
 
257
165
  ##
258
166
  # Dump only crucial instance variables.
259
167
  #--
260
168
  # MAINTAIN ORDER!
169
+ # (down with the man)
261
170
 
262
171
  def _dump(limit)
263
172
  Marshal.dump [
@@ -265,7 +174,7 @@ class Gem::Specification
265
174
  @specification_version,
266
175
  @name,
267
176
  @version,
268
- (Time === @date ? @date : (require 'time'; Time.parse(@date.to_s))),
177
+ date,
269
178
  @summary,
270
179
  @required_ruby_version,
271
180
  @required_rubygems_version,
@@ -276,7 +185,7 @@ class Gem::Specification
276
185
  @authors,
277
186
  @description,
278
187
  @homepage,
279
- @has_rdoc,
188
+ true, # has_rdoc
280
189
  @new_platform,
281
190
  @licenses
282
191
  ]
@@ -333,7 +242,6 @@ class Gem::Specification
333
242
  # List of dependencies that will automatically be activated at runtime.
334
243
 
335
244
  def runtime_dependencies
336
- # TODO: fix #type to return :runtime if nil
337
245
  dependencies.select { |d| d.type == :runtime }
338
246
  end
339
247
 
@@ -345,12 +253,10 @@ class Gem::Specification
345
253
  end
346
254
 
347
255
  def test_suite_file # :nodoc:
348
- warn 'test_suite_file deprecated, use test_files'
349
256
  test_files.first
350
257
  end
351
258
 
352
259
  def test_suite_file=(val) # :nodoc:
353
- warn 'test_suite_file= deprecated, use test_files='
354
260
  @test_files = [] unless defined? @test_files
355
261
  @test_files << val
356
262
  end
@@ -416,16 +322,31 @@ class Gem::Specification
416
322
 
417
323
  def initialize name = nil, version = nil
418
324
  @new_platform = nil
419
- assign_defaults
420
325
  @loaded = false
421
326
  @loaded_from = nil
327
+ @original_platform = nil
328
+
329
+ @@nil_attributes.each do |key|
330
+ instance_variable_set "@#{key}", nil
331
+ end
332
+
333
+ @@non_nil_attributes.each do |key|
334
+ default = default_value(key)
335
+ value = case default
336
+ when Time, Numeric, Symbol, true, false, nil then default
337
+ else default.dup
338
+ end
339
+
340
+ instance_variable_set "@#{key}", value
341
+ end
342
+
343
+ # HACK
344
+ instance_variable_set :@new_platform, Gem::Platform::RUBY
422
345
 
423
346
  self.name = name if name
424
347
  self.version = version if version
425
348
 
426
349
  yield self if block_given?
427
-
428
- @@gather.call(self) if @@gather
429
350
  end
430
351
 
431
352
  ##
@@ -434,38 +355,22 @@ class Gem::Specification
434
355
  def initialize_copy(other_spec)
435
356
  other_ivars = other_spec.instance_variables
436
357
  other_ivars = other_ivars.map { |ivar| ivar.intern } if # for 1.9
437
- other_ivars.any? { |ivar| String === ivar }
358
+ String === other_ivars.first
438
359
 
439
360
  self.class.array_attributes.each do |name|
440
361
  name = :"@#{name}"
441
362
  next unless other_ivars.include? name
442
- instance_variable_set name, other_spec.instance_variable_get(name).dup
443
- end
444
- end
445
363
 
446
- ##
447
- # Each attribute has a default value (possibly nil). Here, we initialize
448
- # all attributes to their default value. This is done through the
449
- # accessor methods, so special behaviours will be honored. Furthermore,
450
- # we take a _copy_ of the default so each specification instance has its
451
- # own empty arrays, etc.
364
+ begin
365
+ instance_variable_set name, other_spec.instance_variable_get(name).dup
366
+ rescue TypeError
367
+ e = Gem::FormatException.new \
368
+ "#{full_name} has an invalid value for #{name}"
452
369
 
453
- def assign_defaults
454
- @@nil_attributes.each do |name|
455
- instance_variable_set name, nil
456
- end
457
-
458
- @@non_nil_attributes.each do |name, default|
459
- value = case default
460
- when Time, Numeric, Symbol, true, false, nil then default
461
- else default.dup
462
- end
463
-
464
- instance_variable_set name, value
370
+ e.file_path = loaded_from
371
+ raise e
372
+ end
465
373
  end
466
-
467
- # HACK
468
- instance_variable_set :@new_platform, Gem::Platform::RUBY
469
374
  end
470
375
 
471
376
  ##
@@ -628,7 +533,7 @@ class Gem::Specification
628
533
  # spec.file_name # => "example-1.0.gem"
629
534
 
630
535
  def file_name
631
- full_name + '.gem'
536
+ "#{full_name}.gem"
632
537
  end
633
538
 
634
539
  ##
@@ -663,7 +568,7 @@ class Gem::Specification
663
568
  # spec.spec_name # => "example-1.0.gemspec"
664
569
 
665
570
  def spec_name
666
- full_name + '.gemspec'
571
+ "#{full_name}.gemspec"
667
572
  end
668
573
 
669
574
  def <=>(other) # :nodoc:
@@ -708,9 +613,6 @@ class Gem::Specification
708
613
  def encode_with coder # :nodoc:
709
614
  mark_version
710
615
 
711
- attributes = @@attributes.map { |name,| name.to_s }.sort
712
- attributes = attributes - %w[name version platform]
713
-
714
616
  coder.add 'name', @name
715
617
  coder.add 'version', @version
716
618
  platform = case @original_platform
@@ -723,11 +625,24 @@ class Gem::Specification
723
625
  end
724
626
  coder.add 'platform', platform
725
627
 
628
+ attributes = @@attributes.map(&:to_s) - %w[name version platform]
726
629
  attributes.each do |name|
727
630
  coder.add name, instance_variable_get("@#{name}")
728
631
  end
729
632
  end
730
633
 
634
+ ##
635
+ # Creates a duplicate spec without large blobs that aren't used at runtime.
636
+
637
+ def for_cache
638
+ spec = dup
639
+
640
+ spec.files = nil
641
+ spec.test_files = nil
642
+
643
+ spec
644
+ end
645
+
731
646
  def to_yaml(opts = {}) # :nodoc:
732
647
  if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? then
733
648
  super.gsub(/ !!null \n/, " \n")
@@ -780,14 +695,13 @@ class Gem::Specification
780
695
  :required_rubygems_version,
781
696
  :specification_version,
782
697
  :version,
698
+ :has_rdoc,
783
699
  ]
784
700
 
785
- attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s }
786
-
787
- attributes.each do |attr_name, default|
701
+ @@attributes.each do |attr_name|
788
702
  next if handled.include? attr_name
789
703
  current_value = self.send(attr_name)
790
- if current_value != default or
704
+ if current_value != default_value(attr_name) or
791
705
  self.class.required_attribute? attr_name then
792
706
  result << " s.#{attr_name} = #{ruby_code current_value}"
793
707
  end
@@ -829,12 +743,7 @@ class Gem::Specification
829
743
  end
830
744
 
831
745
  def to_ruby_for_cache
832
- s = dup
833
- # remove large blobs that aren't used at runtime:
834
- s.files = nil
835
- s.extra_rdoc_files = nil
836
- s.rdoc_options = nil
837
- s.to_ruby
746
+ for_cache.to_ruby
838
747
  end
839
748
 
840
749
  ##
@@ -844,12 +753,21 @@ class Gem::Specification
844
753
  # Raises InvalidSpecificationException if the spec does not pass the
845
754
  # checks..
846
755
 
847
- def validate
756
+ def validate packaging = true
848
757
  require 'rubygems/user_interaction'
849
758
  extend Gem::UserInteraction
850
759
  normalize
851
760
 
852
- if rubygems_version != Gem::VERSION then
761
+ nil_attributes = self.class.non_nil_attributes.find_all do |name|
762
+ instance_variable_get("@#{name}").nil?
763
+ end
764
+
765
+ unless nil_attributes.empty? then
766
+ raise Gem::InvalidSpecificationException,
767
+ "#{nil_attributes.join ', '} must not be nil"
768
+ end
769
+
770
+ if packaging and rubygems_version != Gem::VERSION then
853
771
  raise Gem::InvalidSpecificationException,
854
772
  "expected RubyGems version #{Gem::VERSION}, was #{rubygems_version}"
855
773
  end
@@ -883,7 +801,7 @@ class Gem::Specification
883
801
  !File.file? file
884
802
  end
885
803
 
886
- unless non_files.empty? then
804
+ unless not packaging or non_files.empty? then
887
805
  non_files = non_files.map { |file| file.inspect }
888
806
  raise Gem::InvalidSpecificationException,
889
807
  "[#{non_files.join ", "}] are not files"
@@ -901,10 +819,14 @@ class Gem::Specification
901
819
  "invalid platform #{platform.inspect}, see Gem::Platform"
902
820
  end
903
821
 
904
- unless Array === authors and
905
- authors.all? { |author| String === author } then
906
- raise Gem::InvalidSpecificationException,
907
- 'authors must be Array of Strings'
822
+ self.class.array_attributes.each do |symbol|
823
+ val = self.send symbol
824
+ klass = symbol == :dependencies ? Gem::Dependency : String
825
+
826
+ unless Array === val and val.all? { |x| klass === x } then
827
+ raise(Gem::InvalidSpecificationException,
828
+ "#{symbol} must be an Array of #{klass} instances")
829
+ end
908
830
  end
909
831
 
910
832
  licenses.each { |license|
@@ -914,26 +836,24 @@ class Gem::Specification
914
836
  end
915
837
  }
916
838
 
917
- # reject FIXME and TODO
839
+ # reject lazy developers:
918
840
 
919
- unless authors.grep(/FIXME|TODO/).empty? then
920
- raise Gem::InvalidSpecificationException,
921
- '"FIXME" or "TODO" is not an author'
841
+ lazy = '"FIxxxXME" or "TOxxxDO"'.gsub(/xxx/, '')
842
+
843
+ unless authors.grep(/FI XME|TO DO/x).empty? then
844
+ raise Gem::InvalidSpecificationException, "#{lazy} is not an author"
922
845
  end
923
846
 
924
- unless Array(email).grep(/FIXME|TODO/).empty? then
925
- raise Gem::InvalidSpecificationException,
926
- '"FIXME" or "TODO" is not an email address'
847
+ unless Array(email).grep(/FI XME|TO DO/x).empty? then
848
+ raise Gem::InvalidSpecificationException, "#{lazy} is not an email"
927
849
  end
928
850
 
929
- if description =~ /FIXME|TODO/ then
930
- raise Gem::InvalidSpecificationException,
931
- '"FIXME" or "TODO" is not a description'
851
+ if description =~ /FI XME|TO DO/x then
852
+ raise Gem::InvalidSpecificationException, "#{lazy} is not a description"
932
853
  end
933
854
 
934
- if summary =~ /FIXME|TODO/ then
935
- raise Gem::InvalidSpecificationException,
936
- '"FIXME" or "TODO" is not a summary'
855
+ if summary =~ /FI XME|TO DO/x then
856
+ raise Gem::InvalidSpecificationException, "#{lazy} is not a summary"
937
857
  end
938
858
 
939
859
  if homepage and not homepage.empty? and
@@ -949,10 +869,11 @@ class Gem::Specification
949
869
  alert_warning "no #{attribute} specified" if value.nil? or value.empty?
950
870
  end
951
871
 
952
- if summary and not summary.empty? and description == summary then
872
+ if description == summary then
953
873
  alert_warning 'description and summary are identical'
954
874
  end
955
875
 
876
+ # TODO: raise at some given date
956
877
  alert_warning "deprecated autorequire specified" if autorequire
957
878
 
958
879
  executables.each do |executable|
@@ -1010,11 +931,10 @@ class Gem::Specification
1010
931
  q.group 2, 'Gem::Specification.new do |s|', 'end' do
1011
932
  q.breakable
1012
933
 
1013
- attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s }
1014
-
1015
- attributes.each do |attr_name, default|
934
+ # REFACTOR: each_attr - use in to_yaml as well
935
+ @@attributes.each do |attr_name|
1016
936
  current_value = self.send attr_name
1017
- if current_value != default or
937
+ if current_value != default_value(attr_name) or
1018
938
  self.class.required_attribute? attr_name then
1019
939
 
1020
940
  q.text "s.#{attr_name} = "
@@ -1091,49 +1011,30 @@ class Gem::Specification
1091
1011
  # :section: Required gemspec attributes
1092
1012
 
1093
1013
  ##
1094
- # :attr_accessor: rubygems_version
1095
- #
1096
1014
  # The version of RubyGems used to create this gem.
1097
1015
  #
1098
1016
  # Do not set this, it is set automatically when the gem is packaged.
1099
1017
 
1100
- required_attribute :rubygems_version, Gem::VERSION
1018
+ attr_accessor :rubygems_version
1101
1019
 
1102
1020
  ##
1103
- # :attr_accessor: specification_version
1104
- #
1105
1021
  # The Gem::Specification version of this gemspec.
1106
1022
  #
1107
1023
  # Do not set this, it is set automatically when the gem is packaged.
1108
1024
 
1109
- required_attribute :specification_version, CURRENT_SPECIFICATION_VERSION
1025
+ attr_accessor :specification_version
1110
1026
 
1111
1027
  ##
1112
- # :attr_accessor: name
1113
- #
1114
1028
  # This gem's name
1115
1029
 
1116
- required_attribute :name
1030
+ attr_accessor :name
1117
1031
 
1118
1032
  ##
1119
- # :attr_accessor: version
1120
- #
1121
1033
  # This gem's version
1122
1034
 
1123
- required_attribute :version
1035
+ attr_reader :version
1124
1036
 
1125
1037
  ##
1126
- # :attr_accessor: date
1127
- #
1128
- # The date this gem was created
1129
- #
1130
- # Do not set this, it is set automatically when the gem is packaged.
1131
-
1132
- required_attribute :date, TODAY
1133
-
1134
- ##
1135
- # :attr_accessor: summary
1136
- #
1137
1038
  # A short summary of this gem's description. Displayed in `gem list -d`.
1138
1039
  #
1139
1040
  # The description should be more detailed than the summary. For example,
@@ -1141,22 +1042,18 @@ class Gem::Specification
1141
1042
  #
1142
1043
  # As of RubyGems 1.3.2 newlines are no longer stripped.
1143
1044
 
1144
- required_attribute :summary
1045
+ attr_reader :summary
1145
1046
 
1146
1047
  ##
1147
- # :attr_accessor: require_paths
1148
- #
1149
1048
  # Paths in the gem to add to $LOAD_PATH when this gem is activated.
1150
1049
  #
1151
1050
  # The default 'lib' is typically sufficient.
1152
1051
 
1153
- required_attribute :require_paths, ['lib']
1052
+ attr_accessor :require_paths
1154
1053
 
1155
1054
  # :section: Optional gemspec attributes
1156
1055
 
1157
1056
  ##
1158
- # :attr_accessor: email
1159
- #
1160
1057
  # A contact email for this gem
1161
1058
  #
1162
1059
  # If you are providing multiple authors and multiple emails they should be
@@ -1166,117 +1063,67 @@ class Gem::Specification
1166
1063
  #
1167
1064
  # Gives a hash of author name to email address.
1168
1065
 
1169
- attribute :email
1066
+ attr_accessor :email
1170
1067
 
1171
1068
  ##
1172
- # :attr_accessor: homepage
1173
- #
1174
1069
  # The URL of this gem's home page
1175
1070
 
1176
- attribute :homepage
1071
+ attr_accessor :homepage
1177
1072
 
1178
1073
  ##
1179
- # :attr_accessor: rubyforge_project
1180
- #
1181
1074
  # The rubyforge project this gem lives under. i.e. RubyGems'
1182
1075
  # rubyforge_project is "rubygems".
1183
1076
 
1184
- attribute :rubyforge_project
1077
+ attr_accessor :rubyforge_project
1185
1078
 
1186
1079
  ##
1187
- # :attr_accessor: description
1188
- #
1189
1080
  # A long description of this gem
1190
1081
 
1191
- attribute :description
1082
+ attr_reader :description
1192
1083
 
1193
1084
  ##
1194
- # :attr_accessor: autorequire
1195
- #
1196
1085
  # Autorequire was used by old RubyGems to automatically require a file.
1197
1086
  # It no longer is supported.
1198
1087
 
1199
- attribute :autorequire
1088
+ attr_accessor :autorequire
1200
1089
 
1201
1090
  ##
1202
- # :attr_accessor: default_executable
1203
- #
1204
1091
  # The default executable for this gem.
1205
- #
1206
- # This is not used.
1207
1092
 
1208
- attribute :default_executable
1093
+ attr_writer :default_executable
1209
1094
 
1210
1095
  ##
1211
- # :attr_accessor: bindir
1212
- #
1213
1096
  # The path in the gem for executable scripts
1214
1097
 
1215
- attribute :bindir, 'bin'
1098
+ attr_accessor :bindir
1216
1099
 
1217
1100
  ##
1218
- # :attr_accessor: has_rdoc
1219
- #
1220
- # Deprecated and ignored, defaults to true.
1221
- #
1222
- # Formerly used to indicate this gem was RDoc-capable.
1223
-
1224
- attribute :has_rdoc, true
1225
-
1226
- ##
1227
- # True if this gem supports RDoc
1228
-
1229
- alias :has_rdoc? :has_rdoc
1230
-
1231
- ##
1232
- # :attr_accessor: required_ruby_version
1233
- #
1234
1101
  # The version of ruby required by this gem
1235
1102
 
1236
- attribute :required_ruby_version, Gem::Requirement.default
1103
+ attr_reader :required_ruby_version
1237
1104
 
1238
1105
  ##
1239
- # :attr_accessor: required_rubygems_version
1240
- #
1241
1106
  # The RubyGems version required by this gem
1242
1107
 
1243
- attribute :required_rubygems_version, Gem::Requirement.default
1108
+ attr_reader :required_rubygems_version
1244
1109
 
1245
1110
  ##
1246
- # :attr_accessor: platform
1247
- #
1248
- # The platform this gem runs on. See Gem::Platform for details.
1249
- #
1250
- # Setting this to any value other than Gem::Platform::RUBY or
1251
- # Gem::Platform::CURRENT is probably wrong.
1252
-
1253
- attribute :platform, Gem::Platform::RUBY
1254
-
1255
- ##
1256
- # :attr_accessor: signing_key
1257
- #
1258
1111
  # The key used to sign this gem. See Gem::Security for details.
1259
1112
 
1260
- attribute :signing_key, nil
1113
+ attr_accessor :signing_key
1261
1114
 
1262
1115
  ##
1263
- # :attr_accessor: cert_chain
1264
- #
1265
1116
  # The certificate chain used to sign this gem. See Gem::Security for
1266
1117
  # details.
1267
1118
 
1268
- attribute :cert_chain, []
1119
+ attr_accessor :cert_chain
1269
1120
 
1270
1121
  ##
1271
- # :attr_accessor: post_install_message
1272
- #
1273
1122
  # A message that gets displayed after the gem is installed
1274
1123
 
1275
- attribute :post_install_message, nil
1124
+ attr_accessor :post_install_message
1276
1125
 
1277
1126
  ##
1278
- # :attr_accessor: authors
1279
- #
1280
1127
  # The list of author names who wrote this gem.
1281
1128
  #
1282
1129
  # If you are providing multiple authors and multiple emails they should be
@@ -1286,19 +1133,27 @@ class Gem::Specification
1286
1133
  #
1287
1134
  # Gives a hash of author name to email address.
1288
1135
 
1289
- array_attribute :authors
1136
+ def authors
1137
+ @authors ||= []
1138
+ end
1139
+
1140
+ def authors=(value)
1141
+ @authors = Array(value)
1142
+ end
1290
1143
 
1291
1144
  ##
1292
- # :attr_accessor: licenses
1293
- #
1294
1145
  # The license(s) for the library. Each license must be a short name, no
1295
1146
  # more than 64 characters.
1296
1147
 
1297
- array_attribute :licenses
1148
+ def licenses
1149
+ @licenses ||= []
1150
+ end
1151
+
1152
+ def licenses=(value)
1153
+ @licenses = Array(value)
1154
+ end
1298
1155
 
1299
1156
  ##
1300
- # :attr_accessor: files
1301
- #
1302
1157
  # Files included in this gem. You cannot append to this accessor, you must
1303
1158
  # assign to it.
1304
1159
  #
@@ -1307,117 +1162,210 @@ class Gem::Specification
1307
1162
  # Directories are automatically stripped from this list when building a gem,
1308
1163
  # other non-files cause an error.
1309
1164
 
1310
- array_attribute :files
1165
+ def files
1166
+ @files ||= []
1167
+ end
1168
+
1169
+ def files=(value)
1170
+ @files = Array(value)
1171
+ end
1311
1172
 
1312
1173
  ##
1313
- # :attr_accessor: test_files
1314
- #
1315
1174
  # Test files included in this gem. You cannot append to this accessor, you
1316
1175
  # must assign to it.
1317
1176
 
1318
- array_attribute :test_files
1177
+ def test_files
1178
+ @test_files ||= []
1179
+ end
1180
+
1181
+ def test_files=(value)
1182
+ @test_files = Array(value)
1183
+ end
1319
1184
 
1320
1185
  ##
1321
- # :attr_accessor: rdoc_options
1322
- #
1323
1186
  # An ARGV style array of options to RDoc
1324
1187
 
1325
- array_attribute :rdoc_options
1188
+ def rdoc_options
1189
+ @rdoc_options ||= []
1190
+ end
1191
+
1192
+ def rdoc_options=(value)
1193
+ # TODO: warn about setting instead of pushing
1194
+ @rdoc_options = Array(value)
1195
+ end
1326
1196
 
1327
1197
  ##
1328
- # :attr_accessor: extra_rdoc_files
1329
- #
1330
1198
  # Extra files to add to RDoc such as README or doc/examples.txt
1331
1199
 
1332
- array_attribute :extra_rdoc_files
1200
+ def extra_rdoc_files
1201
+ @extra_rdoc_files ||= []
1202
+ end
1203
+
1204
+ def extra_rdoc_files=(value)
1205
+ # TODO: warn about setting instead of pushing
1206
+ @extra_rdoc_files = Array(value)
1207
+ end
1333
1208
 
1334
1209
  ##
1335
- # :attr_accessor: executables
1336
- #
1337
1210
  # Executables included in the gem.
1338
1211
 
1339
- array_attribute :executables
1212
+ def executables
1213
+ @executables ||= []
1214
+ end
1215
+
1216
+ def executables=(value)
1217
+ # TODO: warn about setting instead of pushing
1218
+ @executables = Array(value)
1219
+ end
1340
1220
 
1341
1221
  ##
1342
- # :attr_accessor: extensions
1343
- #
1344
1222
  # Extensions to build when installing the gem. See
1345
1223
  # Gem::Installer#build_extensions for valid values.
1346
1224
 
1347
- array_attribute :extensions
1225
+ def extensions
1226
+ @extensions ||= []
1227
+ end
1228
+
1229
+ def extensions=(value)
1230
+ # TODO: warn about setting instead of pushing
1231
+ @extensions = Array(value)
1232
+ end
1348
1233
 
1349
1234
  ##
1350
- # :attr_accessor: requirements
1351
- #
1352
1235
  # An array or things required by this gem. Not used by anything
1353
1236
  # presently.
1354
1237
 
1355
- array_attribute :requirements
1238
+ def requirements
1239
+ @requirements ||= []
1240
+ end
1241
+
1242
+ def requirements=(value)
1243
+ # TODO: warn about setting instead of pushing
1244
+ @requirements = Array(value)
1245
+ end
1356
1246
 
1357
1247
  ##
1358
- # :attr_reader: dependencies
1359
- #
1360
1248
  # A list of Gem::Dependency objects this gem depends on.
1361
1249
  #
1362
1250
  # Use #add_dependency or #add_development_dependency to add dependencies to
1363
1251
  # a gem.
1364
1252
 
1365
- array_attribute :dependencies
1366
-
1367
- read_only :dependencies
1253
+ def dependencies
1254
+ @dependencies ||= []
1255
+ end
1368
1256
 
1369
1257
  # :section: Aliased gemspec attributes
1370
1258
 
1371
1259
  ##
1372
1260
  # Singular accessor for #executables
1373
1261
 
1374
- attribute_alias_singular :executable, :executables
1262
+ def executable
1263
+ val = executables and val.first
1264
+ end
1265
+
1266
+ ##
1267
+ # Singular accessor for #executables
1268
+
1269
+ def executable=o
1270
+ self.executables = [o]
1271
+ end
1272
+
1273
+ ##
1274
+ # Singular accessor for #authors
1275
+
1276
+ def author
1277
+ val = authors and val.first
1278
+ end
1375
1279
 
1376
1280
  ##
1377
1281
  # Singular accessor for #authors
1378
1282
 
1379
- attribute_alias_singular :author, :authors
1283
+ def author=o
1284
+ self.authors = [o]
1285
+ end
1286
+
1287
+ ##
1288
+ # Singular accessor for #licenses
1289
+
1290
+ def license
1291
+ val = licenses and val.first
1292
+ end
1380
1293
 
1381
1294
  ##
1382
1295
  # Singular accessor for #licenses
1383
1296
 
1384
- attribute_alias_singular :license, :licenses
1297
+ def license=o
1298
+ self.licenses = [o]
1299
+ end
1385
1300
 
1386
1301
  ##
1387
1302
  # Singular accessor for #require_paths
1388
1303
 
1389
- attribute_alias_singular :require_path, :require_paths
1304
+ def require_path
1305
+ val = require_paths and val.first
1306
+ end
1307
+
1308
+ ##
1309
+ # Singular accessor for #require_paths
1310
+
1311
+ def require_path=o
1312
+ self.require_paths = [o]
1313
+ end
1390
1314
 
1391
1315
  ##
1392
1316
  # Singular accessor for #test_files
1393
1317
 
1394
- attribute_alias_singular :test_file, :test_files
1318
+ def test_file
1319
+ val = test_files and val.first
1320
+ end
1395
1321
 
1396
1322
  ##
1397
- # has_rdoc is now ignored
1323
+ # Singular accessor for #test_files
1324
+
1325
+ def test_file=o
1326
+ self.test_files = [o]
1327
+ end
1328
+
1329
+ ##
1330
+ # Deprecated and ignored, defaults to true.
1331
+ #
1332
+ # Formerly used to indicate this gem was RDoc-capable.
1398
1333
 
1399
- overwrite_accessor :has_rdoc do
1334
+ def has_rdoc
1400
1335
  true
1401
1336
  end
1402
1337
 
1403
1338
  ##
1404
- # has_rdoc is now ignored
1339
+ # Deprecated and ignored.
1340
+ #
1341
+ # Formerly used to indicate this gem was RDoc-capable.
1405
1342
 
1406
- overwrite_accessor :has_rdoc= do |value|
1343
+ def has_rdoc= v
1407
1344
  @has_rdoc = true
1408
1345
  end
1409
1346
 
1410
- overwrite_accessor :version= do |version|
1347
+ alias :has_rdoc? :has_rdoc
1348
+
1349
+ def version= version
1411
1350
  @version = Gem::Version.create(version)
1412
1351
  self.required_rubygems_version = '> 1.3.1' if @version.prerelease?
1413
1352
  return @version
1414
1353
  end
1415
1354
 
1416
- overwrite_accessor :platform do
1355
+ ##
1356
+ # The platform this gem runs on. See Gem::Platform for details.
1357
+
1358
+ def platform
1417
1359
  @new_platform
1418
1360
  end
1419
1361
 
1420
- overwrite_accessor :platform= do |platform|
1362
+ ##
1363
+ # The platform this gem runs on. See Gem::Platform for details.
1364
+ #
1365
+ # Setting this to any value other than Gem::Platform::RUBY or
1366
+ # Gem::Platform::CURRENT is probably wrong.
1367
+
1368
+ def platform= platform
1421
1369
  if @original_platform.nil? or
1422
1370
  @original_platform == Gem::Platform::RUBY then
1423
1371
  @original_platform = platform
@@ -1449,68 +1397,82 @@ class Gem::Specification
1449
1397
  @new_platform
1450
1398
  end
1451
1399
 
1452
- overwrite_accessor :required_ruby_version= do |value|
1400
+ ##
1401
+ # The version of ruby required by this gem
1402
+
1403
+ def required_ruby_version= value
1453
1404
  @required_ruby_version = Gem::Requirement.create(value)
1454
1405
  end
1455
1406
 
1456
- overwrite_accessor :required_rubygems_version= do |value|
1407
+ ##
1408
+ # The RubyGems version required by this gem
1409
+
1410
+ def required_rubygems_version= value
1457
1411
  @required_rubygems_version = Gem::Requirement.create(value)
1458
1412
  end
1459
1413
 
1460
- overwrite_accessor :date= do |date|
1414
+ ##
1415
+ # The date this gem was created
1416
+ #
1417
+ # Do not set this, it is set automatically when the gem is packaged.
1418
+
1419
+ def date= date
1461
1420
  # We want to end up with a Time object with one-day resolution.
1462
1421
  # This is the cleanest, most-readable, faster-than-using-Date
1463
1422
  # way to do it.
1464
- case date
1465
- when String then
1466
- @date = if /\A(\d{4})-(\d{2})-(\d{2})\Z/ =~ date then
1467
- Time.local($1.to_i, $2.to_i, $3.to_i)
1423
+ @date = case date
1424
+ when String then
1425
+ if /\A(\d{4})-(\d{2})-(\d{2})\Z/ =~ date then
1426
+ Time.utc($1.to_i, $2.to_i, $3.to_i)
1468
1427
  else
1469
- require 'time'
1470
- Time.parse date
1428
+ raise(Gem::InvalidSpecificationException,
1429
+ "invalid date format in specification: #{date.inspect}")
1471
1430
  end
1472
- when Time then
1473
- @date = Time.local(date.year, date.month, date.day)
1474
- when Date then
1475
- @date = Time.local(date.year, date.month, date.day)
1476
- else
1477
- @date = TODAY
1478
- end
1431
+ when Time, Date then
1432
+ Time.utc(date.year, date.month, date.day)
1433
+ else
1434
+ TODAY
1435
+ end
1479
1436
  end
1480
1437
 
1481
- overwrite_accessor :date do
1482
- self.date = nil if @date.nil? # HACK Sets the default value for date
1483
- @date
1438
+ ##
1439
+ # The date this gem was created. Lazily defaults to TODAY.
1440
+
1441
+ def date
1442
+ @date ||= TODAY
1484
1443
  end
1485
1444
 
1486
- overwrite_accessor :summary= do |str|
1487
- @summary = if str then
1488
- str.strip.
1489
- gsub(/(\w-)\n[ \t]*(\w)/, '\1\2').
1490
- gsub(/\n[ \t]*/, " ")
1491
- end
1445
+ ##
1446
+ # A short summary of this gem's description.
1447
+
1448
+ def summary= str
1449
+ @summary = str.to_s.strip.
1450
+ gsub(/(\w-)\n[ \t]*(\w)/, '\1\2').gsub(/\n[ \t]*/, " ") # so. weird.
1492
1451
  end
1493
1452
 
1494
- overwrite_accessor :description= do |str|
1453
+ ##
1454
+ # A long description of this gem
1455
+
1456
+ def description= str
1495
1457
  @description = str.to_s
1496
1458
  end
1497
1459
 
1498
- overwrite_accessor :default_executable do
1499
- begin
1500
- if defined?(@default_executable) and @default_executable
1501
- result = @default_executable
1502
- elsif @executables and @executables.size == 1
1503
- result = Array(@executables).first
1504
- else
1505
- result = nil
1506
- end
1507
- result
1508
- rescue
1509
- nil
1460
+ ##
1461
+ # The default executable for this gem.
1462
+
1463
+ def default_executable
1464
+ if defined?(@default_executable) and @default_executable
1465
+ result = @default_executable
1466
+ elsif @executables and @executables.size == 1
1467
+ result = Array(@executables).first
1468
+ else
1469
+ result = nil
1510
1470
  end
1471
+ result
1511
1472
  end
1512
1473
 
1513
- overwrite_accessor :test_files do
1474
+ undef_method :test_files
1475
+ def test_files
1514
1476
  # Handle the possibility that we have @test_suite_file but not
1515
1477
  # @test_files. This will happen when an old gem is loaded via
1516
1478
  # YAML.
@@ -1525,7 +1487,8 @@ class Gem::Specification
1525
1487
  end
1526
1488
  end
1527
1489
 
1528
- overwrite_accessor :files do
1490
+ undef_method :files
1491
+ def files
1529
1492
  # DO NOT CHANGE TO ||= ! This is not a normal accessor. (yes, it sucks)
1530
1493
  @files = [@files,
1531
1494
  @test_files,
@@ -1562,4 +1525,14 @@ class Gem::Specification
1562
1525
  def dependent_specs
1563
1526
  runtime_dependencies.map { |dep| Gem.source_index.search dep, true }.flatten
1564
1527
  end
1528
+
1529
+ extend Deprecate
1530
+
1531
+ deprecate :test_suite_file, :test_file, 2011, 10
1532
+ deprecate :test_suite_file=, :test_file=, 2011, 10
1533
+ deprecate :has_rdoc, :none, 2011, 10
1534
+ deprecate :has_rdoc?, :none, 2011, 10
1535
+ deprecate :has_rdoc=, :none, 2011, 10
1536
+ deprecate :default_executable, :none, 2011, 10
1537
+ deprecate :default_executable=, :none, 2011, 10
1565
1538
  end