Module: Pione::Util::Misc

Included in:
Pione::Util
Defined in:
lib/pione/util/misc.rb

Instance Method Summary collapse

Instance Method Details

#error?(option = {}, &b) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pione/util/misc.rb', line 16

def error?(option={}, &b)
  sec = option[:timeout]
  begin
    timeout(sec) do
      b.call
      false
    end
  rescue Object => e
    true
  end
end

#hostnameString

Returns the hostname of the machine.

Returns:

  • (String)

    hostname



31
32
33
# File 'lib/pione/util/misc.rb', line 31

def hostname
  Socket.gethostname
end

#ignore_exception(*exceptions) { ... } ⇒ void

This method returns an undefined value.

Ignores all exceptions of the block execution.

Yields:

  • [] target block



8
9
10
11
12
13
14
# File 'lib/pione/util/misc.rb', line 8

def ignore_exception(*exceptions, &b)
  exceptions = [Exception] if exceptions.empty?
  b.call
rescue *exceptions => e
  Log::Debug.ignored_exception(e)
  return false
end

#parse_features(textual_features) ⇒ Object



35
36
37
38
39
# File 'lib/pione/util/misc.rb', line 35

def parse_features(textual_features)
  stree = Lang::DocumentParser.new.expr.parse(textual_features)
  opt = {package_name: "*Feature*", filename: "*Feature*"}
  Lang::DocumentTransformer.new.apply(stree, opt)
end

#parse_param_set(textual_param_set) ⇒ Object



41
42
43
44
45
# File 'lib/pione/util/misc.rb', line 41

def parse_param_set(textual_param_set)
  stree = Lang::DocumentParser.new.parameter_set.parse(textual_param_set)
  opt = {package_name: "*ParamSet*", filename: "*ParamSet*"}
  params = Lang::DocumentTransformer.new.apply(stree, opt)
end