Module: RediPress::Configuration
- Defined in:
- lib/redipress/configuration.rb,
lib/redipress/configuration/base.rb
Overview
This module contains all configurations
Defined Under Namespace
Classes: Base
Class Method Summary collapse
-
.all ⇒ Object
Returns a Hash of all available configurations.
-
.available?(*slugs) ⇒ Boolean
Check that the specified configurations are available.
-
.class_for(slug) ⇒ Object
Get the class name for a configuration.
-
.ensure_available!(*slugs) ⇒ Object
Ensure that the specified configurations are available.
-
.gems ⇒ Object
Get the all gems related to configurations.
-
.instance_of(slug) ⇒ Object
Returns an instance of the specified configuration.
-
.instances_of(*slugs) ⇒ Object
Returns a Hash containing instances of the specified configurations.
-
.set_ssh_key_paths(*keys) ⇒ Object
Set the paths to the private SSH Keys to use.
-
.slug_for(klass) ⇒ Object
Get the slug for a configuration class.
-
.slugs ⇒ Object
Get the slugs of all configurations.
Class Method Details
.all ⇒ Object
Returns a Hash of all available configurations.
Example:
>> RediPress::Configuration.all
=> { "test" => #<RediPress::Configuration::Test:0x00000000000000> }
18 19 20 |
# File 'lib/redipress/configuration.rb', line 18 def self.all instances_of(*slugs) end |
.available?(*slugs) ⇒ Boolean
Check that the specified configurations are available.
Arguments:
slugs: (Splat)
Example:
>> RediPress::Configuration.available? :test
=> true
137 138 139 140 141 142 143 |
# File 'lib/redipress/configuration.rb', line 137 def self.available?(*slugs) slugs.each do |slug| return false unless self.slugs.include?(slug.to_s) end true end |
.class_for(slug) ⇒ Object
Get the class name for a configuration.
Arguments:
slug: (Symbol|String)
Example:
>> RediPress::Configuration.class_for :test
=> "RediPress::Configuration::Test"
64 65 66 67 68 69 |
# File 'lib/redipress/configuration.rb', line 64 def self.class_for(slug) klass = slug.to_s.capitalize klass.gsub!(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase } klass.tr!("+", "x") "RediPress::Configuration::#{klass}" end |
.ensure_available!(*slugs) ⇒ Object
Ensure that the specified configurations are available.
Arguments:
slugs: (Splat)
Example:
>> RediPress::Configuration.ensure_available! :test
=> nil
Raises:
RediPress::ConfigurationNotAvailable: If one or more of the specified configurations are not available.
120 121 122 123 124 125 126 |
# File 'lib/redipress/configuration.rb', line 120 def self.ensure_available!(*slugs) slugs.each do |slug| raise RediPress::ConfigurationNotAvailable.new(slug) unless available?(slug) end nil end |
.gems ⇒ Object
Get the all gems related to configurations
Example:
>> RediPress::Configuration.gems
=> { "test" => "redipress/configuration/test" }
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/redipress/configuration.rb', line 161 def self.gems all_gems = Gem::Specification.select do |gem| gem.name.downcase =~ /^redipress-configuration-[a-z0-9-]+$/ end gems = Hash.new all_gems.each do |gem| slug = gem.name.downcase.sub("redipress-configuration-", "").gsub("-", "_") gems[slug] = "redipress/configuration/#{slug}" end gems end |
.instance_of(slug) ⇒ Object
Returns an instance of the specified configuration.
Arguments:
slug: (Symbol|String)
Example:
>> RediPress::Configuration.instance_of :test
=> #<RediPress::Configuration::Test:0x00000000000000>
47 48 49 50 51 52 53 |
# File 'lib/redipress/configuration.rb', line 47 def self.instance_of(slug) load_by_slugs(slug) klass = class_for(slug) klass = Object.const_get(klass) klass.new end |
.instances_of(*slugs) ⇒ Object
Returns a Hash containing instances of the specified configurations.
Arguments:
slugs: (Splat)
Example:
>> RediPress::Configuration.instances_of :test
=> { "test" => #<RediPress::Configuration::Test:0x00000000000000> }
31 32 33 34 35 36 |
# File 'lib/redipress/configuration.rb', line 31 def self.instances_of(*slugs) slugs.sort_by! { |slug| slug } slugs.map! { |slug| [slug.to_s, instance_of(slug.to_s)] } Hash[*slugs.flatten] end |
.set_ssh_key_paths(*keys) ⇒ Object
Set the paths to the private SSH Keys to use
Arguments:
keys: (Splat)
Example:
>> RediPress::Configuration.set_ssh_key_paths('/home/rediwebhosting/.ssh/id_rsa')
=> nil
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/redipress/configuration.rb', line 186 def self.set_ssh_key_paths(*keys) SSHKit::Backend::Netssh.configure do |ssh| ssh.connection_timeout = 60 ssh. = { keys: keys, forward_agent: false, auth_methods: %w(publickey password) } end end |
.slug_for(klass) ⇒ Object
Get the slug for a configuration class.
Arguments:
klass: (Class)
Example:
>> RediPress::Configuration.slug_for RediPress::Configuration::Test
=> "test"
80 81 82 83 84 85 86 87 |
# File 'lib/redipress/configuration.rb', line 80 def self.slug_for(klass) slug = klass.to_s.split("::").last slug.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') slug.gsub!(/([a-z\d])([A-Z])/,'\1_\2') slug.tr!("-", "_") slug.downcase! slug end |
.slugs ⇒ Object
Get the slugs of all configurations
Example:
>> RediPress::Configuration.slugs
=> ["test"]
151 152 153 |
# File 'lib/redipress/configuration.rb', line 151 def self.slugs gems.keys end |