libgems 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -98,7 +98,7 @@ require 'thread'
98
98
  module LibGems
99
99
  NAME = 'LibGems'
100
100
  GEM_NAME = 'libgems'
101
- VERSION = '0.0.2'
101
+ VERSION = '0.0.3'
102
102
  GEM_VERSION = '1.3.8'
103
103
 
104
104
  ##
@@ -173,40 +173,33 @@ module LibGems
173
173
  @pre_uninstall_hooks ||= []
174
174
  @pre_install_hooks ||= []
175
175
 
176
+
177
+ def self.rubygems_compat?
178
+ @using_rubygems_compat
179
+ end
180
+
176
181
  ##
177
- # Specialized eval for gemspecs that sets Gem to LibGems
182
+ # Run code with Gem = LibGems
178
183
 
179
- def self.gemspec_eval(str, *args)
180
- eval(<<-end_eval, *args)
184
+ def self.with_rubygems_compat
185
+ unless LibGems.rubygems_compat?
181
186
  begin
187
+ @using_rubygems_compat = true
182
188
  libgems_original_gem = nil
183
189
  if Object.const_defined?(:Gem)
184
190
  libgems_original_gem = Object::Gem
185
191
  Object.send(:remove_const, :Gem)
186
192
  end
187
193
  Object.const_set(:Gem, LibGems)
188
- #{str}
194
+ yield
189
195
  ensure
190
196
  Object.send(:remove_const, :Gem)
191
197
  Object.const_set(:Gem, libgems_original_gem) if libgems_original_gem
198
+ @using_rubygems_compat = false
192
199
  end
193
- end_eval
194
- end
195
-
196
- ##
197
- # Run code with Gem = LibGems
198
-
199
- def self.with_rubygems_compat
200
- libgems_original_gem = nil
201
- if Object.const_defined?(:Gem)
202
- libgems_original_gem = Object::Gem
203
- Object.send(:remove_const, :Gem)
200
+ else
201
+ yield
204
202
  end
205
- Object.const_set(:Gem, LibGems)
206
- yield
207
- ensure
208
- Object.send(:remove_const, :Gem)
209
- Object.const_set(:Gem, libgems_original_gem) if libgems_original_gem
210
203
  end
211
204
 
212
205
  ##
@@ -471,7 +464,7 @@ module LibGems
471
464
  base = File.basename(gp)
472
465
  specfn = File.join(dir, "specifications", base + ".gemspec")
473
466
  if File.exist?(specfn)
474
- spec = gemspec_eval(File.read(specfn))
467
+ spec = with_rubygems_compat{ eval(File.read(specfn)) }
475
468
  spec.require_paths.each do |rp|
476
469
  yield(File.join(gp, rp))
477
470
  end
@@ -1251,5 +1244,7 @@ class << LibGems
1251
1244
  end
1252
1245
  end
1253
1246
 
1247
+ require 'libgems/custom_require'
1248
+
1254
1249
  LibGems.clear_paths
1255
1250
  LibGems.load_configuration
@@ -47,7 +47,7 @@ class LibGems::Commands::BuildCommand < LibGems::Command
47
47
 
48
48
  def yaml?(filename)
49
49
  line = open(filename) { |f| line = f.gets }
50
- result = line =~ %r{!ruby/object:LibGems::Specification}
50
+ result = line =~ %r{!ruby/object:Gem::Specification}
51
51
  result
52
52
  end
53
53
  end
@@ -26,11 +26,14 @@ module Kernel
26
26
  # that file has already been loaded is preserved.
27
27
 
28
28
  def require(path) # :doc:
29
- libgems_original_require path
29
+ # If we're using rubygems compat mode we don't want to call the original RubyGems require
30
+ require_method = (LibGems.rubygems_compat? && defined?(gem_original_require)) ?
31
+ :gem_original_require : :libgems_original_require
32
+ send(require_method, path)
30
33
  rescue LoadError => load_error
31
34
  if load_error.message.end_with?(path)
32
35
  if LibGems.try_activate(path)
33
- return libgems_original_require(path)
36
+ return send(require_method, path)
34
37
  end
35
38
  end
36
39
 
@@ -138,6 +138,10 @@ class LibGems::Requirement
138
138
  as_list.join ", "
139
139
  end
140
140
 
141
+ def to_yaml_type
142
+ "!ruby/object:Gem::Requirement"
143
+ end
144
+
141
145
  def <=> other # :nodoc:
142
146
  to_s <=> other.to_s
143
147
  end
@@ -92,7 +92,7 @@ class LibGems::SourceIndex
92
92
  end.untaint
93
93
 
94
94
  begin
95
- gemspec = LibGems.gemspec_eval(spec_code, binding, file_name)
95
+ gemspec = LibGems.with_rubygems_compat{ eval(spec_code, binding, file_name) }
96
96
 
97
97
  if gemspec.is_a?(LibGems::Specification)
98
98
  gemspec.loaded_from = file_name
@@ -505,7 +505,7 @@ class LibGems::Specification
505
505
  raise "NESTED Specification.load calls not allowed!" if @@gather
506
506
  @@gather = proc { |gs| gemspec = gs }
507
507
  data = File.read filename
508
- LibGems.gemspec_eval(data, nil, filename)
508
+ LibGems.with_rubygems_compat{ eval(data, nil, filename) }
509
509
  gemspec
510
510
  ensure
511
511
  @@gather = nil
@@ -708,10 +708,14 @@ class LibGems::Specification
708
708
  encode_with map
709
709
  end
710
710
  end
711
- ret.gsub("!ruby/object:LibGems", "!ruby/object:Gem")
711
+ ret #.to_s.gsub("!ruby/object:LibGems", "!ruby/object:Gem").to_yaml
712
712
  end
713
713
  end
714
714
 
715
+ def to_yaml_type
716
+ "!ruby/object:Gem::Specification"
717
+ end
718
+
715
719
  def init_with coder # :nodoc:
716
720
  yaml_initialize coder.tag, coder.map
717
721
  end
@@ -313,4 +313,9 @@ class LibGems::Version
313
313
 
314
314
  return 0
315
315
  end
316
+
317
+ def to_yaml_type
318
+ "!ruby/object:Gem::Version"
319
+ end
320
+
316
321
  end
@@ -23,10 +23,10 @@ SIMPLE_GEM = <<-GEMDATA
23
23
  end
24
24
 
25
25
  __END__
26
- --- !ruby/object:LibGems::Specification
26
+ --- !ruby/object:Gem::Specification
27
27
  rubygems_version: "1.0"
28
28
  name: testing
29
- version: !ruby/object:LibGems::Version
29
+ version: !ruby/object:Gem::Version
30
30
  version: 1.2.3
31
31
  date: 2004-03-18 22:01:52.859121 -05:00
32
32
  platform:
@@ -19,7 +19,7 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
19
19
  @cmd.execute
20
20
  end
21
21
 
22
- assert_match %r|LibGems::Specification|, @ui.output
22
+ assert_match %r|Gem::Specification|, @ui.output
23
23
  assert_match %r|name: foo|, @ui.output
24
24
  assert_equal '', @ui.error
25
25
  end
@@ -35,7 +35,7 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
35
35
  @cmd.execute
36
36
  end
37
37
 
38
- assert_match %r|LibGems::Specification|, @ui.output
38
+ assert_match %r|Gem::Specification|, @ui.output
39
39
  assert_match %r|name: foo|, @ui.output
40
40
  assert_match %r|version: 0.0.1|, @ui.output
41
41
  assert_match %r|version: 0.0.2|, @ui.output
@@ -65,7 +65,7 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
65
65
  @cmd.execute
66
66
  end
67
67
 
68
- assert_match %r|LibGems::Specification|, @ui.output
68
+ assert_match %r|Gem::Specification|, @ui.output
69
69
  assert_match %r|name: foo|, @ui.output
70
70
  assert_equal '', @ui.error
71
71
  end
@@ -115,7 +115,7 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
115
115
  @cmd.execute
116
116
  end
117
117
 
118
- assert_match %r|\A--- !ruby/object:LibGems::Specification|, @ui.output
118
+ assert_match %r|\A--- !ruby/object:Gem::Specification|, @ui.output
119
119
  assert_match %r|name: foo|, @ui.output
120
120
  end
121
121
 
@@ -130,7 +130,7 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
130
130
  @cmd.execute
131
131
  end
132
132
 
133
- assert_match %r|LibGems::Specification.new|, @ui.output
133
+ assert_match %r|Gem::Specification.new|, @ui.output
134
134
  assert_match %r|s.name = %q\{foo\}|, @ui.output
135
135
  assert_equal '', @ui.error
136
136
  end
@@ -520,7 +520,7 @@ eighty characters.&lt;/pre&gt;
520
520
  yaml_path = File.join @tempdir, 'yaml'
521
521
  dump_path = File.join @tempdir, "Marshal.#{@marshal_version}"
522
522
 
523
- yaml_index = YAML.load_file yaml_path
523
+ yaml_index = LibGems.with_rubygems_compat{ YAML.load_file yaml_path }
524
524
  dump_index = Marshal.load LibGems.read_binary(dump_path)
525
525
 
526
526
  dump_index.each do |_,gem|
@@ -840,7 +840,7 @@ load LibGems.bin_path('a', 'my_exec', version)
840
840
  @installer.write_spec
841
841
 
842
842
  assert File.exist?(spec_file)
843
- assert_equal @spec, LibGems.gemspec_eval(File.read(spec_file))
843
+ assert_equal @spec, LibGems.with_rubygems_compat{ eval(File.read(spec_file)) }
844
844
  end
845
845
 
846
846
  def old_ruby_required
@@ -119,7 +119,7 @@ class TestGemServer < RubyGemTestCase
119
119
  assert @res['date']
120
120
  assert_equal 'application/x-deflate', @res['content-type']
121
121
 
122
- spec = YAML.load LibGems.inflate(@res.body)
122
+ spec = LibGems.with_rubygems_compat{ YAML.load LibGems.inflate(@res.body) }
123
123
  assert_equal 'a', spec.name
124
124
  assert_equal LibGems::Version.new(1), spec.version
125
125
  end
@@ -136,7 +136,7 @@ class TestGemServer < RubyGemTestCase
136
136
  assert @res['date']
137
137
  assert_equal 'application/x-deflate', @res['content-type']
138
138
 
139
- spec = YAML.load LibGems.inflate(@res.body)
139
+ spec = LibGems.with_rubygems_compat{ YAML.load LibGems.inflate(@res.body) }
140
140
  assert_equal 'a', spec.name
141
141
  assert_equal LibGems::Version.new(1), spec.version
142
142
  assert_equal LibGems::Platform.local, spec.platform
@@ -154,7 +154,7 @@ class TestGemServer < RubyGemTestCase
154
154
  assert @res['date']
155
155
  assert_equal 'application/x-deflate', @res['content-type']
156
156
 
157
- spec = YAML.load LibGems.inflate(@res.body)
157
+ spec = LibGems.with_rubygems_compat{ YAML.load LibGems.inflate(@res.body) }
158
158
  assert_equal 'a', spec.name
159
159
  assert_equal LibGems::Version.new(1), spec.version
160
160
  end
@@ -318,7 +318,7 @@ class TestGemServer < RubyGemTestCase
318
318
  si = LibGems::SourceIndex.new
319
319
  si.add_specs @a1, @a2
320
320
 
321
- assert_equal si, YAML.load(@res.body)
321
+ assert_equal si, LibGems.with_rubygems_compat{ YAML.load(@res.body) }
322
322
  end
323
323
 
324
324
  def test_yaml_Z
@@ -334,7 +334,7 @@ class TestGemServer < RubyGemTestCase
334
334
  si = LibGems::SourceIndex.new
335
335
  si.add_specs @a1, @a2
336
336
 
337
- assert_equal si, YAML.load(LibGems.inflate(@res.body))
337
+ assert_equal si, LibGems.with_rubygems_compat{ YAML.load(LibGems.inflate(@res.body)) }
338
338
  end
339
339
 
340
340
  def util_listen
@@ -152,7 +152,7 @@ EOF
152
152
  end
153
153
 
154
154
  def test_self_load_legacy_ruby
155
- spec = LibGems.gemspec_eval LEGACY_RUBY_SPEC
155
+ spec = LibGems.with_rubygems_compat{ eval LEGACY_RUBY_SPEC }
156
156
  assert_equal 'keyedlist', spec.name
157
157
  assert_equal '0.4.0', spec.version.to_s
158
158
  assert_equal true, spec.has_rdoc?
@@ -162,7 +162,7 @@ EOF
162
162
  end
163
163
 
164
164
  def test_self_load_rubygems_style
165
- spec = LibGems.gemspec_eval RUBYGEMS_SPEC
165
+ spec = LibGems.with_rubygems_compat{ eval RUBYGEMS_SPEC }
166
166
  assert_equal LibGems::Specification, spec.class
167
167
  assert_equal 'rubygems-compatible', spec.name
168
168
  assert_equal '1.0', spec.version.to_s
@@ -811,11 +811,11 @@ EOF
811
811
  expected = <<-SPEC
812
812
  # -*- encoding: utf-8 -*-
813
813
 
814
- LibGems::Specification.new do |s|
814
+ Gem::Specification.new do |s|
815
815
  s.name = %q{a}
816
816
  s.version = \"2\"
817
817
 
818
- s.required_rubygems_version = LibGems::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
818
+ s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
819
819
  s.authors = [\"A User\"]
820
820
  s.date = %q{#{LibGems::Specification::TODAY.strftime "%Y-%m-%d"}}
821
821
  s.description = %q{This is a test description}
@@ -827,9 +827,9 @@ LibGems::Specification.new do |s|
827
827
  s.summary = %q{this is a summary}
828
828
 
829
829
  if s.respond_to? :specification_version then
830
- s.specification_version = #{LibGems::Specification::CURRENT_SPECIFICATION_VERSION}
830
+ s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
831
831
 
832
- if LibGems::Version.new(LibGems::GEM_VERSION) >= LibGems::Version.new('1.2.0') then
832
+ if Gem::Version.new(Gem::GEM_VERSION) >= Gem::Version.new('1.2.0') then
833
833
  s.add_runtime_dependency(%q<b>, [\"= 1\"])
834
834
  else
835
835
  s.add_dependency(%q<b>, [\"= 1\"])
@@ -842,7 +842,7 @@ end
842
842
 
843
843
  assert_equal expected, ruby_code
844
844
 
845
- same_spec = LibGems.gemspec_eval ruby_code
845
+ same_spec = LibGems.with_rubygems_compat{ eval ruby_code }
846
846
 
847
847
  assert_equal @a2, same_spec
848
848
  end
@@ -857,12 +857,12 @@ end
857
857
  expected = <<-SPEC
858
858
  # -*- encoding: utf-8 -*-
859
859
 
860
- LibGems::Specification.new do |s|
860
+ Gem::Specification.new do |s|
861
861
  s.name = %q{a}
862
862
  s.version = \"1\"
863
- s.platform = LibGems::Platform.new(#{expected_platform})
863
+ s.platform = Gem::Platform.new(#{expected_platform})
864
864
 
865
- s.required_rubygems_version = LibGems::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
865
+ s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
866
866
  s.authors = [\"A User\"]
867
867
  s.date = %q{#{LibGems::Specification::TODAY.strftime "%Y-%m-%d"}}
868
868
  s.default_executable = %q{exec}
@@ -884,7 +884,7 @@ LibGems::Specification.new do |s|
884
884
  if s.respond_to? :specification_version then
885
885
  s.specification_version = 3
886
886
 
887
- if LibGems::Version.new(LibGems::GEM_VERSION) >= LibGems::Version.new('1.2.0') then
887
+ if Gem::Version.new(Gem::GEM_VERSION) >= Gem::Version.new('1.2.0') then
888
888
  s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
889
889
  s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"])
890
890
  s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
@@ -903,15 +903,15 @@ end
903
903
 
904
904
  assert_equal expected, ruby_code
905
905
 
906
- same_spec = LibGems.gemspec_eval ruby_code
906
+ same_spec = LibGems.with_rubygems_compat{ eval ruby_code }
907
907
 
908
908
  assert_equal @a1, same_spec
909
909
  end
910
910
 
911
911
  def test_to_ruby_legacy
912
- gemspec1 = LibGems.gemspec_eval LEGACY_RUBY_SPEC
912
+ gemspec1 = LibGems.with_rubygems_compat{ eval LEGACY_RUBY_SPEC }
913
913
  ruby_code = gemspec1.to_ruby
914
- gemspec2 = LibGems.gemspec_eval ruby_code
914
+ gemspec2 = LibGems.with_rubygems_compat{ eval ruby_code }
915
915
 
916
916
  assert_equal gemspec1, gemspec2
917
917
  end
@@ -922,7 +922,7 @@ end
922
922
 
923
923
  ruby_code = @a2.to_ruby
924
924
 
925
- same_spec = LibGems.gemspec_eval ruby_code
925
+ same_spec = LibGems.with_rubygems_compat{ eval ruby_code }
926
926
 
927
927
  assert_equal 'old_platform', same_spec.original_platform
928
928
  end
@@ -932,7 +932,7 @@ end
932
932
 
933
933
  refute_match '!!null', yaml_str
934
934
 
935
- same_spec = YAML.load(yaml_str)
935
+ same_spec = LibGems.with_rubygems_compat{ YAML.load(yaml_str) }
936
936
 
937
937
  assert_equal @a1, same_spec
938
938
  end
@@ -941,7 +941,7 @@ end
941
941
  @a1.platform = LibGems::Platform.local
942
942
  yaml_str = @a1.to_yaml
943
943
 
944
- same_spec = YAML.load(yaml_str)
944
+ same_spec = LibGems.with_rubygems_compat{ YAML.load(yaml_str) }
945
945
 
946
946
  assert_equal LibGems::Platform.local, same_spec.platform
947
947
 
@@ -960,7 +960,7 @@ end
960
960
 
961
961
  yaml_str = @a1.to_yaml
962
962
 
963
- same_spec = YAML.load yaml_str
963
+ same_spec = LibGems.with_rubygems_compat{ YAML.load yaml_str }
964
964
 
965
965
  assert_equal LibGems::Platform.new('powerpc-darwin7'), same_spec.platform
966
966
  assert_equal 'powerpc-darwin7.9.0', same_spec.original_platform
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: libgems
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jim Weirich
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2011-06-11 00:00:00 Z
16
+ date: 2011-06-14 00:00:00 Z
17
17
  dependencies: []
18
18
 
19
19
  description: |
@@ -290,7 +290,7 @@ files:
290
290
  homepage: http://rubygems.org
291
291
  licenses: []
292
292
 
293
- post_install_message: "Upgraded from LibGems to LibGems 0.0.2\n\
293
+ post_install_message: "Upgraded from LibGems to LibGems 0.0.3\n\
294
294
  \xEF\xBB\xBF=== 1.3.8 / 2011-05-16\n\n\
295
295
  SlimGems is born! SlimGems is a fork of RubyGems, see README.md for more.\n\n"
296
296
  rdoc_options: []