attribution 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/attribution.gemspec +1 -1
- data/lib/attribution/version.rb +1 -1
- data/lib/attribution.rb +6 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 465049007b0878be5f3011b44be9eae8e2a45e79
|
4
|
+
data.tar.gz: 377c3d034d4a4a3794531c53ef7764a32519b42b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e0daba150f2620356590745e3d072c37f05f675a68ae91172e57adbf1005fb511516be606f059c56d5233e324fdf229dfcc0bad8d1e459a8192c058b652e274
|
7
|
+
data.tar.gz: 8a94de2fda927d95e33d968125a167f0a38ffd7e70769036283a6c0300bc790d938a204753e3188f820e00671d24e14c8ed46141883fcb1d262bbf2655d13460
|
data/attribution.gemspec
CHANGED
data/lib/attribution/version.rb
CHANGED
data/lib/attribution.rb
CHANGED
@@ -216,7 +216,7 @@ module Attribution
|
|
216
216
|
def hash_attr(attr, metadata={})
|
217
217
|
add_attribute(attr, :hash, metadata)
|
218
218
|
define_method("#{attr}=") do |arg|
|
219
|
-
instance_variable_set("@#{attr}",
|
219
|
+
instance_variable_set("@#{attr}", arg || {})
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
@@ -296,12 +296,7 @@ module Attribution
|
|
296
296
|
if instance_variable_defined?("@#{association_name}")
|
297
297
|
instance_variable_get("@#{association_name}")
|
298
298
|
elsif id = instance_variable_get("@#{association_name}_id")
|
299
|
-
|
300
|
-
begin
|
301
|
-
association_class = Object.const_get(association_class_name)
|
302
|
-
rescue NameError => ex
|
303
|
-
raise ArgumentError.new("Association #{association_name} in #{self.class} is invalid because #{association_class_name} does not exist")
|
304
|
-
end
|
299
|
+
association_class = association_class_name.constantize
|
305
300
|
|
306
301
|
if self.class.autoload_associations? && association_class.respond_to?(:find)
|
307
302
|
instance_variable_set("@#{association_name}", association_class.find(id))
|
@@ -313,11 +308,7 @@ module Attribution
|
|
313
308
|
|
314
309
|
# foo=
|
315
310
|
define_method("#{association_name}=") do |arg|
|
316
|
-
|
317
|
-
association_class = Object.const_get(association_class_name)
|
318
|
-
rescue NameError => ex
|
319
|
-
raise ArgumentError.new("Association #{association_name} in #{self.class} is invalid because #{association_class_name} does not exist")
|
320
|
-
end
|
311
|
+
association_class = association_class_name.constantize
|
321
312
|
|
322
313
|
if instance_variable_defined?("@#{association_name}_id")
|
323
314
|
remove_instance_variable("@#{association_name}_id")
|
@@ -340,13 +331,9 @@ module Attribution
|
|
340
331
|
|
341
332
|
# foos
|
342
333
|
define_method(association_name) do |*query|
|
343
|
-
|
344
|
-
begin
|
345
|
-
association_class = Object.const_get(association_class_name)
|
346
|
-
rescue NameError => ex
|
347
|
-
raise ArgumentError.new("Association #{association_name} in #{self.class} is invalid because #{association_class_name} does not exist")
|
348
|
-
end
|
334
|
+
association_class = association_class_name.constantize
|
349
335
|
|
336
|
+
# TODO: Support a more generic version of lazy-loading
|
350
337
|
if query.empty? # Ex: Books.all, so we want to cache it.
|
351
338
|
ivar = "@#{association_name}"
|
352
339
|
if instance_variable_defined?(ivar)
|
@@ -363,12 +350,7 @@ module Attribution
|
|
363
350
|
|
364
351
|
# foos=
|
365
352
|
define_method("#{association_name}=") do |arg|
|
366
|
-
|
367
|
-
begin
|
368
|
-
association_class = Object.const_get(association_class_name)
|
369
|
-
rescue NameError => ex
|
370
|
-
raise ArgumentError.new("Association #{association_name} in #{self.class} is invalid because #{association_class_name} does not exist")
|
371
|
-
end
|
353
|
+
association_class = association_class_name.constantize
|
372
354
|
|
373
355
|
attr_name = self.class.name.demodulize.underscore
|
374
356
|
objs = (arg.is_a?(Hash) ? arg.values : Array(arg)).map do |obj|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribution
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|