module Codable
Rails plugin for the attribute - code
Constants
- VERSION
Public Instance Methods
[](value)
click to toggle source
# File lib/codable.rb, line 10 def [](value) raise ArgumentError, 'value must be present' unless value.present? Rails.cache.fetch("#{_codable_cache_key_prefix}/#{value}") do find_by!(codable_key => value) end end
_codable_cache_key_prefix()
click to toggle source
# File lib/codable.rb, line 18 def _codable_cache_key_prefix "codable/#{table_name}/#{codable_key}" end
method_missing(method, *args)
click to toggle source
Calls superclass method
# File lib/codable.rb, line 30 def method_missing(method, *args) if method.to_s.end_with?('?') attributes[self.class.codable_key.to_s] == method.to_s.chomp('?') else super end end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/codable.rb, line 38 def respond_to_missing?(method, include_private = false) method.to_s.end_with?('?') || super end
Private Instance Methods
_codable_clear_expired_cache()
click to toggle source
# File lib/codable.rb, line 44 def _codable_clear_expired_cache # When the codable_key field is modified, we need to remove the cache of the original value value = attribute_before_last_save(self.class.codable_key.to_s) || attributes[self.class.codable_key.to_s] Rails.cache.delete("#{self.class._codable_cache_key_prefix}/#{value}") end