batch-require 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 53ee3ca8ee010477ee3ee907fe9253d8ceeed941
4
+ data.tar.gz: 7ee46aae94af7600c2ac6349a5e0f61cb5bcf59f
5
+ SHA512:
6
+ metadata.gz: b218352e6e2e01494097989e0342b1ea04bbae5be1377c80ee3e85a6e67ee0b5f1f6ae46ff2be523e3e356b04ba874a76309cc18003b8530e2c0c53a497d0be7
7
+ data.tar.gz: 85e842a0c282b6d89e803e21c76b80a09db76dab53b387f34db32695bc76b17b89e013e20a73e0f154a3210688da237aaa64a47fdf73f9532f17115980fd6e21
@@ -0,0 +1,41 @@
1
+ require 'open-uri'
2
+
3
+ def internet_connection?
4
+ begin
5
+ true if open("http://www.google.com/")
6
+ rescue
7
+ false
8
+ end
9
+ end
10
+
11
+ def require_list_modify list
12
+
13
+ for i in (0..list.count-1)
14
+ list[i] = list[i].split("(")[0].gsub(" ","")
15
+ end
16
+
17
+ return list
18
+
19
+ end
20
+
21
+ def require_inbuilt_modify list
22
+
23
+ for i in (0..list.count-1)
24
+ list[i] = list[i].gsub(".rb","")
25
+ end
26
+
27
+ return list
28
+
29
+ end
30
+
31
+ def inbuilt_path
32
+
33
+ version = Dir.entries("/usr/lib/ruby")
34
+ version.delete(".")
35
+ version.delete("..")
36
+ version.delete("vendor_ruby")
37
+ version_used = version[0]
38
+
39
+ return "/usr/lib/ruby/#{version_used}"
40
+
41
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "batch-require-helper"
2
+
3
+ class BatchRequire
4
+
5
+ def initialize *gems
6
+
7
+ gem_list_local , gem_list_server = `gem list -l`.split("\n") , internet_connection? ? `gem list -r`.split("\n") : []
8
+ gem_list_local , gem_list_server = require_list_modify(gem_list_local) , require_list_modify(gem_list_server)
9
+ gem_list_inbuilt = require_inbuilt_modify(Dir.entries(inbuilt_path()).keep_if { |inbuilt| (inbuilt.end_with? ".rb")})
10
+ all_gems = (gem_list_local + gem_list_server + gem_list_inbuilt).uniq
11
+
12
+ gems.each do |each_gem|
13
+ if all_gems.include? each_gem
14
+ if gem_list_local.include? each_gem
15
+ require "#{each_gem}"
16
+ elsif gem_list_inbuilt.include? each_gem
17
+ require "#{each_gem}"
18
+ elsif gem_list_server.include? each_gem
19
+ if internet_connection?
20
+ `gem install #{each_gem}`
21
+ require "#{each_gem}"
22
+ else
23
+ puts "#{each_gem} gem couldn't be downloaded due to no internet connection"
24
+ end
25
+ end
26
+ else
27
+ puts "Invalid gem : #{each_gem}."
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: batch-require
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Athitya Kumar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem that can act as a Gemlock file for ruby with non-rails structure.
14
+ Online feature allows installation of non-instaled gems while offline feature allows
15
+ requiring of gems.
16
+ email: athityakumar@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/batch-require-helper.rb
22
+ - lib/batch-require.rb
23
+ homepage: http://rubygems.org/gems/batch-require
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.4
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Requires list of gems
47
+ test_files: []