Module: Blackbeard::StorableAttributes::ClassMethods
- Defined in:
- lib/blackbeard/storable_attributes.rb
Instance Method Summary collapse
- #integer_attributes(*attributes) ⇒ Object
- #json_attributes(*attributes) ⇒ Object
- #storable_attributes ⇒ Object
- #storable_attributes=(x) ⇒ Object
- #string_attributes(*attributes) ⇒ Object
Instance Method Details
#integer_attributes(*attributes) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/blackbeard/storable_attributes.rb', line 23 def integer_attributes(*attributes) self.storable_attributes += attributes attributes.each do |method_name| method_name = method_name.to_sym send :define_method, method_name do storable_attributes_hash[method_name.to_s].to_i end send :define_method, "#{method_name}=".to_sym do |value| storable_attributes_hash[method_name.to_s] = value.to_i.to_s @storable_attributes_dirty = true end end end |
#json_attributes(*attributes) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/blackbeard/storable_attributes.rb', line 37 def json_attributes(*attributes) self.storable_attributes += attributes attributes.each do |method_name| method_name = method_name.to_sym send :define_method, method_name do return nil if storable_attributes_hash[method_name.to_s].nil? JSON.parse(storable_attributes_hash[method_name.to_s]) end send :define_method, "#{method_name}=".to_sym do |value| storable_attributes_hash[method_name.to_s] = JSON.generate(value) @storable_attributes_dirty = true end end end |
#storable_attributes ⇒ Object
17 18 19 20 21 |
# File 'lib/blackbeard/storable_attributes.rb', line 17 def storable_attributes return @storable_attributes if defined? @storable_attributes return self.superclass.storable_attributes if self.superclass.respond_to?(:storable_attributes) [] end |
#storable_attributes=(x) ⇒ Object
13 14 15 |
# File 'lib/blackbeard/storable_attributes.rb', line 13 def storable_attributes=(x) @storable_attributes = x end |
#string_attributes(*attributes) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/blackbeard/storable_attributes.rb', line 52 def string_attributes(*attributes) self.storable_attributes += attributes attributes.each do |method_name| method_name = method_name.to_sym send :define_method, method_name do storable_attributes_hash[method_name.to_s] end send :define_method, "#{method_name}=".to_sym do |value| storable_attributes_hash[method_name.to_s] = value.to_s @storable_attributes_dirty = true end end end |