Class: Ruber::PluginSpecificationReader::Option

Inherits:
OpenStruct show all
Defined in:
lib/ruber/plugin_specification_reader.rb

Overview

Class used to contain the information about an option. It behaves as a regular OpenStruct, except for the default and the to_os methods.

Instance Method Summary (collapse)

Instance Method Details

- (Object) compute_default(bind = TOPLEVEL_BINDING)



55
56
57
58
59
60
61
62
63
64
# File 'lib/ruber/plugin_specification_reader.rb', line 55

def compute_default bind = TOPLEVEL_BINDING
  val = super()
  if val.is_a? String and self.eval_default
    begin eval val, bind
    rescue NoMethodError, SyntaxError, NameError, ArgumentError
      val
    end
  else val
  end
end

- (Object) default(bind = TOPLEVEL_BINDING)

Returns the default value of the option, computed basing on the value stored in the default entry in the option description in the PDF. In particular:

  • if the value is not a string, it is returned unchanged
  • if the value is a string and the eval_default attribute has been set to false in the PDF, it is returned unchanged
  • if it is a string, it is evaluated in the bindings bind (using eval) and the corresponding value is returned. If eval raises SyntaxError, NoMethodError or NameError then the string is returned unchanged (of course, the exception isn’t propagated).


44
45
46
47
48
49
50
51
52
53
# File 'lib/ruber/plugin_specification_reader.rb', line 44

def default bind = TOPLEVEL_BINDING
  val = super()
  if val.is_a? String and self.eval_default
    begin eval val, bind
    rescue NoMethodError, SyntaxError, NameError, ArgumentError
      val
    end
  else val
  end
end

- (Object) to_os(bind = TOPLEVEL_BINDING)

Returns an OpenStruct with the same contents as self, except for the default attribute, which is obtained using the default method using the bindings bind.



70
71
72
73
74
# File 'lib/ruber/plugin_specification_reader.rb', line 70

def to_os bind = TOPLEVEL_BINDING
  hash = to_h
  hash[:default] = default bind
  OpenStruct.new hash
end