Class: RediPress::Configuration::Base
- Inherits:
-
Object
- Object
- RediPress::Configuration::Base
- Includes:
- SSHKit::DSL
- Defined in:
- lib/redipress/configuration/base.rb
Overview
This class is the basis of a configuration
Class Method Summary collapse
-
._name ⇒ Object
Get the name of the configuration.
-
._parameters ⇒ Object
Get the array of parameters for the configuration.
-
.name(name) ⇒ Object
Set a name for the configuration.
-
.parameter(slug, &block) ⇒ Object
Add a parameter to the configuration.
Instance Method Summary collapse
-
#name ⇒ Object
Get the name of the configuration.
-
#parameters ⇒ Object
Get the parameters for the configuration.
-
#slug ⇒ Object
Get the slug of the configuration.
-
#to_s ⇒ Object
Convert the class to a string.
Class Method Details
._name ⇒ Object
Get the name of the configuration
Example:
>> configuration.class._name
=> "Test"
40 41 42 |
# File 'lib/redipress/configuration/base.rb', line 40 def _name @name end |
._parameters ⇒ Object
Get the array of parameters for the configuration
Example:
>> configuration.class._parameters
=> [#<RediPress::Configuration::Parameter:0x00000000000000>]
76 77 78 |
# File 'lib/redipress/configuration/base.rb', line 76 def _parameters @parameters end |
.name(name) ⇒ Object
Set a name for the configuration
Arguments:
name: (String)
Example:
>> class Test < RediPress::Configuration
>> name "Test"
>> end
30 31 32 |
# File 'lib/redipress/configuration/base.rb', line 30 def name(name) @name = name end |
.parameter(slug, &block) ⇒ Object
Add a parameter to the configuration
Arguments:
slug: (String)
Example:
>> class Test < RediPress::Configuration
>> parameter :username do
>> name 'Username'
>> validation /^[a-z]{4,}$/
>> end
>> end
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/redipress/configuration/base.rb', line 57 def parameter(slug, &block) return nil if slug.nil? @parameters ||= [] return @parameters if @parameters.map { |p| p.slug }.include?(slug) parameter = RediPress::Parameter.new(slug) parameter.instance_eval(&block) if block_given? @parameters << parameter end |
Instance Method Details
#name ⇒ Object
Get the name of the configuration
Example:
>> configuration.name
=> "Test"
97 98 99 |
# File 'lib/redipress/configuration/base.rb', line 97 def name self.class._name end |
#parameters ⇒ Object
Get the parameters for the configuration
Example:
>> configuration.parameters
=> [#<RediPress::Configuration::Parameter:0x00000000000000>]
107 108 109 |
# File 'lib/redipress/configuration/base.rb', line 107 def parameters self.class._parameters end |
#slug ⇒ Object
Get the slug of the configuration
Example:
>> configuration.slug
=> "test"
87 88 89 |
# File 'lib/redipress/configuration/base.rb', line 87 def slug RediPress::Configuration.slug_for(self.class) end |
#to_s ⇒ Object
Convert the class to a string
Example:
>> configuration.to_s
=> 'Test'
117 118 119 |
# File 'lib/redipress/configuration/base.rb', line 117 def to_s name end |