rgversion 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0a671e6288a2cf7effb0dcc715f75ce710720c91465a44eb1e8ced3a9a27698
4
- data.tar.gz: c5279810cbcc65be48b74308288b2bbfa46f524720f7e04e9212c765cef0e49b
3
+ metadata.gz: 00cfb6d88a01bd4035fc2000dc3f3c9744c5e68b38ab8f0169524a32848e00f2
4
+ data.tar.gz: 90d9af0b08e23dba45bd18025cda7cf858efc5d1b4800fc6eda1879f711e445e
5
5
  SHA512:
6
- metadata.gz: 936742e033502d8c90677c7cb369624934642aa6569132d2ffc0aa0a1bd06957bdca0261472ea220122440f9859604dcbe9ad0b75c33fe12b2003e93d76e9a4e
7
- data.tar.gz: f4818a33250b332daf42b2f62bb14a814d5a739f34a394994fd62476d40c20b65f233fa52719c39bca522edbc339fdd47a445078ee4596ae77472b37ce967e3e
6
+ metadata.gz: 5f757a76858f05e9bf37a5b82dfa781f5cb2fe8fc8448d3aa973ee66b741ddb8a3a97533ee446ddb2066808dcfd905983ebf109cbd908022afd125a668f3044b
7
+ data.tar.gz: 628937f24f440e1d06a354daabb7b057cb58f53fc74efa16a148ec4a4f378a09034605f7cbaf54140a7f730cfc9ab51747bbea777627cd0543e12c30c8362374
@@ -6,9 +6,9 @@ module Rgversion
6
6
  end
7
7
 
8
8
  def run
9
- terminal = Terminal.new(results)
9
+ terminal = Terminal.new(command, results)
10
10
  terminal.report
11
- terminal.copy_to_clipboard if OS.mac?
11
+ terminal.copy_to_clipboard
12
12
  rescue StandardError => ex
13
13
  $stderr.puts ex.message
14
14
  end
@@ -19,5 +19,11 @@ module Rgversion
19
19
  spider = Spider.new(@gems, @selector)
20
20
  spider.walk
21
21
  end
22
+
23
+ def command
24
+ return :pbcopy if OS.mac?
25
+ return :xclip if OS.linux?
26
+ nil
27
+ end
22
28
  end
23
29
  end
@@ -1,6 +1,7 @@
1
1
  module Rgversion
2
2
  class Terminal
3
- def initialize(results)
3
+ def initialize(command, results)
4
+ @command = command
4
5
  @results = results
5
6
  end
6
7
 
@@ -11,8 +12,12 @@ module Rgversion
11
12
 
12
13
  def copy_to_clipboard
13
14
  return if @output.blank?
14
- `echo "#{@output}" | pbcopy`
15
- puts "\nCopied to your clipboard!".green
15
+ if command_exists?
16
+ `echo "#{@output}" | #{clarified_command}`
17
+ puts "\nCopied to your clipboard!".green
18
+ else
19
+ render_instructions
20
+ end
16
21
  end
17
22
 
18
23
  private
@@ -28,5 +33,37 @@ module Rgversion
28
33
  @output = @results[:gems].join("\n")
29
34
  puts @output
30
35
  end
36
+
37
+ def clarified_command
38
+ return "#{@command} -selection clipboard" if OS.linux?
39
+ @command
40
+ end
41
+
42
+ def command_exists?
43
+ return false if which(@command.to_s).nil?
44
+ true
45
+ end
46
+
47
+ # based on https://stackoverflow.com/a/5471032
48
+ # let's avoid find_executable from mkmf because in this case we need to supress logs
49
+ def which(cmd)
50
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
51
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
52
+ exts.each do |ext|
53
+ exe = File.join(path, "#{cmd}#{ext}")
54
+ return exe if File.executable?(exe) && !File.directory?(exe)
55
+ end
56
+ end
57
+ nil
58
+ end
59
+
60
+ def render_instructions
61
+ if @command.nil?
62
+ puts "\nRgversion doesn't support copy to clipboard feature if your OS isn't macOS or Linux. You can manually copy output above."
63
+ else
64
+ puts "\nUnable to copy to clipboard because #{@command} is missed.\nTry the command below if you are on Ubuntu/Debian:"
65
+ puts "sudo apt-get install #{@command}"
66
+ end
67
+ end
31
68
  end
32
69
  end
@@ -1,4 +1,4 @@
1
1
  module Rgversion
2
- VERSION = "1.1.3".freeze
3
- PREVIOUS_VERSION = "1.1.2".freeze
2
+ VERSION = "1.1.4".freeze
3
+ PREVIOUS_VERSION = "1.1.3".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - vavgustov