Class: RedBlocks::EnumSet
Constant Summary collapse
- ADDRESSED_OBJECT_REGEXP =
Match string such as ‘#<User:0x007fa3323a2b90>`
/^#<(.+):0x\w+>$/
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Set
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ EnumSet
constructor
A new instance of EnumSet.
- #key_suffix ⇒ Object
Methods inherited from Set
#cache_time, #disabled?, #expiration_time, #expression, #get, #ids, #key, key_pattern, #label, #size, #update!, #update_if_disabled!
Methods included from SetOptimizer
Methods included from SetUtils
included, #joined_key, #normalize_entries, #validate_array_entry, #validate_entries!
Constructor Details
#initialize(value) ⇒ EnumSet
Returns a new instance of EnumSet.
5 6 7 8 9 10 |
# File 'lib/red_blocks/enum_set.rb', line 5 def initialize(value) unless self.class.available_values.include?(value) raise RedBlocks::DomainError.new(value, self.class.available_values) end @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/red_blocks/enum_set.rb', line 3 def value @value end |
Class Method Details
.available_values ⇒ Object
32 33 34 |
# File 'lib/red_blocks/enum_set.rb', line 32 def self.available_values raise NotImplementedError end |
.warmup! ⇒ Object
26 27 28 29 30 |
# File 'lib/red_blocks/enum_set.rb', line 26 def self.warmup! available_values.each do |value| self.new(value).update! end end |
Instance Method Details
#key_suffix ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/red_blocks/enum_set.rb', line 15 def key_suffix suffix = @value.to_s if suffix =~ ADDRESSED_OBJECT_REGEXP raise <<MSG The key suffix may include random address #{suffix.inspect}. You must override `key_suffix` explicitly, or use `value` which implements deterministic `to_s`. MSG end suffix end |