Class: Binbundle::JewelryBox
- Inherits:
-
Array
- Object
- Array
- Binbundle::JewelryBox
- Defined in:
- lib/binbundle/jewelry_box.rb
Overview
String helpers
Instance Attribute Summary collapse
-
#include_version ⇒ Object
writeonly
Include version info in output.
-
#sudo ⇒ Object
writeonly
Include sudo.
-
#user_install ⇒ Object
writeonly
Include –user-install.
Instance Method Summary collapse
-
#bins_for_gem(gem) ⇒ Object
List binaries for a given gem name.
-
#gem_for_bin(bin) ⇒ String
Find a gem for a given binary name.
-
#init_from_contents(contents) ⇒ Object
Read and parse a Binfile for gems to install.
-
#initialize(include_version: true, sudo: false, user_install: false, contents: nil) ⇒ JewelryBox
constructor
Create a new JewelryBox object.
-
#to_s ⇒ String
Output a Binfile version of the JewelryBox.
Constructor Details
#initialize(include_version: true, sudo: false, user_install: false, contents: nil) ⇒ JewelryBox
Create a new JewelryBox object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/binbundle/jewelry_box.rb', line 24 def initialize(include_version: true, sudo: false, user_install: false, contents: nil) @include_version = include_version @sudo = sudo @user_install = user_install super() return unless contents init_from_contents(contents) end |
Instance Attribute Details
#include_version=(value) ⇒ Object (writeonly)
Include version info in output
7 8 9 |
# File 'lib/binbundle/jewelry_box.rb', line 7 def include_version=(value) @include_version = value end |
#sudo=(value) ⇒ Object (writeonly)
Include sudo
10 11 12 |
# File 'lib/binbundle/jewelry_box.rb', line 10 def sudo=(value) @sudo = value end |
#user_install=(value) ⇒ Object (writeonly)
Include –user-install
13 14 15 |
# File 'lib/binbundle/jewelry_box.rb', line 13 def user_install=(value) @user_install = value end |
Instance Method Details
#bins_for_gem(gem) ⇒ Object
List binaries for a given gem name
73 74 75 76 77 78 |
# File 'lib/binbundle/jewelry_box.rb', line 73 def bins_for_gem(gem) m = select { |g| g.gem == gem }.first return "Gem #{gem} not found" unless m m.bins ? m.bins.join(', ') : 'Missing info' end |
#gem_for_bin(bin) ⇒ String
Find a gem for a given binary name
61 62 63 64 65 66 |
# File 'lib/binbundle/jewelry_box.rb', line 61 def gem_for_bin(bin) m = select { |gem| gem.bins&.include?(bin) }.first return "Gem for #{bin} not found" unless m m.gem end |
#init_from_contents(contents) ⇒ Object
Read and parse a Binfile for gems to install
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/binbundle/jewelry_box.rb', line 41 def init_from_contents(contents) rx = /(?mix)(?:\#\sExecutables:\s(?<bins>[\S\s,]+?)\n)?(?:sudo\s)?gem\sinstall \s(?:--user-install\s)? (?<gem>\S+)(?:\s(?:-v|--version)\s'(?<version>[0-9.]+)')?/ contents.to_enum(:scan, rx).map { Regexp.last_match }.each do |m| g = Jewel.new(m['gem'], m['bins'], m['version']) g.include_version = @include_version g.sudo = @sudo g.user_install = @user_install push(g) end end |
#to_s ⇒ String
Output a Binfile version of the JewelryBox
85 86 87 |
# File 'lib/binbundle/jewelry_box.rb', line 85 def to_s map(&:to_s).join("\n") end |