Switch from class_inheritable_accessor to class_attribute #9

Merged
merged 1 commit into from Jul 23, 2011

Conversation

Projects
None yet
2 participants
Contributor

brynary commented Jul 23, 2011

class_inheritable_accessor is deprecated in Rails 3.1. class_attribute has slightly different semantics, but this change should be functionality neutral since it appears there's only one place where the attachment_names Set is modified.

@brynary brynary Switch from class_inheritable_accessor to class_attribute
* class_inheritable_accessor is deprecated in Rails 3.1
7e6a49c

@bkeepers bkeepers commented on the diff Jul 23, 2011

lib/joint/class_methods.rb
@@ -8,7 +8,7 @@ module Joint
options.symbolize_keys!
name = name.to_sym
- self.attachment_names << name
+ self.attachment_names = attachment_names.dup.add(name)
@bkeepers

bkeepers Jul 23, 2011

Contributor

What's the advantage of duping here? Do we need a test for it?

@brynary

brynary Jul 23, 2011

Contributor

Duping is required so we don't mutate the Set object. This is required, and if you remove the dup two tests will fail so it seems to be well covered.

Docs on class_attribute explain this a bit: api.rubyonrails.org/classes/Class.html#method-i-class_attribute

Specifically: "However, you need to be aware when using class_attribute with mutable structures as Array or Hash. In such cases, you don’t want to do changes in places but use setters:"

@bkeepers

bkeepers Jul 23, 2011

Contributor

awesome, thanks!

@bkeepers bkeepers added a commit that referenced this pull request Jul 23, 2011

@bkeepers bkeepers Merge pull request #9 from brynary/class_attribute
Switch from class_inheritable_accessor to class_attribute
f7a0609

@bkeepers bkeepers merged commit f7a0609 into jnunemaker:master Jul 23, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment