tracks-attributes 1.1.0 → 1.1.1
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/lib/tracks_attributes.rb +6 -7
- data/lib/tracks_attributes/base.rb +1 -1
- data/lib/tracks_attributes/version.rb +1 -1
- metadata +2 -2
data/lib/tracks_attributes.rb
CHANGED
@@ -67,6 +67,8 @@ module TracksAttributes
|
|
67
67
|
#
|
68
68
|
# @see TracksAttributesInternal TracksAttributesInternal for full method list
|
69
69
|
def tracks_attributes(options={})
|
70
|
+
return if respond_to? :attr_info_for # prevent recursion
|
71
|
+
|
70
72
|
include TracksAttributesInternal
|
71
73
|
enable_validations if options[:validates]
|
72
74
|
self
|
@@ -76,10 +78,6 @@ module TracksAttributes
|
|
76
78
|
module TracksAttributesInternal
|
77
79
|
extend ActiveSupport::Concern
|
78
80
|
|
79
|
-
included do
|
80
|
-
@tracked_attrs ||= {}
|
81
|
-
end
|
82
|
-
|
83
81
|
module ClassMethods
|
84
82
|
|
85
83
|
# Override attr_accessor to track accessors for an TracksAttributes.
|
@@ -137,6 +135,8 @@ module TracksAttributes
|
|
137
135
|
|
138
136
|
private
|
139
137
|
def add_tracked_attrs(is_readable, is_writeable, *vars) #:nodoc:
|
138
|
+
@tracked_attrs ||= {}
|
139
|
+
|
140
140
|
attr_params = vars.extract_options!
|
141
141
|
klass = attr_params[:klass]
|
142
142
|
vars.each do |var|
|
@@ -213,11 +213,10 @@ module TracksAttributes
|
|
213
213
|
|
214
214
|
attr_info = self.class.attr_info_for name
|
215
215
|
klass = attr_info && attr_info.klass
|
216
|
-
|
217
|
-
if klass && klass.respond_to?(:create)
|
216
|
+
|
217
|
+
if klass && !value.kind_of?(klass) && klass.respond_to?(:create)
|
218
218
|
value = value.kind_of?(Array)? set_array_values(value, klass) : klass.create(value)
|
219
219
|
end
|
220
|
-
|
221
220
|
send("#{name}=", value)
|
222
221
|
end
|
223
222
|
|
@@ -12,6 +12,7 @@ module TracksAttributes
|
|
12
12
|
class Base
|
13
13
|
extend ClassMethods
|
14
14
|
include ActiveModel::Validations
|
15
|
+
tracks_attributes
|
15
16
|
|
16
17
|
##
|
17
18
|
# The standard create class method needed by a class that implements
|
@@ -34,7 +35,6 @@ module TracksAttributes
|
|
34
35
|
# @param [Hash] options to be passed onto the initialize method.
|
35
36
|
#
|
36
37
|
def initialize(attributes = {}, options = {})
|
37
|
-
self.class.tracks_attributes(options) unless self.class.respond_to? :attr_info_for
|
38
38
|
self.all_attributes = attributes
|
39
39
|
end
|
40
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tracks-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|