Class: RediPress::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/redipress/parameter.rb

Overview

This class holds all paramaters required by a configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slug) ⇒ Parameter

Setup an instance of the parameters class.

Arguments:

slug: (String|Symbol)

Example:

>> RediPress::Parameter.new(:username)
=> #<RediPress::Parameter:0x00000000000000>


20
21
22
23
24
25
# File 'lib/redipress/parameter.rb', line 20

def initialize(slug)
  @slug = slug
  @name = slug.to_s
  @required = true
  @type = :text
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/redipress/parameter.rb', line 9

def options
  @options
end

#required(required = nil) ⇒ Object (readonly)

Set the parameter to required

Available With Types:

:text

Arguments:

required: (Boolean)

Example:

>> parameter.required(true)
=> true


52
53
54
# File 'lib/redipress/parameter.rb', line 52

def required
  @required
end

#slugObject (readonly)

Returns the value of attribute slug.



9
10
11
# File 'lib/redipress/parameter.rb', line 9

def slug
  @slug
end

Instance Method Details

#default(default = nil) ⇒ Object

Set the default value

Available With types:

:text

Arguments:

default: (String)

Example:

>> parameter.default('rediwebhosting')
=> "rediwebhosting"


81
82
83
# File 'lib/redipress/parameter.rb', line 81

def default(default = nil)
  default.nil? ? @default : @default = default
end

#name(name = nil) ⇒ Object

Set the name of the parameter

Arguments:

name: (String)

Example:

>> parameter.name("Username")
=> "Username"


36
37
38
# File 'lib/redipress/parameter.rb', line 36

def name(name = nil)
  name.nil? ? @name : @name = name
end

#option(option) ⇒ Object

Add an option

Available With types:

:select
:multi_select

Arguments:

option: (String)

Example:

>> parameter.option('rediweb')
=> nil
>> parameter.option('rediwebhosting')
=> nil


116
117
118
119
120
# File 'lib/redipress/parameter.rb', line 116

def option(option)
  @options ||= []
  @options << option
  nil
end

#type(type = nil) ⇒ Object

Set the type of the parameter

Arguments:

type: (Symbol)

Example:

>> parameter.type(:text)
=> :text


65
66
67
# File 'lib/redipress/parameter.rb', line 65

def type(type = nil)
  type.nil? ? @type : @type = type
end

#validation(validation = nil) ⇒ Object

Set the validation regex

Available With types:

:text

Arguments:

validation: (Regex)

Example:

>> parameter.validation(/^[a-z]{4,}$/)
=> /^[a-z]{4,}$/


97
98
99
# File 'lib/redipress/parameter.rb', line 97

def validation(validation = nil)
  validation.nil? ? @validation : @validation = validation
end