class RediPress::Configuration::Base
This class is the basis of a configuration
Public Class Methods
_name()
click to toggle source
Get the name of the configuration
Example:
>> configuration.class._name => "Test"
# File lib/redipress/configuration/base.rb, line 40 def _name @name end
_parameters()
click to toggle source
Get the array of parameters for the configuration
Example:
>> configuration.class._parameters => [#<RediPress::Configuration::Parameter:0x00000000000000>]
# File lib/redipress/configuration/base.rb, line 76 def _parameters @parameters end
name(name)
click to toggle source
Set a name for the configuration
Arguments:
name: (String)
Example:
>> class Test < RediPress::Configuration >> name "Test" >> end
# File lib/redipress/configuration/base.rb, line 30 def name(name) @name = name end
parameter(slug, &block)
click to toggle source
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
# 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
Public Instance Methods
name()
click to toggle source
Get the name of the configuration
Example:
>> configuration.name => "Test"
# File lib/redipress/configuration/base.rb, line 97 def name self.class._name end
parameters()
click to toggle source
Get the parameters for the configuration
Example:
>> configuration.parameters => [#<RediPress::Configuration::Parameter:0x00000000000000>]
# File lib/redipress/configuration/base.rb, line 107 def parameters self.class._parameters end
slug()
click to toggle source
Get the slug of the configuration
Example:
>> configuration.slug => "test"
# File lib/redipress/configuration/base.rb, line 87 def slug RediPress::Configuration.slug_for(self.class) end
to_s()
click to toggle source
Convert the class to a string
Example:
>> configuration.to_s => 'Test'
# File lib/redipress/configuration/base.rb, line 117 def to_s name end
Protected Instance Methods
compatible?(host, options)
click to toggle source
Check if the configuration is compatible with the server
Arguments:
host: (SSHKit::Host) options: (Hash)
Example:
>> configuration.compatible?(host, options) => true
# File lib/redipress/configuration/base.rb, line 133 def compatible?(host, options) true end
configure(host, options)
click to toggle source
Configure the server This method should return a hash with info to display (if needed) or nil
Arguments:
host: (SSHKit::Host) options: (Hash)
Example:
>> configuration.configure(host, options) => nil
Raises:
RediPress::ConfigurationNotImplemented: If this method is not overriden
# File lib/redipress/configuration/base.rb, line 151 def configure(host, options) raise RediPress::ConfigurationNotImplemented end
fail(error)
click to toggle source
Fail with an error
Arguments:
error: (String)
Example:
>> configuration.fail("Test error") => nil
Raises:
RediPress::ConfigurationFailed: When this method is called
# File lib/redipress/configuration/base.rb, line 167 def fail(error) raise RediPress::ConfigurationFailed.new(self, error) end