Module: ActiveRecord::Store::ClassMethods
- Defined in:
- lib/active_record/store.rb
Instance Method Summary collapse
-
#_store_accessors_module ⇒ Object
:nodoc:.
- #store(store_attribute, options = {}) ⇒ Object
- #store_accessor(store_attribute, *keys) ⇒ Object
- #stored_attributes ⇒ Object
Instance Method Details
#_store_accessors_module ⇒ Object
:nodoc:
107 108 109 110 111 112 113 |
# File 'lib/active_record/store.rb', line 107 def _store_accessors_module # :nodoc: @_store_accessors_module ||= begin mod = Module.new include mod mod end end |
#store(store_attribute, options = {}) ⇒ Object
80 81 82 83 |
# File 'lib/active_record/store.rb', line 80 def store(store_attribute, = {}) serialize store_attribute, IndifferentCoder.new(store_attribute, [:coder]) store_accessor(store_attribute, [:accessors]) if .has_key? :accessors end |
#store_accessor(store_attribute, *keys) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/active_record/store.rb', line 85 def store_accessor(store_attribute, *keys) keys = keys.flatten _store_accessors_module.module_eval do keys.each do |key| define_method("#{key}=") do |value| write_store_attribute(store_attribute, key, value) end define_method(key) do read_store_attribute(store_attribute, key) end end end # assign new store attribute and create new hash to ensure that each class in the hierarchy # has its own hash of stored attributes. self.local_stored_attributes ||= {} self.local_stored_attributes[store_attribute] ||= [] self.local_stored_attributes[store_attribute] |= keys end |
#stored_attributes ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/active_record/store.rb', line 115 def stored_attributes parent = superclass.respond_to?(:stored_attributes) ? superclass.stored_attributes : {} if local_stored_attributes parent.merge!(local_stored_attributes) { |k, a, b| a | b } end parent end |