Class: Diecut::PluginDescription::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/diecut/plugin-description/option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Option

Returns a new instance of Option.



4
5
6
7
# File 'lib/diecut/plugin-description/option.rb', line 4

def initialize(name)
  @name = name
  @default_value = NO_VALUE
end

Instance Attribute Details

#context_pathObject (readonly)

Returns the value of attribute context_path.



8
9
10
# File 'lib/diecut/plugin-description/option.rb', line 8

def context_path
  @context_path
end

#default_valueObject (readonly)

Returns the value of attribute default_value.



8
9
10
# File 'lib/diecut/plugin-description/option.rb', line 8

def default_value
  @default_value
end

#description(desc = NO_VALUE) ⇒ Object (readonly)

A description for the option in the user interface.

Parameters:

  • desc (String) (defaults to: NO_VALUE)

    The description itself



21
22
23
# File 'lib/diecut/plugin-description/option.rb', line 21

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/diecut/plugin-description/option.rb', line 8

def name
  @name
end

Instance Method Details

#default(value) ⇒ Object

Gives the option a default value (and therefore makes it optional for the user to provide)

Parameters:

  • value

    The default value



58
59
60
# File 'lib/diecut/plugin-description/option.rb', line 58

def default(value)
  @default_value = value
end

#goes_to(*context_path) ⇒ Object

Defines the templating context path this value should be copied to.

Examples:

Three equivalent calls

option.goes_to("deeply.nested.field")
option.goes_to(%w{deeply nested field})
option.goes_to("deeply", "nested", "field")

Parameters:

  • context_path (Array, String)

    The path into the context to set from this option’s value.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/diecut/plugin-description/option.rb', line 37

def goes_to(*context_path)
  if context_path.length == 1
    context_path =
      case context_path.first
      when Array
        context_path.first
      when /.+\..+/ # has an embedded .
        context_path.first.split('.')
      else
        context_path
      end
  end

  @context_path = context_path
end

#has_context_path?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/diecut/plugin-description/option.rb', line 14

def has_context_path?
  !context_path.nil?
end

#has_default?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/diecut/plugin-description/option.rb', line 10

def has_default?
  default_value != NO_VALUE
end