fake-gem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/fake_gem.rb +45 -0
  2. data/lib/rubygems_plugin.rb +32 -0
  3. metadata +56 -0
@@ -0,0 +1,45 @@
1
+ require "fileutils"
2
+ require "tmpdir"
3
+ require "rubygems/installer"
4
+
5
+ class FakeGem
6
+ DEFAULT_VERSION = "99.0.0"
7
+
8
+ include Gem::UserInteraction
9
+
10
+ def initialize(name, options={})
11
+ @name = name
12
+ @options = {:install_dir => Gem.dir}.merge(options)
13
+ @version = options.delete(:version) || DEFAULT_VERSION
14
+ end
15
+
16
+ def install
17
+ temp_path = File.join(Dir.tmpdir, "fakegem.#{Process.pid}")
18
+ FileUtils.mkdir_p(temp_path)
19
+ Dir.chdir(temp_path) do
20
+ build_gem
21
+ Gem::Installer.new(specification.file_name, @options).install
22
+ end
23
+ say "Fake gem #@name #@version is now installed"
24
+ end
25
+
26
+ private
27
+ def specification
28
+ @specification ||= Gem::Specification.new{ |s|
29
+ s.name = @name
30
+ s.version = @version
31
+ s.summary = "Fake #@name gem"
32
+ s.author = "Nobody"
33
+ s.email = "nobody@localhost"
34
+ s.has_rdoc = false
35
+ s.files = []
36
+ s.executables = []
37
+ s.require_paths = ["lib"]
38
+ }
39
+ end
40
+
41
+ def build_gem
42
+ FileUtils.mkdir_p("lib")
43
+ Gem::Builder.new(specification).build
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems/command_manager'
2
+ require 'rubygems/command'
3
+ require 'fake_gem'
4
+
5
+ class Gem::Commands::FakeCommand < Gem::Command
6
+ def initialize
7
+ super "fake", "Make RubyGems think that the named gem is already installed."
8
+
9
+ add_option(
10
+ "-v", "--version VERSION",
11
+ "Specify a version for the gem (default is #{FakeGem::DEFAULT_VERSION})"
12
+ ) do |value, options|
13
+ options[:version] = value
14
+ end
15
+ end
16
+
17
+ def summary # :nodoc:
18
+ FakeGem::SUMMARY
19
+ end
20
+
21
+ def usage # :nodoc:
22
+ "#{program_name} GEMNAME [GEMNAME ...]"
23
+ end
24
+
25
+ def execute
26
+ options[:args].each do |gemname|
27
+ FakeGem.new(gemname, options).install
28
+ end
29
+ end
30
+ end
31
+
32
+ Gem::CommandManager.instance.register_command :fake
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Battley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-21 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: pbattley@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/rubygems_plugin.rb
26
+ - lib/fake_gem.rb
27
+ has_rdoc: true
28
+ homepage: http://github.com/threedaymonk/fake-gem
29
+ licenses: []
30
+
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.3.5
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Make RubyGems think that a gem is already installed.
55
+ test_files: []
56
+