Module: ActiveRedis::AttributeMethods
- Included in:
- Base
- Defined in:
- lib/active_redis/attributes.rb
Instance Method Summary collapse
- #after_set(field_name) ⇒ Object
- #allow_mass_assignment?(attr) ⇒ Boolean
- #expire_field(field_name) ⇒ Object
- #set_attributes(attrs) ⇒ Object
- #update_attributes(attrs) ⇒ Object
Instance Method Details
#after_set(field_name) ⇒ Object
20 21 22 |
# File 'lib/active_redis/attributes.rb', line 20 def after_set(field_name) expire_field(field_name) end |
#allow_mass_assignment?(attr) ⇒ Boolean
3 4 5 |
# File 'lib/active_redis/attributes.rb', line 3 def allow_mass_assignment?(attr) self.class.attr_accessible?(attr) end |
#expire_field(field_name) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/active_redis/attributes.rb', line 24 def expire_field(field_name) expires_in = self.class.[field_name.to_sym][:expires_in] if expires_in.to_i > 0 ActiveRedis.redis.expire(send("#{field_name}_redis_key"), expires_in.to_i) end end |
#set_attributes(attrs) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/active_redis/attributes.rb', line 7 def set_attributes(attrs) if attrs attrs.each do |attr, value| send("#{attr}=", value) if allow_mass_assignment?(attr) && respond_to?("#{attr}=") end end end |
#update_attributes(attrs) ⇒ Object
15 16 17 18 |
# File 'lib/active_redis/attributes.rb', line 15 def update_attributes(attrs) set_attributes(attrs) save end |