Class: Setup::Installer::Shebang

Inherits:
Object
  • Object
show all
Defined in:
lib/setup/installer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, args = []) ⇒ Shebang

Returns a new instance of Shebang.



347
348
349
350
# File 'lib/setup/installer.rb', line 347

def initialize(cmd, args = [])
  @cmd = cmd
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



353
354
355
# File 'lib/setup/installer.rb', line 353

def args
  @args
end

#cmdObject (readonly)

Returns the value of attribute cmd.



352
353
354
# File 'lib/setup/installer.rb', line 352

def cmd
  @cmd
end

Class Method Details

.load(path) ⇒ Object



333
334
335
336
337
338
339
340
# File 'lib/setup/installer.rb', line 333

def Shebang.load(path)
  line = nil
  File.open(path) {|f|
    line = f.gets
  }
  return nil unless /\A#!/ =~ line
  parse(line)
end

.parse(line) ⇒ Object



342
343
344
345
# File 'lib/setup/installer.rb', line 342

def Shebang.parse(line)
  cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ')
  new(cmd, args)
end

Instance Method Details

#to_sObject



355
356
357
# File 'lib/setup/installer.rb', line 355

def to_s
  "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}")
end