Class: ConfigManager::Toggles::Definition
- Inherits:
-
Object
- Object
- ConfigManager::Toggles::Definition
- Defined in:
- lib/config_manager/toggles/definition.rb
Class Method Summary collapse
Instance Method Summary collapse
- #acceptable_values ⇒ Object
- #acceptable_values=(values) ⇒ Object (also: #formatted_acceptable_values=)
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #formatted_acceptable_values ⇒ Object
-
#initialize(test) ⇒ Definition
constructor
A new instance of Definition.
- #message ⇒ Object
- #name ⇒ Object
- #to_hash ⇒ Object
- #to_yaml ⇒ Object
- #type ⇒ Object
- #type=(type) ⇒ Object
- #type_class ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(test) ⇒ Definition
Returns a new instance of Definition.
5 6 7 |
# File 'lib/config_manager/toggles/definition.rb', line 5 def initialize(test) @key = key(test) end |
Class Method Details
.prefix ⇒ Object
58 59 60 |
# File 'lib/config_manager/toggles/definition.rb', line 58 def self.prefix "#{Rails.application.class.parent_name.underscore}_toggles-" end |
.types ⇒ Object
54 55 56 |
# File 'lib/config_manager/toggles/definition.rb', line 54 def self.types %w(boolean set) end |
Instance Method Details
#acceptable_values ⇒ Object
36 37 38 39 40 |
# File 'lib/config_manager/toggles/definition.rb', line 36 def acceptable_values @values ||= $redis.hget(@key, 'acceptable_values') #self.send("to_#{type}", @values) type_class.from_json(@values) end |
#acceptable_values=(values) ⇒ Object Also known as: formatted_acceptable_values=
42 43 44 45 46 47 48 |
# File 'lib/config_manager/toggles/definition.rb', line 42 def acceptable_values=(values) return unless valid? $redis.hset(@key, 'acceptable_values', type_class.to_json(values)) #$redis.hset(@key, 'acceptable_values', self.send("to_#{type}", values)) @values = $redis.hget(@key, 'acceptable_values') end |
#delete ⇒ Object
50 51 52 |
# File 'lib/config_manager/toggles/definition.rb', line 50 def delete $redis.del(@key) end |
#exists? ⇒ Boolean
9 10 11 |
# File 'lib/config_manager/toggles/definition.rb', line 9 def exists? $redis.exists(@key) end |
#formatted_acceptable_values ⇒ Object
73 74 75 76 |
# File 'lib/config_manager/toggles/definition.rb', line 73 def formatted_acceptable_values values = acceptable_values values.respond_to?(:join) ? values.join(',') : values end |
#message ⇒ Object
66 67 68 69 70 |
# File 'lib/config_manager/toggles/definition.rb', line 66 def return "missing name" unless name.present? return "missing type" unless type.present? nil end |
#name ⇒ Object
13 14 15 |
# File 'lib/config_manager/toggles/definition.rb', line 13 def name @name ||= @key.gsub(Definition.prefix, '') end |
#to_hash ⇒ Object
82 83 84 |
# File 'lib/config_manager/toggles/definition.rb', line 82 def to_hash {name => {'type' => type, 'acceptable_values' => formatted_acceptable_values}} end |
#to_yaml ⇒ Object
78 79 80 |
# File 'lib/config_manager/toggles/definition.rb', line 78 def to_yaml to_hash.to_yaml end |
#type ⇒ Object
17 18 19 |
# File 'lib/config_manager/toggles/definition.rb', line 17 def type @type ||= $redis.hget(@key, 'type') end |
#type=(type) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/config_manager/toggles/definition.rb', line 21 def type=(type) return unless name.present? unless Definition.types.include?(type) raise("#{type} is an unsupported Toggle type. Acceptable values are #{Definition.types}") end $redis.hset(@key, 'type', type) @type = $redis.hget(@key, 'type') end |
#type_class ⇒ Object
31 32 33 34 |
# File 'lib/config_manager/toggles/definition.rb', line 31 def type_class return Null unless valid? eval("ConfigManager::Toggles::#{type.camelize}") end |
#valid? ⇒ Boolean
62 63 64 |
# File 'lib/config_manager/toggles/definition.rb', line 62 def valid? !!(name.present? && type) end |