rgversion 1.0.1 → 1.1.1

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
  SHA256:
3
- metadata.gz: e270d7040799c8251cb599e8fe4ec42f3af8f24a63983071a812c748515ee637
4
- data.tar.gz: a1f9fd0295fbebb3523b53b8259f5cad111b4b9890f3b146911c0596dec2d9de
3
+ metadata.gz: f679f5e8a92e54d3f4e1be4d4ade7b585d2afcf1e60803115c1a0e057ffa5439
4
+ data.tar.gz: e997b762436ef24f9921d4edbd0c9d23745d92ee0bd8d1bf71714fa8939d18ba
5
5
  SHA512:
6
- metadata.gz: 1c6731b2e4f92c1ffb328aa94ce038fab81215125fa03341452e4e7bc5338ce5de10fee6024d62877d233ffaedc56283531c6d8b26cd720362e9a999abbd54df
7
- data.tar.gz: 3180a089e8d0148e6ea63fc09f70e98bdfc5cf9546c2f53de52c37b2b607a8ac06f5a06bc9a080769843d4ff222c7ae28202f478ed9c751c14c55f11b3070c67
6
+ metadata.gz: 5446b3412ae516c1c77ea64a6eb1c3573888d63f5aeffe86c2b7b19389253b46edcc5ce725e7073129b2ca26da8e866e8cc75628f42126133566a07b3ac3a1bf
7
+ data.tar.gz: f731ded2e2ddcc1422eb4aaf97dfa8b41c988ed96db23312ecb79494d1788b708d5965f6841b39123864b2e265d09736ac4afd2c43a04eee919e0ebfd4804fbe
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- # Rgversion [![Gem](https://img.shields.io/gem/v/rgversion.svg)](https://rubygems.org/gems/rgversion) [![Build Status](https://img.shields.io/travis/vavgustov/rgversion/master.svg)](https://travis-ci.org/vavgustov/rgversion) [![Maintainability](https://api.codeclimate.com/v1/badges/b5d59c13b4d649c321ea/maintainability)](https://codeclimate.com/github/vavgustov/rgversion/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/b5d59c13b4d649c321ea/test_coverage)](https://codeclimate.com/github/vavgustov/rgversion/test_coverage)
1
+ # Rgversion
2
+ [![Gem](https://img.shields.io/gem/v/rgversion.svg)](https://rubygems.org/gems/rgversion) [![Build Status](https://img.shields.io/travis/vavgustov/rgversion/master.svg)](https://travis-ci.org/vavgustov/rgversion) [![Maintainability](https://api.codeclimate.com/v1/badges/b5d59c13b4d649c321ea/maintainability)](https://codeclimate.com/github/vavgustov/rgversion/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/b5d59c13b4d649c321ea/test_coverage)](https://codeclimate.com/github/vavgustov/rgversion/test_coverage)
2
3
 
3
- This library allow you to quickly copy latest semantic versions of specified gems to your clipboard. Versions will be taken from [`rubygems.org`](https://rubygems.org/). Then you can past them in your `Gemfile`.
4
+ This library allow you to copy latest semantic versions of specified gems from terminal to your clipboard.
5
+ Versions will be taken from [`rubygems.org`](https://rubygems.org/). Then you can past them in your `Gemfile`
6
+ or whatever you want.
4
7
  ![image](https://user-images.githubusercontent.com/312873/28492511-d2dbf140-6f0d-11e7-9912-beb8b94a1ca7.png)
5
8
 
6
9
  ## Installation
@@ -9,11 +12,14 @@ This library allow you to quickly copy latest semantic versions of specified gem
9
12
  gem install rgversion
10
13
  ```
11
14
 
12
- ##### macOS / OS X
15
+ ### macOS / OS X
13
16
  No further actions required.
14
17
 
15
- ##### Ubuntu / Debian
16
- Copy to clipboard work through ``pbcopy`` and to make it work on Ubuntu / Debian you can follow these [steps](https://coderwall.com/p/oaaqwq/pbcopy-on-ubuntu-linux).
18
+ ### Ubuntu / Debian
19
+ You may need to install xclip for clipboard feature:
20
+ ```bash
21
+ sudo apt-get install xclip
22
+ ```
17
23
 
18
24
  ## Usage
19
25
  Open terminal and execute ``rgversion`` with list of needed gems. E.g:
data/exe/rgversion CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  require "rgversion"
4
4
 
5
- Rgversion::Application.run
5
+ app = Rgversion::Application.new(ARGV, Rgversion::SELECTOR)
6
+ app.run
@@ -1,10 +1,29 @@
1
1
  module Rgversion
2
- module Application
3
- def self.run
4
- terminal = Terminal.new ARGV
2
+ class Application
3
+ def initialize(gems, selector)
4
+ @gems = gems
5
+ @selector = selector
6
+ end
7
+
8
+ def run
9
+ terminal = Terminal.new(command, results)
10
+ terminal.report
5
11
  terminal.copy_to_clipboard
6
- rescue NoArguments => ex
7
- puts ex.message
12
+ rescue StandardError => ex
13
+ $stderr.puts ex.message
14
+ end
15
+
16
+ private
17
+
18
+ def results
19
+ spider = Spider.new(@gems, @selector)
20
+ spider.walk
21
+ end
22
+
23
+ def command
24
+ return :pbcopy if OS.mac?
25
+ return :xclip if OS.linux?
26
+ nil
8
27
  end
9
28
  end
10
29
  end
@@ -1,3 +1,4 @@
1
1
  module Rgversion
2
2
  class NoArguments < StandardError; end
3
+ class WrongSelector < StandardError; end
3
4
  end
@@ -3,28 +3,39 @@ require "open-uri"
3
3
 
4
4
  module Rgversion
5
5
  class Spider
6
- def initialize(gems)
6
+ def initialize(gems, selector)
7
+ raise NoArguments, error_messages(:arguments) if gems.blank?
7
8
  @gems = gems
9
+ @selector = selector
8
10
  end
9
11
 
10
- def output
11
- gem_text = []
12
+ def walk
13
+ lines = []
14
+ errors = []
12
15
  @gems.each do |gem|
13
16
  begin
14
- gem_text << grab_version(gem)
17
+ lines << grab_version(gem)
15
18
  rescue OpenURI::HTTPError
16
- puts "#{gem} not found"
19
+ errors << "#{gem} not found"
17
20
  end
18
21
  end
19
- gem_text
22
+ { gems: lines, errors: errors }
20
23
  end
21
24
 
22
25
  private
23
26
 
27
+ def error_messages(key)
28
+ {
29
+ arguments: "No gems passed as arguments. Try to use like this:\nrgversion rails sinatra",
30
+ selector: "Selector #{@selector} doesn't exists on the page.\nRgversion should be updated."
31
+ }[key].red
32
+ end
33
+
24
34
  def grab_version(gem)
25
35
  gem_url = "https://rubygems.org/gems/#{gem}"
26
36
  gem_page = Nokogiri::HTML(open(gem_url))
27
- gem_page.at("#gemfile_text")["value"]
37
+ raise WrongSelector, error_messages(:selector) if gem_page.at(@selector).nil?
38
+ gem_page.at(@selector)["value"]
28
39
  end
29
40
  end
30
41
  end
@@ -1,24 +1,65 @@
1
1
  module Rgversion
2
2
  class Terminal
3
- def initialize(argv = [])
4
- raise NoArguments, 'No gems passed as arguments.' if argv.length.zero?
5
- @argv = argv
3
+ def initialize(command, results)
4
+ @command = command
5
+ @results = results
6
+ end
7
+
8
+ def report
9
+ render_errors
10
+ render_output
6
11
  end
7
12
 
8
13
  def copy_to_clipboard
9
- data = process_spider
10
- unless data.empty?
11
- output = data.join("\n")
12
- `echo "#{output}" | pbcopy`
13
- puts "#{output}\n\nCopied to your clipboard!"
14
+ return if @output.blank?
15
+ if command_exists?
16
+ `echo "#{@output}" | #{@command}`
17
+ puts "Copied to your clipboard!".green
18
+ else
19
+ render_instructions
14
20
  end
15
21
  end
16
22
 
17
23
  private
18
24
 
19
- def process_spider
20
- spider = Spider.new @argv
21
- spider.output
25
+ def render_errors
26
+ return if @results[:errors].blank?
27
+ puts @results[:errors].join("\n").red
28
+ puts
29
+ end
30
+
31
+ def render_output
32
+ return if @results[:gems].blank?
33
+ @output = @results[:gems].join("\n")
34
+ puts "#{@output}"
35
+ puts
36
+ end
37
+
38
+ def command_exists?
39
+ return false if which(@command.to_s).nil?
40
+ true
41
+ end
42
+
43
+ # based on https://stackoverflow.com/a/5471032
44
+ # let's avoid find_executable from mkmf because in this case we need to supress logs
45
+ def which(cmd)
46
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
47
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
48
+ exts.each do |ext|
49
+ exe = File.join(path, "#{cmd}#{ext}")
50
+ return exe if File.executable?(exe) && !File.directory?(exe)
51
+ end
52
+ end
53
+ nil
54
+ end
55
+
56
+ def render_instructions
57
+ if command.nil?
58
+ puts "Rgversion doesn't support copy to clipboard feature if your OS isn't macOS or Linux. You can manually copy output above."
59
+ else
60
+ puts "Unable to copy to clipboard because #{@command} is missed. Try the command below if you are on Ubuntu/Debian:"
61
+ puts "sudo apt-get install #{command}"
62
+ end
22
63
  end
23
64
  end
24
65
  end
@@ -1,4 +1,4 @@
1
1
  module Rgversion
2
- VERSION = "1.0.1".freeze
3
- PREVIOUS_VERSION = "1.0".freeze
2
+ VERSION = "1.1.1".freeze
3
+ PREVIOUS_VERSION = "1.0.1".freeze
4
4
  end
data/lib/rgversion.rb CHANGED
@@ -1,5 +1,12 @@
1
- require "rgversion/version"
1
+ require "active_support/core_ext/object/blank"
2
+ require "awesome_print"
3
+ require "os"
2
4
  require "rgversion/application"
3
5
  require "rgversion/exceptions"
4
6
  require "rgversion/spider"
5
7
  require "rgversion/terminal"
8
+ require "rgversion/version"
9
+
10
+ module Rgversion
11
+ SELECTOR = "#gemfile_text".freeze
12
+ end
data/rgversion.gemspec CHANGED
@@ -24,10 +24,13 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
+ spec.add_dependency "activesupport", "> 4.0", "< 6"
28
+ spec.add_dependency "awesome_print", "~> 1.8"
29
+ spec.add_dependency "nokogiri", "~> 1.8"
30
+ spec.add_dependency "os", "~> 1.0"
31
+
27
32
  spec.add_development_dependency "bundler", "~> 1.16"
28
33
  spec.add_development_dependency "rake", "~> 12.3"
29
34
  spec.add_development_dependency "rspec", "~> 3.7"
30
35
  spec.add_development_dependency "simplecov", "~> 0.15"
31
-
32
- spec.add_runtime_dependency "nokogiri", "~> 1.8"
33
36
  end
metadata CHANGED
@@ -1,15 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - vavgustov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-08 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: awesome_print
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.8'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.8'
47
+ - !ruby/object:Gem::Dependency
48
+ name: nokogiri
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.8'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.8'
61
+ - !ruby/object:Gem::Dependency
62
+ name: os
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
13
75
  - !ruby/object:Gem::Dependency
14
76
  name: bundler
15
77
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +128,6 @@ dependencies:
66
128
  - - "~>"
67
129
  - !ruby/object:Gem::Version
68
130
  version: '0.15'
69
- - !ruby/object:Gem::Dependency
70
- name: nokogiri
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.8'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.8'
83
131
  description: This library allow you to quickly copy latest semantic versions of specified
84
132
  gems to your clipboard.
85
133
  email: