Module: Blackbeard::StorableAttributes::InstanceMethods

Defined in:
lib/blackbeard/storable_attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributes_hash_keyObject



94
95
96
# File 'lib/blackbeard/storable_attributes.rb', line 94

def attributes_hash_key
  "#{key}::attributes"
end

#reload_storable_attributesObject



85
86
87
88
# File 'lib/blackbeard/storable_attributes.rb', line 85

def reload_storable_attributes
  @storable_attributes = nil
  @storable_attributes_dirty = false
end

#save_storable_attributesObject

Raises:



77
78
79
80
81
82
83
# File 'lib/blackbeard/storable_attributes.rb', line 77

def save_storable_attributes
  raise StorableNotSaved if new_record?
  if @storable_attributes_dirty
    db.hash_multi_set(attributes_hash_key, storable_attributes_hash)
    @storable_attributes_dirty = false
  end
end

#storable_attributes_hashObject



90
91
92
# File 'lib/blackbeard/storable_attributes.rb', line 90

def storable_attributes_hash
  @storable_attributes ||= db.hash_get_all(attributes_hash_key)
end

#update_attributes(tainted_params) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/blackbeard/storable_attributes.rb', line 68

def update_attributes(tainted_params)
  attributes = self.class.storable_attributes
  safe_attributes = tainted_params.keys.select{ |k| attributes.include?(k.to_sym) }
  safe_attributes.each do |attribute|
    self.send("#{attribute}=".to_sym, tainted_params[attribute])
  end
  save_storable_attributes
end