dynamic_attributes 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/lib/dynamic_attributes.rb +11 -5
- data/test/helper.rb +1 -1
- metadata +14 -5
data/README.rdoc
CHANGED
@@ -71,6 +71,8 @@ Note that a dynamic attribute should be prefixed (by default with 'field_'), see
|
|
71
71
|
* Get Info:
|
72
72
|
* dynamic_model.has_dynamic_attribute?(dynamic_attribute)
|
73
73
|
* Returns whether a given attribute is a dynamic attribute. Accepts strings and symbols.
|
74
|
+
* dynamic_model.read_dynamic_attribute(dynamic_attribute)
|
75
|
+
* Returns the value for a given dynamic attribute. Returns nil if the attribute does not exist or if the attribute is not a dynamic attribute.
|
74
76
|
* dynamic_model.persisting_dynamic_attributes
|
75
77
|
* Returns an array of the dynamic attributes that will be persisted.
|
76
78
|
* DynamicModel.dynamic_attribute_field
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/dynamic_attributes.rb
CHANGED
@@ -99,20 +99,26 @@ module DynamicAttributes
|
|
99
99
|
class << self
|
100
100
|
self
|
101
101
|
end
|
102
|
-
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Defines an accessor for the given attribute. It is defined withinin the public scope to ensure the
|
105
|
+
# accessor is publicly available in ruby 1.9.
|
106
|
+
def define_accessor_for_attribute(att)
|
107
|
+
singleton_class.send(:attr_accessor, att)
|
108
|
+
end
|
103
109
|
|
104
110
|
private
|
105
|
-
|
111
|
+
|
106
112
|
# Method that is called when a dynamic attribute is added to this model. It adds this attribute to the list
|
107
113
|
# of attributes that will be persisited, creates an accessor and sets the attribute value. To reflect that the
|
108
114
|
# attribute has been added, the serialization attribute will also be updated.
|
109
|
-
def set_dynamic_attribute(att, value)
|
115
|
+
def set_dynamic_attribute(att, value = nil)
|
110
116
|
att = att.to_s
|
111
117
|
persisting_dynamic_attributes << att
|
112
|
-
|
118
|
+
define_accessor_for_attribute(att)
|
113
119
|
send(att + '=', value)
|
114
120
|
update_dynamic_attribute(att, value)
|
115
|
-
end
|
121
|
+
end
|
116
122
|
|
117
123
|
# Called on object initialization or when calling update_attributes to convert passed dynamic attributes
|
118
124
|
# into attributes that will be persisted by calling set_dynamic_attribute if it does not exist already.
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Reinier de Lange
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-11-21 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -38,6 +39,10 @@ files:
|
|
38
39
|
- VERSION
|
39
40
|
- init.rb
|
40
41
|
- lib/dynamic_attributes.rb
|
42
|
+
- test/helper.rb
|
43
|
+
- test/test_dynamic_attributes.rb
|
44
|
+
- test/database.yml
|
45
|
+
- test/schema.rb
|
41
46
|
has_rdoc: true
|
42
47
|
homepage: http://github.com/moiristo/dynamic_attributes
|
43
48
|
licenses: []
|
@@ -48,23 +53,27 @@ rdoc_options:
|
|
48
53
|
require_paths:
|
49
54
|
- lib
|
50
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
51
57
|
requirements:
|
52
58
|
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
54
61
|
segments:
|
55
62
|
- 0
|
56
63
|
version: "0"
|
57
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ">="
|
60
68
|
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
61
70
|
segments:
|
62
71
|
- 0
|
63
72
|
version: "0"
|
64
73
|
requirements: []
|
65
74
|
|
66
75
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.3.
|
76
|
+
rubygems_version: 1.3.7
|
68
77
|
signing_key:
|
69
78
|
specification_version: 3
|
70
79
|
summary: dynamic_attributes is a gem that lets you dynamically specify attributes on ActiveRecord models, which will be serialized and deserialized to a given text column.
|