Module: Grundler::Commands::Common
Instance Method Summary collapse
- #initialize(cli) ⇒ Object
- #install(version) ⇒ Object
- #latest_version(package_name) ⇒ Object
- #module?(version) ⇒ Boolean
- #no_such_package ⇒ Object
Instance Method Details
#initialize(cli) ⇒ Object
7 8 9 |
# File 'lib/grundler/commands/common.rb', line 7 def initialize(cli) @cli = cli end |
#install(version) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/grundler/commands/common.rb', line 21 def install(version) return no_such_package if version == "Not found" if module?(version) GoodMode.new(@cli, version).write else CrapMode.new(@cli, version).write end version end |
#latest_version(package_name) ⇒ Object
15 16 17 18 19 |
# File 'lib/grundler/commands/common.rb', line 15 def latest_version(package_name) = JSON.parse(HTTP.get("https://registry.npmjs.org/#{package_name}").to_s) latest_version_number = .dig("dist-tags", "latest") ["error"] || .dig("versions", latest_version_number) end |
#module?(version) ⇒ Boolean
11 12 13 |
# File 'lib/grundler/commands/common.rb', line 11 def module?(version) !version["module"].nil? || version["type"] == "module" end |
#no_such_package ⇒ Object
33 34 35 |
# File 'lib/grundler/commands/common.rb', line 33 def no_such_package puts "That package could not be found in the npm repository!" end |