File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 1
1
## Rails 4.0.0 (unreleased) ##
2
2
3
- * Added a ` stored_attributes ` hash which contains the attributes stored
4
- using ActiveRecord::Store. This allows you to retrieve the list of
5
- attributes you've defined.
3
+ * Added ` stored_attributes ` hash which contains the attributes stored using
4
+ ActiveRecord::Store. This allows you to retrieve the list of attributes
5
+ you've defined.
6
6
7
- * Joost Baaij*
7
+ class User < ActiveRecord::Base
8
+ store : settings , accessors: [ : color , : homepage ]
9
+ end
10
+
11
+ User.stored_attributes[ : settings ] # [ : color , : homepage ]
12
+
13
+ * Joost Baaij & Carlos Antonio da Silva*
8
14
9
15
* ` composed_of ` was removed. You'll have to write your own accessor
10
16
and mutator methods if you'd like to use value objects to represent some
Original file line number Diff line number Diff line change 1
1
require 'active_support/concern'
2
2
require 'active_support/core_ext/hash/indifferent_access'
3
+ require 'active_support/core_ext/class/attribute'
3
4
4
5
module ActiveRecord
5
6
# Store gives you a thin wrapper around serialize for the purpose of storing hashes in a single column.
@@ -42,7 +43,7 @@ module Store
42
43
extend ActiveSupport ::Concern
43
44
44
45
included do
45
- config_attribute :stored_attributes
46
+ class_attribute :stored_attributes
46
47
self . stored_attributes = { }
47
48
end
48
49
@@ -53,7 +54,8 @@ def store(store_attribute, options = {})
53
54
end
54
55
55
56
def store_accessor ( store_attribute , *keys )
56
- keys . flatten . each do |key |
57
+ keys = keys . flatten
58
+ keys . each do |key |
57
59
define_method ( "#{ key } =" ) do |value |
58
60
initialize_store_attribute ( store_attribute )
59
61
send ( store_attribute ) [ key ] = value
@@ -66,7 +68,7 @@ def store_accessor(store_attribute, *keys)
66
68
end
67
69
end
68
70
69
- self . stored_attributes [ store_attribute ] = keys . flatten
71
+ self . stored_attributes [ store_attribute ] = keys
70
72
end
71
73
end
72
74
You can’t perform that action at this time.
0 commit comments