Module: Blackbeard::StorableAttributes::ClassMethods

Defined in:
lib/blackbeard/storable_attributes.rb

Instance Method Summary collapse

Instance Method Details

#storable_attributesObject



13
14
15
16
17
# File 'lib/blackbeard/storable_attributes.rb', line 13

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



9
10
11
# File 'lib/blackbeard/storable_attributes.rb', line 9

def storable_attributes=(x)
  @storable_attributes = x
end

#string_attributes(*attributes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/blackbeard/storable_attributes.rb', line 19

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|
      db.hash_set(attributes_hash_key, method_name, value)
      storable_attributes_hash[method_name.to_s] = value
    end
  end
end