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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7fbd76f70d8e5491d55e03c1ac6f0b38b095b6b
4
- data.tar.gz: afe56be4e9efe8c16595942dd2378917728c0abe
3
+ metadata.gz: 465049007b0878be5f3011b44be9eae8e2a45e79
4
+ data.tar.gz: 377c3d034d4a4a3794531c53ef7764a32519b42b
5
5
  SHA512:
6
- metadata.gz: aad19801c643833ee388d1a389d9f74664a3b02262982e3af5566142c5e0cdcbcb2427ef29bc52579ddd6995d880f98e210a745ecc98074d1dae9e7e93bd364c
7
- data.tar.gz: b4d49688cb6eeb36337a32a0c2d2b32301f478c1ee0abae579e2ce2280fdf2f17f479cb07b68ed345b19e61cfdffd8d457725f325799d019ba1b23645db6a86b
6
+ metadata.gz: 8e0daba150f2620356590745e3d072c37f05f675a68ae91172e57adbf1005fb511516be606f059c56d5233e324fdf229dfcc0bad8d1e459a8192c058b652e274
7
+ data.tar.gz: 8a94de2fda927d95e33d968125a167f0a38ffd7e70769036283a6c0300bc790d938a204753e3188f820e00671d24e14c8ed46141883fcb1d262bbf2655d13460
data/attribution.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "attribution"
5
- gem.version = "0.9.0"
5
+ gem.version = "0.9.1"
6
6
  gem.authors = ["Paul Barry"]
7
7
  gem.email = ["mail@paulbarry.com"]
8
8
  gem.description = %q{Add attributes to Ruby objects}
@@ -1,3 +1,3 @@
1
1
  module Attribution
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
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}", Hash(arg))
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
- begin
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
- # TODO: Support a more generic version of lazy-loading
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
- # TODO: put this in method
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.0
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-25 00:00:00.000000000 Z
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport