Class: SysCmd::Shell

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Shell

Returns a new instance of Shell.



437
438
439
# File 'lib/sys_cmd.rb', line 437

def initialize(options = {})
  @type = SysCmd.os_type(options)
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



441
442
443
# File 'lib/sys_cmd.rb', line 441

def type
  @type
end

Instance Method Details

#applicable?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/sys_cmd.rb', line 474

def applicable?(options = {})
  applicable = true
  only_on = Array(options[:only_on])
  unless only_on.empty?
    applicable = false unless only_on.include?(@type)
  end
  except_on = Array(options[:except_on])
  unless except_on.empty?
    applicable = false if except_on.include?(@type)
  end
  applicable
end

#escape(text) ⇒ Object



443
444
445
# File 'lib/sys_cmd.rb', line 443

def escape(text)
  SysCmd.escape(text, os: @type)
end

#escape_filename(name) ⇒ Object



455
456
457
458
459
460
# File 'lib/sys_cmd.rb', line 455

def escape_filename(name)
  if @type == :windows
    name = name.gsub('/', '\\')
  end
  escape name
end

#escape_value(value) ⇒ Object



462
463
464
# File 'lib/sys_cmd.rb', line 462

def escape_value(value)
  escape value.to_s
end

#here_doc(data, options = {}) ⇒ Object



487
488
489
# File 'lib/sys_cmd.rb', line 487

def here_doc(data, options = {})
  SysCmd.here_doc(data, options.merge(os: @type))
end

#line_separatorObject



466
467
468
# File 'lib/sys_cmd.rb', line 466

def line_separator
  SysCmd.line_separator(os: @type)
end

#option_switchObject



470
471
472
# File 'lib/sys_cmd.rb', line 470

def option_switch
  SysCmd.option_switch(os: @type)
end

#requires_escaping?(text) ⇒ Boolean

Returns:

  • (Boolean)


447
448
449
# File 'lib/sys_cmd.rb', line 447

def requires_escaping?(text)
  SysCmd.requires_escaping?(text, os: @type)
end

#split(text) ⇒ Object



451
452
453
# File 'lib/sys_cmd.rb', line 451

def split(text)
  SysCmd.split(text, os: @type)
end