Class: Bwrap::Args::Args

Inherits:
Hash
  • Object
show all
Defined in:
lib/bwrap/args/args.rb

Overview

Used as container for arguments constructed via Construct.

Where `Hash` defaults to nil as default argument, Args defaults to `Array`.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Args

Creates new instance of a hash for storing arguments.

Where `Hash` defaults to nil as default argument, Bwrap::Args::Args defaults to `[]`.

See Also:

  • Hash#initialize


22
23
24
25
26
27
28
# File 'lib/bwrap/args/args.rb', line 22

def initialize(*args)
  if args.empty? and !block_given?
    super(*args) { [] }
  else
    super(*args)
  end
end

Instance Method Details

#add(type, *data) ⇒ Object

Adds given data to array identified by given type.

Following types are meant to be used, though everything is accepted:

  • :mount

  • (and many others, they are not documented here)

Parameters:

  • type (Symbol)

    Type of the argument

Returns:

  • self



38
39
40
41
42
43
44
45
46
# File 'lib/bwrap/args/args.rb', line 38

def add(type, *data)
  if data.respond_to? :each
    self[type] += data.flatten
  else
    self[type] << data
  end

  self
end

#add_uniq(type, *data) ⇒ Object

Adds ugiven data to array identified by given type if they have not been already added.

Following types are meant to be used, though everything is accepted:

  • :mount

  • (and many others, they are not documented here)

Parameters:

  • type (Symbol)

    Type of the argument

Returns:

  • self



57
58
59
60
61
62
63
64
65
# File 'lib/bwrap/args/args.rb', line 57

def add_uniq(type, *data)
  if data.respond_to? :each
    self[type] |= data
  else
    self[type] << data unless include? data
  end

  self
end

#ro_bind(type, path) ⇒ Object

Adds a read-only bind to bind given path from host to same path inside sandbox.

TODO: doc for params

See Also:

  • argument `--ro-bind`.


72
73
74
# File 'lib/bwrap/args/args.rb', line 72

def ro_bind(type, path)
  add(type, %W{ --ro-bind #{path} #{path} })
end