bun 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fb12f5eb445c643446202ce117fb8a3938210de2d06be473bc934cd65dcc7938
4
+ data.tar.gz: d04e66d00b02d6a16430cc20a06b14a4060b79a69f8ce0141252c3866d3b2fec
5
+ SHA512:
6
+ metadata.gz: 2c77d30d9a4bae86ff3291db8ac59e5ec4eeb44888a7c04883fd8ea95652e7b8df1c19a87f065627adf0e870853c4b406e99b18a9ad1800017c7af38ab4463e4
7
+ data.tar.gz: 1ca70952a165a225a8e447d5b4b71c6fd49d7d76a5189bac17f0677940356114ad243dfc1d1f21bd83fda98f2be4cb2aaa55f7fdacc60178e2bb3824d47a6a00
@@ -0,0 +1,2 @@
1
+ tmp
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bun (1.0.0)
5
+ paint (~> 2.0.1)
6
+ tty-spinner (~> 0.8.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ method_source (0.9.0)
14
+ paint (2.0.1)
15
+ pry (0.11.3)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.5.0)
19
+ rspec (3.7.0)
20
+ rspec-core (~> 3.7.0)
21
+ rspec-expectations (~> 3.7.0)
22
+ rspec-mocks (~> 3.7.0)
23
+ rspec-core (3.7.1)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-expectations (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-mocks (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-support (3.7.1)
32
+ tty-cursor (0.5.0)
33
+ tty-spinner (0.8.0)
34
+ tty-cursor (>= 0.5.0)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bun!
41
+ bundler (~> 1.16)
42
+ pry (~> 0.11.3)
43
+ rake (~> 10.0)
44
+ rspec (~> 3.7.0)
45
+
46
+ BUNDLED WITH
47
+ 1.16.1
data/bin/bun ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/bun"
4
+
5
+ Bun::Runner.call(*ARGV)
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "bun/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bun"
7
+ spec.version = Bun::VERSION
8
+ spec.authors = ["Hrvoje Šimić"]
9
+ spec.email = ["shime@twobucks.co"]
10
+
11
+ spec.summary = %q{CLI tool to install and remove gems from Gemfile with ease.}
12
+ spec.homepage = "https://github.com/shime/bun"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "tty-spinner", "~> 0.8.0"
23
+ spec.add_runtime_dependency "paint", "~> 2.0.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.7.0"
28
+ spec.add_development_dependency "pry", "~> 0.11.3"
29
+ end
@@ -0,0 +1,10 @@
1
+ require_relative "bun/errors"
2
+ require_relative "bun/messages"
3
+ require_relative "bun/runner"
4
+ require_relative "bun/version"
5
+ require_relative "bun/arguments"
6
+ require_relative "bun/gemfile"
7
+ require_relative "bun/version_fetcher"
8
+
9
+ module Bun
10
+ end
@@ -0,0 +1,66 @@
1
+ require "optparse"
2
+
3
+ class Arguments
4
+ def initialize(arguments)
5
+ @arguments = arguments
6
+ end
7
+
8
+ attr_accessor :optimistic, :strict, :group, :skip_install, :print
9
+
10
+ alias :strict? :strict
11
+ alias :optimistic? :optimistic
12
+ alias :skip_install? :skip_install
13
+ alias :print? :print
14
+
15
+ def empty?
16
+ @arguments.empty?
17
+ end
18
+
19
+ def parse
20
+ opt_parser = OptionParser.new do |opts|
21
+ opts.banner = Bun::Messages::USAGE
22
+
23
+ opts.on("-P", "--print", "# Just print the gem name and version and exit.") do
24
+ self.print = true
25
+ end
26
+
27
+ opts.on("-o", "--optimistic", "# Use optimistic version range >= instead of ~>.") do
28
+ self.optimistic = true
29
+ end
30
+
31
+ opts.on("-S", "--strict", "# Use strict version instead of ~> range.") do
32
+ self.strict = true
33
+ end
34
+
35
+ opts.on("-d", "--development", "# Add gem to development group.") do
36
+ self.group = :development
37
+ end
38
+
39
+ opts.on("-t", "--test", "# Add gem to test group.") do
40
+ self.group = :test
41
+ end
42
+
43
+ opts.on("-s", "--skip-install", "# Skip the install step.") do
44
+ self.skip_install = true
45
+ end
46
+
47
+ opts.on_tail("-h", "--help", "# Print these usage instructions.") do
48
+ puts opts
49
+ end
50
+
51
+ opts.on("-v", "--version", "# Show current Bun version.") do
52
+ puts Bun::VERSION
53
+ end
54
+ end
55
+
56
+ begin
57
+ opt_parser.parse(arguments)
58
+ rescue OptionParser::InvalidOption
59
+ puts opt_parser
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ attr :arguments
66
+ end
@@ -0,0 +1,7 @@
1
+ module Bun
2
+ module Errors
3
+ class DuplicateGemError < StandardError; end
4
+ class GemNotFoundError < StandardError; end
5
+ end
6
+ end
7
+
@@ -0,0 +1,60 @@
1
+ require "tempfile"
2
+
3
+ module Bun
4
+ class Gemfile
5
+ PATH = "Gemfile"
6
+
7
+ def init
8
+ return if File.file?(PATH)
9
+
10
+ File.write(PATH, %Q{source "https://rubygems.org"\n\n}, mode: "w")
11
+ end
12
+
13
+ def add(gem, version_string, group)
14
+ file = File.read(PATH)
15
+
16
+ if file =~ /gem "#{gem}"/
17
+ raise ::Bun::Errors::DuplicateGemError.new("Aborting. Gem already present in the Gemfile: #{gem}")
18
+ end
19
+
20
+ if file =~ /group :#{group} do/
21
+ # appends gem to the end of the group block
22
+ file.gsub!(%r{(group :#{group} do\n.*?)(end)}m,
23
+ "\\1 gem \"#{gem}\", \"#{version_string}\"\n\\2")
24
+ File.write(PATH, file, mode: "w")
25
+ else
26
+ with_group(group) do
27
+ File.write(PATH, "#{" " if group }gem \"#{gem}\", \"#{version_string}\"\n", mode: "a")
28
+ end
29
+ end
30
+ end
31
+
32
+ def with_group(group)
33
+ File.write(PATH, "\ngroup :#{group} do\n", mode: "a") if group
34
+ yield
35
+ File.write(PATH, "end\n", mode: "a") if group
36
+ end
37
+
38
+ def remove(gem)
39
+ output = Tempfile.new(PATH)
40
+
41
+ File.foreach(PATH) do |line|
42
+ if line !~ /gem "#{gem}"/
43
+ output.write(line)
44
+ end
45
+ end
46
+
47
+ FileUtils.mv(output.path, PATH)
48
+ end
49
+
50
+ def verify_unique!(gem)
51
+ if File.read(PATH) =~ /gem "#{gem}"/
52
+ raise ::Bun::Errors::DuplicateGemError.new("Aborting. Gem already present in the Gemfile: #{gem}")
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ attr :runner
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ module Bun
2
+ module Messages
3
+ USAGE = <<-USAGE.gsub /^( +)(\w+| -)/, '\2'
4
+
5
+ Bun
6
+
7
+ Bundler's little helper. A missing CLI tool to install and remove gems from Gemfile with ease.
8
+
9
+ Usage: bun <COMMAND> [GEMS] [OPTIONS]
10
+
11
+ Commands:
12
+
13
+ install - adds gems to Gemfile, alias: i
14
+ uninstall - removes gems from Gemfile, alias: rm, d
15
+
16
+ Example:
17
+
18
+ bun install rspec --test
19
+
20
+ Options:
21
+
22
+ USAGE
23
+ end
24
+ end
@@ -0,0 +1,100 @@
1
+ require "bundler"
2
+ require "paint"
3
+
4
+ module Bun
5
+ class Runner
6
+ def self.call(*arguments)
7
+ new(*arguments).call
8
+ end
9
+
10
+ def initialize(*arguments)
11
+ @arguments = arguments
12
+ end
13
+
14
+ def call
15
+ parse_arguments
16
+
17
+ command = parsed_arguments.shift
18
+ gems = parsed_arguments.take_while { |argument| argument !~ /^-|^--/}
19
+
20
+ self.gemfile = Gemfile.new
21
+
22
+ run_command(command, gems)
23
+ end
24
+
25
+ private
26
+
27
+ attr_accessor :arguments
28
+ attr_accessor :parsed_arguments
29
+ attr_accessor :gemfile
30
+
31
+ def run_command(command, gems)
32
+ with_exception_handling do
33
+ install if arguments.empty?
34
+
35
+ case command
36
+ when /^install$|^i$/
37
+ install(gems)
38
+ when /^uninstall$|^rm$|^d$/
39
+ uninstall(gems)
40
+ end
41
+ end
42
+ end
43
+
44
+ def with_exception_handling
45
+ yield
46
+ rescue Errors::DuplicateGemError, Errors::GemNotFoundError => ex
47
+ puts Paint[ex.message, :red, :bright]
48
+ exit(1)
49
+ end
50
+
51
+ def uninstall(gems)
52
+ gems.each do |gem|
53
+ gemfile.remove(gem)
54
+ end
55
+
56
+ bundle_install
57
+ end
58
+
59
+ def install(gems = [])
60
+ gemfile.init
61
+
62
+ gems.each do |gem|
63
+ if arguments.print?
64
+ version = version_string(VersionFetcher.new(gem, arguments).fetch_latest_version)
65
+ puts "gem \"#{gem}\", \"#{version}\""
66
+ else
67
+ gemfile.verify_unique!(gem)
68
+ gemfile.add(gem,
69
+ version_string(VersionFetcher.new(gem, arguments).fetch_latest_version),
70
+ arguments.group)
71
+ end
72
+ end
73
+
74
+ bundle_install
75
+ end
76
+
77
+ def version_string(version)
78
+ if arguments.optimistic?
79
+ ">= #{version}"
80
+ elsif arguments.strict?
81
+ "#{version}"
82
+ else
83
+ "~> #{version}"
84
+ end
85
+ end
86
+
87
+ def bundle_install
88
+ return if arguments.skip_install? || arguments.print?
89
+
90
+ Bundler.with_clean_env do
91
+ system("bundle install")
92
+ end
93
+ end
94
+
95
+ def parse_arguments
96
+ self.arguments = Arguments.new(arguments)
97
+ self.parsed_arguments = arguments.parse
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ module Bun
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,46 @@
1
+ require "json"
2
+ require "open-uri"
3
+ require "tty/spinner"
4
+
5
+ class VersionFetcher
6
+ RUBYGEMS_SEARCH_URL = "https://rubygems.org/api/v1/search.json"
7
+ def initialize(gem, arguments)
8
+ @gem = gem
9
+ @arguments = arguments
10
+ end
11
+
12
+ def fetch_latest_version
13
+ version = nil
14
+
15
+ with_optional_spinner do
16
+ response = open("#{RUBYGEMS_SEARCH_URL}?query=#{gem}").read
17
+ json_response = JSON.parse(response)
18
+ latest_gem_attributes = json_response.
19
+ find {|attributes| attributes["name"] == gem }
20
+
21
+ unless latest_gem_attributes
22
+ raise ::Bun::Errors::GemNotFoundError.new("Aborting. Gem not found: #{gem}")
23
+ end
24
+
25
+ version = latest_gem_attributes["version"]
26
+ end
27
+
28
+ version
29
+ end
30
+
31
+ def with_optional_spinner
32
+ if arguments.print?
33
+ yield
34
+ else
35
+ spinner = TTY::Spinner.new("[:spinner] Finding latest gem version for \"#{gem}\"...")
36
+ spinner.auto_spin
37
+ yield
38
+ spinner.stop("Done!")
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ attr :gem
45
+ attr :arguments
46
+ end
data/license ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Hrvoje Simic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -0,0 +1,76 @@
1
+ # Bun
2
+
3
+ Bundler's little helper. A missing CLI tool to install and remove gems from Gemfile with ease.
4
+
5
+
6
+ ![](https://twobucks.co/assets/bun-example-min.gif)
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ $ gem install bun
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Install RSpec:
17
+
18
+ ```
19
+ $ bun install rspec
20
+ ```
21
+
22
+ Install Pry in development group:
23
+
24
+ ```
25
+ $ bun install pry --development
26
+ ```
27
+
28
+ Install RSpec and Cucumber in test group:
29
+
30
+ ```
31
+ $ bun install rspec cucumber --test
32
+ ```
33
+
34
+ Uninstall RSpec:
35
+
36
+ ```
37
+ $ bun uninstall rspec
38
+ ```
39
+
40
+ Uninstall Rails:
41
+
42
+ ```
43
+ $ bun rm rails
44
+ ```
45
+
46
+ Install Cuba with strict version range:
47
+
48
+ ```
49
+ $ bun i cuba --strict
50
+ ```
51
+
52
+ Add Sequel to the Gemfile and exit without installing it:
53
+
54
+ ```
55
+ $ bun i sequel --skip-install
56
+ ```
57
+
58
+ Just print the gem name with the latest version found and exit:
59
+
60
+ ```
61
+ $ bun i sequel --print
62
+ ```
63
+
64
+ More info:
65
+
66
+ ```
67
+ $ bun --help
68
+ ```
69
+
70
+ ## Prior art
71
+
72
+ * [Gemrat](https://github.com/drurly/gemrat)
73
+
74
+ ## License
75
+
76
+ [MIT](/license)
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bun
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hrvoje Šimić
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-spinner
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: paint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.7.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.7.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.11.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.11.3
97
+ description:
98
+ email:
99
+ - shime@twobucks.co
100
+ executables:
101
+ - bun
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - bin/bun
109
+ - bun.gemspec
110
+ - lib/bun.rb
111
+ - lib/bun/arguments.rb
112
+ - lib/bun/errors.rb
113
+ - lib/bun/gemfile.rb
114
+ - lib/bun/messages.rb
115
+ - lib/bun/runner.rb
116
+ - lib/bun/version.rb
117
+ - lib/bun/version_fetcher.rb
118
+ - license
119
+ - readme.md
120
+ homepage: https://github.com/shime/bun
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.7.3
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: CLI tool to install and remove gems from Gemfile with ease.
144
+ test_files: []