Skip to content

Instantly share code, notes, and snippets.

@jdickey
Last active November 19, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdickey/2c8cfbd50268d24cf3bac6c3028ff453 to your computer and use it in GitHub Desktop.
Save jdickey/2c8cfbd50268d24cf3bac6c3028ff453 to your computer and use it in GitHub Desktop.
Want to be able to pull down all the Gems for a project so you can use 'bundle install --local'? Here's how
# ENV['TZ'] needs to be set for Time#ctime to work properly. Adjust as needed.
ENV['TZ'] = 'Asia/Singapore'
def deps_for(name)
version = Gem.latest_version_for(name)
dep = Gem::Dependency.new name, version
deps = Array(Gem.latest_spec_for(name.to_s).dependencies)
deps = [dep] + deps.reject { |gem| gem.type == :development }
deps.flatten.sort
end
def all_deps_for(list)
list.map { |gem| deps_for(gem) }.flatten.sort
end
# `list` must be in order as per client Gemfile; to get the values for `list`,
# run the following in a Pry session in the directory containing the Gemfile:
#
# list = File.open('Gemfile', 'r') do |f|
# f.lines.to_a }.
# map(&:strip).
# select { |s| s.start_with? 'gem ' }.
# map { |str| str[5..-1] }.
# map { |str| str.sub(/(\w)\'.*$/, '\1') }
# end
list = [
'rake',
'dry-monads',
'hanami',
'hanami-model',
'awesome_print',
'email_address',
'pg',
'sass',
'timerizer',
'strong_password',
'tachiban',
'shotgun',
'flog',
'flay',
'reek',
'rubocop',
'dotenv',
'pry-byebug',
'pry-doc',
'minitest',
'minitest-hooks',
'minitest-reporters',
'minitest-tagz',
'database_cleaner',
'hanami-fabrication',
'ffaker',
'capybara',
'selenium-webdriver',
'simplecov',
'puma'
]
puts Time.now.localtime.to_s;
r = Gem::Resolver.new(all_deps_for(list)).resolve;
puts Time.now.localtime.to_s;
gem_strings = r.map { |req| req.full_name.sub(/\-(\d)/, ':\1') };
full_list = gem_strings.join(' ')
# => "public_suffix:3.0.3 addressable:2.5.2 ansi:1.5.0 awesome_print:1.8.0 bcrypt:3.1.12 builder:3.2.3 bundler:1.17.1 " \
# "byebug:10.0.2 mini_portile2:2.3.0 nokogiri:1.8.5 xpath:3.2.0 regexp_parser:1.3.0 rack:2.0.6 rack-test:1.1.0 " \
# "mini_mime:1.0.1 capybara:3.11.1 ffi:1.9.25 childprocess:0.9.0 thread_safe:0.3.6 ice_nine:0.11.2 " \
# "descendants_tracker:0.0.4 axiom-types:0.1.1 coercible:1.0.0 equalizer:0.0.11 virtus:1.0.5 " \
# "codeclimate-engine-rb:0.4.1 concurrent-ruby:1.1.3 database_cleaner:1.7.0 docile:1.3.1 dotenv:2.5.0 dry-core:0.4.7 " \
# dry-equalizer:0.2.1 dry-monads:1.1.0 inflecto:0.0.2 dry-configurable:0.7.0 dry-container:0.6.0 dry-logic:0.4.2 " \
# "dry-types:0.11.1 netaddr:2.0.3 unf_ext:0.0.7.5 unf:0.1.4 simpleidn:0.1.1 email_address:0.1.11 erubis:2.7.0 " \
# "fabrication:2.20.1 ffaker:2.10.0 path_expander:1.0.3 sexp_processor:4.11.0 ruby_parser:3.11.0 flay:2.12.0 " \
# "flog:4.6.2 transproc:1.0.2 hanami-utils:1.3.0 hanami-cli:0.3.0 tilt:2.0.8 hanami-helpers:1.3.0 hanami-assets:1.3.0 " \
# "mail:2.7.1 hanami-mailer:1.3.0 hanami-view:1.3.0 hanami-controller:1.3.0 url_mount:0.2.1 http_router:0.11.2 " \
# "hanami-router:1.3.0 dry-validation:0.11.0 hanami-validations:1.3.0 hanami:1.3.0 hanami-fabrication:0.1.0 " \
# "dry-struct:0.3.1 rom-mapper:0.5.1 dry-initializer:1.4.1 rom:3.3.3 rom-repository:1.4.0 sequel:4.49.0 rom-sql:1.3.5 " \
# "hanami-model:1.3.0 jaro_winkler:1.5.1 json:2.1.0 kwalify:0.7.2 minitest:5.11.3 minitest-hooks:1.5.0 " \
# "ruby-progressbar:1.10.0 minitest-reporters:1.3.5 minitest-tagz:1.6.0 parallel:1.12.1 ast:2.4.0 parser:2.5.3.0 " \
# "pg:1.1.3 powerpack:0.1.2 method_source:0.9.2 coderay:1.1.2 pry:0.12.2 pry-byebug:3.6.0 yard:0.9.16 pry-doc:0.13.5 " \
# "puma:3.12.0 rainbow:3.0.0 rake:12.3.1 reek:5.2.0 unicode-display_width:1.4.0 rubocop:0.60.0 rubyzip:1.2.2 " \
# "rb-inotify:0.9.10 rb-fsevent:0.10.3 sass-listen:4.0.0 sass:3.7.2 selenium-webdriver:3.141.0 shotgun:0.9.2 " \
# "simplecov-html:0.10.2 simplecov:0.16.1 strong_password:0.0.6 tachiban:0.6.0 timerizer:0.3.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment