Class: Bun::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/bun/runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*arguments) ⇒ Runner

Returns a new instance of Runner.



10
11
12
13
14
15
# File 'lib/bun/runner.rb', line 10

def initialize(*arguments)
  @arguments = arguments
  @gemfile = Gemfile.new

  parse_arguments
end

Class Method Details

.call(*arguments) ⇒ Object



6
7
8
# File 'lib/bun/runner.rb', line 6

def self.call(*arguments)
  new(*arguments).call
end

Instance Method Details

#callObject



17
18
19
20
21
22
# File 'lib/bun/runner.rb', line 17

def call
  command = parsed_arguments.shift
  gems = parsed_arguments.take_while { |argument| argument !~ /^-|^--/}

  run_command(command, gems)
end

#install(gems = [], opts: {}) ⇒ Object Also known as: add



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bun/runner.rb', line 33

def install(gems = [], opts: {})
  gemfile.init

  gems.each do |gem|
    name, version = extract_name_and_version_from_gem(gem)

    if print?
      version ||= VersionFetcher.new(name, arguments).fetch_latest_version
      puts "gem \"#{name}\", \"#{version_string(version)}\"" 
    else
      gemfile.verify_unique!(name)
      version ||= VersionFetcher.new(name, arguments).fetch_latest_version
      gemfile.add(name,
                  version_string(version),
                  arguments.group)
    end
  end

  bundle_install
end

#uninstall(gems, opts: {}) ⇒ Object Also known as: remove



24
25
26
27
28
29
30
# File 'lib/bun/runner.rb', line 24

def uninstall(gems, opts: {})
  gems.each do |gem|
    gemfile.remove(gem)
  end

  bundle_install
end