Class: ConfCtl::ModuleOptions::Option

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nixos_opt) ⇒ Option

Returns a new instance of Option.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/confctl/module_options.rb', line 8

def initialize(nixos_opt)
  @name = nixos_opt['name']
  @description = nixos_opt['description'] || 'This option has no description.'
  @type = nixos_opt['type']
  @default = extract_expression(nixos_opt['default'])
  @example = extract_expression(nixos_opt['example'])
  @declarations = nixos_opt['declarations'].map do |v|
    raise "unable to place module '#{v}'" unless %r{/confctl/([^$]+)} =~ v

    "<confctl/#{::Regexp.last_match(1)}>"
  end
end

Instance Attribute Details

#declarationsObject (readonly)

Returns the value of attribute declarations.



6
7
8
# File 'lib/confctl/module_options.rb', line 6

def declarations
  @declarations
end

#defaultObject (readonly)

Returns the value of attribute default.



6
7
8
# File 'lib/confctl/module_options.rb', line 6

def default
  @default
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/confctl/module_options.rb', line 6

def description
  @description
end

#exampleObject (readonly)

Returns the value of attribute example.



6
7
8
# File 'lib/confctl/module_options.rb', line 6

def example
  @example
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/confctl/module_options.rb', line 6

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/confctl/module_options.rb', line 6

def type
  @type
end

Instance Method Details

#md_descriptionObject



21
22
23
24
25
26
27
# File 'lib/confctl/module_options.rb', line 21

def md_description
  tagless = description
            .gsub(%r{<literal>([^<]+)</literal>}, '`\1`')
            .gsub(%r{<option>([^<]+)</option>}, '`\1`')

  CGI.unescapeHTML(tagless)
end

#nix_defaultObject



29
30
31
# File 'lib/confctl/module_options.rb', line 29

def nix_default
  nixify(default)
end

#nix_exampleObject



33
34
35
# File 'lib/confctl/module_options.rb', line 33

def nix_example
  example && nixify(example)
end