Class: RQR::Installer::Shebang

Inherits:
Object
  • Object
show all
Defined in:
lib/rqr.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.



1325
1326
1327
1328
# File 'lib/rqr.rb', line 1325

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



1331
1332
1333
# File 'lib/rqr.rb', line 1331

def args
  @args
end

#cmdObject (readonly)

Returns the value of attribute cmd.



1330
1331
1332
# File 'lib/rqr.rb', line 1330

def cmd
  @cmd
end

Class Method Details

.load(path) ⇒ Object



1311
1312
1313
1314
1315
1316
1317
1318
# File 'lib/rqr.rb', line 1311

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

.parse(line) ⇒ Object



1320
1321
1322
1323
# File 'lib/rqr.rb', line 1320

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

Instance Method Details

#to_sObject



1333
1334
1335
# File 'lib/rqr.rb', line 1333

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