depend 0.0.1.pre.rc1 → 0.0.1.pre.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64069d3806ad6dc7187205281ebab1c2ecdca6f4
4
- data.tar.gz: 07e94403564b0fb3e5429332d05e53f6992d5fcd
3
+ metadata.gz: 0d369724bdd4e5ea3265934ee5f331f5700f9c3b
4
+ data.tar.gz: a9938335cf39d63612e20e4d36cd19c1dac4382a
5
5
  SHA512:
6
- metadata.gz: ac3ed0bad5ed9ca186636830bd8b28fad5dfc4a7a2ba536c4bba83b0b68ab0ed9af42b761f61b47de67b6a3116be61c0d0b5c6a43ddbea7c86eab42176677852
7
- data.tar.gz: afd577b26a039a9887de36f5637d0fae561a597caa1d2776bc63c6c14ca2b41eac7d916e630aa41030d82db2ddbd1ad8d417c8896201feee9f9b969abfefd865
6
+ metadata.gz: 3251fc990c16bd0e639ab417c26d221c12e21240cc3809b6c218529d6a5cf0cc42bfafb6858e3b2d19489022c369c9b196254cacb1901fd586c080742374ee3f
7
+ data.tar.gz: 78646ddec97d5aa9273296227dcd6f1806e7b2040f00d8b5ce201003def95ecefbd934ef855655be1b662b94e83482353b48b9b5a35faaeffb66c9cab3604a92
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/depend`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
- With Depend, you can handle native dependent more easily for rubygems
5
+ With Depend, you can handle native dependent more easily
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,6 +22,27 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ ```ruby
26
+ class YourGem::Depend < Depend::Base
27
+ def mac_os_x
28
+ case package_provider
29
+ when 'homebrew'
30
+ %w{mysql-dev}
31
+ when 'macports'
32
+ %w{mysql-dev}
33
+ end
34
+ end
35
+
36
+ def ubuntu
37
+ %w{mysql-dev}
38
+ end
39
+
40
+ def fedora
41
+ %w{mysql-devel}
42
+ end
43
+ end
44
+ ```
45
+
25
46
  ## Development
26
47
 
27
48
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'test'
6
+ t.test_files = FileList["test/*spec.rb"]
6
7
  end
7
8
 
8
9
  desc "Run tests"
data/depend.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Newell Zhu"]
10
10
  spec.email = ["zlx.star@gmail.com"]
11
11
  spec.license = 'MIT'
12
- spec.summary = %q{RubyGems Native Depend Solution.}
12
+ spec.summary = %q{RubyGems Native Depend Solution}
13
13
  spec.description = %q{RubyGems Native Depend Solution.}
14
14
  spec.homepage = "https://github.com/zlx/depend"
15
15
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "ohai", "~> 6.20.0"
21
+ spec.add_dependency "os_platform"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.9"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
@@ -0,0 +1,23 @@
1
+ module Depend
2
+ class Configuration
3
+ attr_accessor :default_dependencies, :homebrew_dependencies, :apt_dependencies
4
+
5
+ def initialize
6
+ @default_dependencies = []
7
+ @homebrew_dependencies = []
8
+ @apt_dependencies = []
9
+ end
10
+
11
+ def dependencies_for_default=(deps = [])
12
+ @default_dependencies = deps
13
+ end
14
+
15
+ def dependencies_for_homebrew=(deps = [])
16
+ @homebrew_dependencies = deps
17
+ end
18
+
19
+ def dependencies_for_apt=(deps = [])
20
+ @apt_dependencies = deps
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Depend
2
+ module Dependent
3
+
4
+ def dependencies_for(platform, package_provider)
5
+ if Depend.configuration.send("#{package_provider.display_name.downcase}_dependencies").empty?
6
+ Depend.configuration.default_dependencies
7
+ else
8
+ Depend.configuration.send("#{package_provider.display_name.downcase}_dependencies")
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ require 'os_platform'
2
+
3
+ module Depend
4
+ class Installer
5
+
6
+ def self.install
7
+ install_platform_dependencies
8
+ end
9
+
10
+ def self.install_platform_dependencies
11
+ puts "install dependency for gem"
12
+ os_platform = OSPlatform.local
13
+ depend_instance = Depend::Base.new(os_platform.platform, os_platform.platform_version)
14
+ package_providers = depend_instance.package_providers
15
+ unless package_providers.empty?
16
+ package_provider = decide(package_providers)
17
+ deps = depend_instance.dependencies_for(package_provider)
18
+
19
+ unless deps.empty?
20
+ puts "Trying to install native dependencies for Gem '#{spec.name}': #{deps.join ' '}"
21
+ deps.each do |dep|
22
+ unless package_provider.install(spec.name, dep)
23
+ raise Gem::InstallError, "Failed to install native dependencies for '#{spec.name}'."
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def self.decide(package_providers)
33
+ if package_providers.size > 1
34
+ puts "You have installed many package_providers, which do your want to install dependency for #{spec.name}"
35
+ puts package_providers.map.each_with_index do |p, i|
36
+ "#{i+1}: #{p.display_name}\n"
37
+ end.join
38
+ index = STDIN.getc
39
+ (package_providers[index] || package_providers.shift).new
40
+ else
41
+ package_providers.shift.new
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ module Depend
2
+ module PackageProvider
3
+ class Apt
4
+ include Common
5
+
6
+ def command
7
+ 'apt-get'
8
+ end
9
+
10
+ def installed?(dep)
11
+ !!system("dpkg -s #{dep}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ module Depend
2
+ module PackageProvider
3
+ module Common
4
+ # Install dep for spec
5
+ #
6
+ def install(spec, dep)
7
+ unless installed?(dep)
8
+ print "#{spec} need #{dep} installed, Install it with #{display_name} now? y(y/n)"
9
+ y = STDIN.getc
10
+ exec_install(dep) unless y.downcase == 'n'
11
+ end
12
+ installed?(dep)
13
+ end
14
+
15
+ # exec install command
16
+ #
17
+ # command: command for package_provider
18
+ # dep: library need installed
19
+ def exec_install(dep)
20
+ `#{command} install #{dep}`
21
+ end
22
+
23
+ # command for package_provider
24
+ #
25
+ def command
26
+ fail NotImplementedError, "Implement #command in subclass"
27
+ end
28
+
29
+ # Check package_provider exist in this system
30
+ #
31
+ def exist?
32
+ paths = (
33
+ ENV['PATH'].split(::File::PATH_SEPARATOR) +
34
+ %w(/bin /usr/bin /sbin /usr/sbin /opt/local/bin)
35
+ )
36
+
37
+ paths.each do |path|
38
+ possible = File.join(path, command)
39
+ return possible if File.executable?(possible)
40
+ end
41
+
42
+ false
43
+ end
44
+
45
+ # display_name for package_provider
46
+ #
47
+ def display_name
48
+ self.class.to_s.split("::").last.capitalize
49
+ end
50
+
51
+ # check dep installed in this system
52
+ def installed?(dep)
53
+ fail NotImplementedError, "Implement #installed in subclass"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ module Depend
2
+ module PackageProvider
3
+ class Homebrew
4
+ include Common
5
+
6
+ def command
7
+ "brew"
8
+ end
9
+
10
+ def installed?(dep)
11
+ !!system("#{command} info #{dep}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ module Depend
2
+ class PlatformNotSupportedError < StandardError; end
3
+
4
+ module Registerable
5
+ OPERATION_SYSTEMS = %w{ Ubuntu MacOS }.freeze
6
+ attr_accessor :platforms
7
+
8
+ def acceptable_operations_systems
9
+ OPERATION_SYSTEMS
10
+ end
11
+
12
+ def register(package_provider, platform, platform_version = nil)
13
+ puts "in register"
14
+ fail PlatformNotSupportedError unless platform_accepted?(platform)
15
+ @platforms ||= {}
16
+ if @platforms[platform]
17
+ @platforms[platform] << [platform_version, package_provider]
18
+ else
19
+ @platforms[platform] = [[platform_version, package_provider]]
20
+ end
21
+ end
22
+
23
+ def package_providers_for(platform, platform_version)
24
+ return [] if @platforms.nil? || @platforms.empty?
25
+ _platform = @platforms[platform]
26
+ _platform.select{|plat| version_include?(plat.shift, platform_version)}.map(&:last)
27
+ end
28
+
29
+ private
30
+
31
+ def version_include?(version_string, platform_version)
32
+ return true if version_string.nil?
33
+ min_version, max_version = version_string.split(",").map(&:strip)
34
+ return unless min_version
35
+ if max_version
36
+ Gem::Version.new(min_version) <= Gem::Version.new(platform_version) &&
37
+ Gem::Version.new(platform_version) <= Gem::Version.new(max_version)
38
+ else
39
+ Gem::Version.new(platform_version) >= Gem::Version.new(min_version)
40
+ end
41
+ end
42
+
43
+ def platform_accepted?(platform)
44
+ OPERATION_SYSTEMS.map(&:downcase).include?(platform.downcase)
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Depend
2
- VERSION = "0.0.1-rc1"
2
+ VERSION = "0.0.1-rc2"
3
3
  end
data/lib/depend.rb CHANGED
@@ -1,6 +1,55 @@
1
1
  require "depend/version"
2
- require "depend/bundler"
3
2
 
4
3
  module Depend
5
- # Your code goes here...
4
+ autoload :Registerable, "depend/registerable"
5
+ autoload :Dependent, "depend/dependent"
6
+ autoload :Configuration, "depend/configuration"
7
+
8
+ module PackageProvider
9
+ autoload :Common, "depend/package_provider/common"
10
+ autoload :Apt, "depend/package_provider/apt"
11
+ autoload :Homebrew, "depend/package_provider/homebrew"
12
+ end
13
+
14
+ class << self
15
+ attr_writer :configuration
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def self.reset_configuration
23
+ @configuration = Configuration.new
24
+ end
25
+
26
+ def self.configure
27
+ puts "in configure"
28
+ yield(configuration)
29
+ end
30
+
31
+ class Base
32
+ extend Registerable
33
+ extend Dependent
34
+
35
+ self.register PackageProvider::Apt, 'Ubuntu'
36
+ self.register PackageProvider::Homebrew, 'MacOS'
37
+
38
+ OPERATION_SYSTEMS = %w{ Ubuntu MacOS }.freeze
39
+
40
+ def initialize(platform, platform_version = nil)
41
+ @platform = platform
42
+ @platform_version = platform_version
43
+ end
44
+
45
+ def package_providers
46
+ self.class.package_providers_for(@platform, @platform_version)
47
+ end
48
+
49
+ def dependencies_for(package_provider)
50
+ self.class.dependencies_for(@platform, package_provider)
51
+ end
52
+
53
+ end
54
+
6
55
  end
@@ -1 +1,6 @@
1
- require 'rubygems/depend'
1
+ require 'depend/installer'
2
+
3
+ Gem.pre_install do |gem_installer|
4
+ puts "inside gem pre install"
5
+ Depend::Installer.install
6
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: depend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.rc1
4
+ version: 0.0.1.pre.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Newell Zhu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ohai
14
+ name: os_platform
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 6.20.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 6.20.0
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,21 +80,16 @@ files:
80
80
  - Rakefile
81
81
  - bin/console
82
82
  - bin/setup
83
- - data/fedora.yml
84
83
  - depend.gemspec
85
84
  - lib/depend.rb
86
- - lib/depend/bundler.rb
85
+ - lib/depend/configuration.rb
86
+ - lib/depend/dependent.rb
87
+ - lib/depend/installer.rb
88
+ - lib/depend/package_provider/apt.rb
89
+ - lib/depend/package_provider/common.rb
90
+ - lib/depend/package_provider/homebrew.rb
91
+ - lib/depend/registerable.rb
87
92
  - lib/depend/version.rb
88
- - lib/rubygems/depend.rb
89
- - lib/rubygems/depend/dependency.rb
90
- - lib/rubygems/depend/host_detection.rb
91
- - lib/rubygems/depend/host_detection/package_provider.rb
92
- - lib/rubygems/depend/host_detection/platform.rb
93
- - lib/rubygems/depend/installer.rb
94
- - lib/rubygems/depend/installer/apt_installer.rb
95
- - lib/rubygems/depend/installer/base_installer.rb
96
- - lib/rubygems/depend/installer/homebrew_installer.rb
97
- - lib/rubygems/depend/installer/yum_installer.rb
98
93
  - lib/rubygems_plugin.rb
99
94
  homepage: https://github.com/zlx/depend
100
95
  licenses:
@@ -119,5 +114,5 @@ rubyforge_project:
119
114
  rubygems_version: 2.2.0
120
115
  signing_key:
121
116
  specification_version: 4
122
- summary: RubyGems Native Depend Solution.
117
+ summary: RubyGems Native Depend Solution
123
118
  test_files: []
data/data/fedora.yml DELETED
@@ -1,154 +0,0 @@
1
- basic_build_deps:
2
- - gcc
3
- - ruby-devel
4
- - make
5
- gems:
6
- atk:
7
- - atk-devel
8
- atk-devel:
9
- - atk-devel
10
- bigdecimal:
11
- - db4-devel
12
- - gdbm-devel
13
- - libffi-devel
14
- - libyaml-devel
15
- - ncurses-devel
16
- - openssl-devel
17
- - readline-devel
18
- - tk-devel
19
- cairo:
20
- - cairo-devel
21
- cairo-devel:
22
- - cairo-devel
23
- curb:
24
- - libcurl-devel
25
- eventmachine:
26
- - openssl-devel
27
- ffi:
28
- - libffi-devel
29
- gdk_pixbuf2:
30
- - gdk-pixbuf2-devel
31
- - rubygem-cairo-devel
32
- gdk_pixbuf2-devel:
33
- - gdk-pixbuf2-devel
34
- - rubygem-cairo-devel
35
- glib2:
36
- - glib2-devel
37
- glib2-devel:
38
- - glib2-devel
39
- gtk2:
40
- - gtk2-devel
41
- - rubygem-cairo-devel
42
- gtk2-devel:
43
- - gtk2-devel
44
- - rubygem-cairo-devel
45
- gtksourceview2:
46
- - gtksourceview2-devel
47
- gtksourceview2-devel:
48
- - gtksourceview2-devel
49
- idn:
50
- - libidn-devel
51
- io-console:
52
- - db4-devel
53
- - gdbm-devel
54
- - libffi-devel
55
- - libyaml-devel
56
- - ncurses-devel
57
- - openssl-devel
58
- - readline-devel
59
- - tk-devel
60
- krb5-auth:
61
- - krb5-devel
62
- mkrf:
63
- - libxml2-devel
64
- nokogiri:
65
- - libxml2-devel
66
- - libxslt-devel
67
- pango:
68
- - pango-devel
69
- - rubygem-cairo-devel
70
- pango-devel:
71
- - pango-devel
72
- - rubygem-cairo-devel
73
- passenger:
74
- - httpd-devel
75
- - libcurl-devel
76
- - libev-devel
77
- - zlib-devel
78
- passenger-devel:
79
- - httpd-devel
80
- - libcurl-devel
81
- - libev-devel
82
- - zlib-devel
83
- passenger-native:
84
- - httpd-devel
85
- - libcurl-devel
86
- - libev-devel
87
- - zlib-devel
88
- passenger-native-libs:
89
- - httpd-devel
90
- - libcurl-devel
91
- - libev-devel
92
- - zlib-devel
93
- pg:
94
- - postgresql-devel
95
- pkg-config:
96
- - cairo-devel
97
- poppler:
98
- - poppler-glib-devel
99
- - rubygem-cairo-devel
100
- - rubygem-gtk2-devel
101
- poppler-devel:
102
- - poppler-glib-devel
103
- - rubygem-cairo-devel
104
- - rubygem-gtk2-devel
105
- qpid:
106
- - qpid-cpp-client-devel
107
- rake:
108
- - db4-devel
109
- - gdbm-devel
110
- - libffi-devel
111
- - libyaml-devel
112
- - ncurses-devel
113
- - openssl-devel
114
- - readline-devel
115
- - tk-devel
116
- rdoc:
117
- - db4-devel
118
- - gdbm-devel
119
- - libffi-devel
120
- - libyaml-devel
121
- - ncurses-devel
122
- - openssl-devel
123
- - readline-devel
124
- - tk-devel
125
- rsvg2:
126
- - librsvg2-devel
127
- - rubygem-cairo-devel
128
- rsvg2-devel:
129
- - librsvg2-devel
130
- - rubygem-cairo-devel
131
- ruby-libvirt:
132
- - libvirt-devel
133
- ruby-opengl:
134
- - freeglut-devel
135
- - libGL-devel
136
- - libGLU-devel
137
- sqlite3:
138
- - sqlite-devel
139
- thin:
140
- - libcurl-devel
141
- typhoeus:
142
- - libcurl-devel
143
- vte:
144
- - vte-devel
145
- vte-devel:
146
- - vte-devel
147
- xmlparser:
148
- - expat-devel
149
- zoom:
150
- - libgcrypt-devel
151
- - libgpg-error-devel
152
- - libxslt-devel
153
- - libyaz-devel
154
- - tcp_wrappers-devel
@@ -1,9 +0,0 @@
1
- Bundler::Source::Path.instance_eval do
2
- unless instance_methods.include?(:orig_install)
3
- alias_method :orig_install, :install
4
- define_method(:install) do |*args|
5
- Gem.load_plugins
6
- orig_install(*args)
7
- end
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- module Depend
2
- class Dependency
3
- def self.dependencies_for(platform, spec)
4
- []
5
- end
6
- end
7
- end
@@ -1,83 +0,0 @@
1
- module Depend
2
- class HostDetection
3
- class PackageProvider
4
- COMMANDS = {
5
- 'aix' => 'installp',
6
- 'yum' => 'yum',
7
- 'packman' => 'packman',
8
- 'apt' => 'apt-get',
9
- 'feebsd' => 'pkg_add',
10
- 'portage' => 'emerge',
11
- 'homebrew' => 'brew',
12
- 'macports' => 'port',
13
- 'solaris' => 'pkg_add',
14
- 'ips' => 'pkg',
15
- 'zypper' => 'zypper',
16
- 'smartos' => 'pkgin'
17
- }.freeze
18
-
19
- PROVIDERS = {
20
- 'aix' => 'aix',
21
- 'amazon' => 'yum',
22
- 'arch' => 'pacman',
23
- 'centos' => 'yum',
24
- 'debian' => 'apt',
25
- 'fedora' => 'yum',
26
- 'freebsd' => 'freebsd',
27
- 'gcel' => 'apt',
28
- 'gentoo' => 'portage',
29
- 'linaro' => 'apt',
30
- 'linuxmint' => 'apt',
31
- 'mac_os_x' => ['homebrew', 'macports'],
32
- 'mac_os_x_server' => 'macports',
33
- 'nexentacore' => 'solaris',
34
- 'omnios' => 'ips',
35
- 'openindiana' => 'ips',
36
- 'opensolaris' => 'ips',
37
- 'opensuse' => 'zypper',
38
- 'oracle' => 'yum',
39
- 'raspbian' => 'apt',
40
- 'redhat' => 'yum',
41
- 'scientific' => 'yum',
42
- 'smartos' => 'smartos',
43
- 'solaris2' => 'ips',
44
- 'suse' => 'zypper',
45
- 'ubuntu' => 'apt',
46
- 'xcp' => 'yum',
47
- 'xenserver' => 'yum'
48
- }.freeze
49
-
50
- def initialize(platform)
51
- @platform = platform
52
- end
53
-
54
- def name
55
- providers = Array(PROVIDERS[@platform.name])
56
- return providers.first if providers.count < 2
57
-
58
- providers.find do |provider|
59
- which(COMMANDS[provider]) != nil
60
- end
61
- end
62
-
63
- protected
64
-
65
- # copied from Chef cookbook 'apt'
66
- # source: apt/libraries/helpers.rb
67
- def which(cmd)
68
- paths = (
69
- ENV['PATH'].split(::File::PATH_SEPARATOR) +
70
- %w(/bin /usr/bin /sbin /usr/sbin /opt/local/bin)
71
- )
72
-
73
- paths.each do |path|
74
- possible = File.join(path, cmd)
75
- return possible if File.executable?(possible)
76
- end
77
-
78
- nil
79
- end
80
-
81
- end
82
- end
83
- end
@@ -1,34 +0,0 @@
1
- require 'ohai'
2
-
3
- module Depend
4
- class HostDetection
5
- class Platform
6
-
7
- def initialize
8
- @ohai = build_ohai
9
- end
10
-
11
- def name
12
- ohai_hash[:platform]
13
- end
14
-
15
- def version
16
- ohai_hash[:platform_version]
17
- end
18
-
19
- def ohai_hash
20
- @ohai
21
- end
22
-
23
- protected
24
-
25
- def build_ohai
26
- ohai = Ohai::System.new
27
- ohai.require_plugin 'os'
28
- ohai.require_plugin 'platform'
29
- ohai
30
- end
31
-
32
- end
33
- end
34
- end
@@ -1,25 +0,0 @@
1
- require 'rubygems/depend/host_detection/platform'
2
- require 'rubygems/depend/host_detection/package_provider'
3
-
4
- module Depend
5
- class HostDetection
6
-
7
- def initialize(opts={})
8
- @detect_platform = opts.fetch(:detect_platform) { Platform.new }
9
- @detect_package_provider = opts.fetch(:detect_package_provider) {
10
- PackageProvider.new(@detect_platform) }
11
- end
12
-
13
- def platform
14
- @detect_platform.name
15
- end
16
-
17
- def platform_version
18
- @detect_platform.version
19
- end
20
-
21
- def package_provider
22
- @detect_package_provider.name
23
- end
24
- end
25
- end
@@ -1,8 +0,0 @@
1
- module Depend
2
- class AptInstaller < BaseInstaller
3
-
4
- def self.install(names)
5
- system "su -c 'apt-get install #{names.join(' ')}'"
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Depend
2
- class BaseInstaller
3
-
4
- def self.install(names)
5
- fail NotImplementedError
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Depend
2
- class HomebrewInstaller < BaseInstaller
3
-
4
- def self.install(names)
5
- system "su -c 'brew install #{names.join(' ')}'"
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Depend
2
- class YumInstaller < BaseInstaller
3
-
4
- def self.install(names)
5
- system "su -c 'yum install #{names.join(' ')}'"
6
- end
7
- end
8
- end
@@ -1,20 +0,0 @@
1
- require 'rubygems/depend/installer/base_installer'
2
- require 'rubygems/depend/installer/yum_installer'
3
- require 'rubygems/depend/installer/homebrew_installer'
4
- require 'rubygems/depend/installer/apt_installer'
5
-
6
- module Depend
7
- class Installer
8
-
9
- package_installers = {
10
- 'yum' => YumInstaller,
11
- 'homebrew' => HomebrewInstaller,
12
- 'apt' => AptInstaller
13
- }.freeze
14
-
15
- def self.installer(package_provider)
16
- package_installers[package_provider]
17
- end
18
-
19
- end
20
- end
@@ -1,48 +0,0 @@
1
- module Gem
2
- pre_install do |gem_installer|
3
- puts "install some gem append depend module"
4
- unless gem_installer.spec.extensions.empty?
5
- gem_installer.extend Gem::Installer::Depend
6
- end
7
- end
8
-
9
-
10
- class Installer
11
- module Depend
12
- require 'rubygems/user_interaction'
13
- require 'rubygems/depend/host_detection'
14
- require 'rubygems/depend/installer'
15
-
16
- include Gem::UserInteraction
17
-
18
- def build_extensions
19
- super
20
- puts "in build extension"
21
- rescue ExtensionBuildError => e
22
- # Install platform dependencies and try the build again.
23
- if install_platform_dependencies
24
- super
25
- else
26
- raise
27
- end
28
- end
29
-
30
- def install_platform_dependencies
31
- puts "install dependency for gem"
32
- platform = Depend::HostDetection.new.platform
33
- package_provider = Depend::HostDetection.new.package_provider
34
- if installer = Depend::Installer.installer_for(package_provider)
35
- missing_deps = Depend::Dependency.dependencies_for(platform, spec.name)
36
-
37
- unless missing_deps.empty?
38
- say "Trying to install native dependencies for Gem '#{spec.name}': #{missing_deps.join ' '}"
39
- unless installer.install(spec.name, missing_deps)
40
- raise Gem::InstallError, "Failed to install native dependencies for '#{spec.name}'."
41
- end
42
- end
43
- return true
44
- end
45
- end
46
- end
47
- end
48
- end