Commit 01c1557140a250a7c55269fa415fe842175e66ff
1 parent
f4b316aa
Exists in
master
and in
22 other branches
Refactor Article#copy
Using a constant instead of a method call that instantiates that array at every call; besides, using symbols instead of strings.
Showing
1 changed file
with
17 additions
and
4 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -269,14 +269,27 @@ class Article < ActiveRecord::Base |
269 | 269 | |
270 | 270 | |
271 | 271 | def copy(options) |
272 | - attrs = attributes.reject! { |key, value| article_attr_blacklist.include?(key) } | |
272 | + attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } | |
273 | 273 | attrs.merge!(options) |
274 | 274 | self.class.create(attrs) |
275 | 275 | end |
276 | 276 | |
277 | - def article_attr_blacklist | |
278 | - ['id', 'profile_id', 'parent_id', 'slug', 'path', 'updated_at', 'created_at', 'last_changed_by_id', 'version', 'lock_version', 'type', 'children_count', 'comments_count', 'hits'] | |
279 | - end | |
277 | + ATTRIBUTES_NOT_COPIED = [ | |
278 | + :id, | |
279 | + :profile_id, | |
280 | + :parent_id, | |
281 | + :slug, | |
282 | + :path, | |
283 | + :updated_at, | |
284 | + :created_at, | |
285 | + :last_changed_by_id, | |
286 | + :version, | |
287 | + :lock_version, | |
288 | + :type, | |
289 | + :children_count, | |
290 | + :comments_count, | |
291 | + :hits, | |
292 | + ] | |
280 | 293 | |
281 | 294 | def self.find_by_old_path(old_path) |
282 | 295 | find(:first, :include => :versions, :conditions => ['article_versions.path = ?', old_path], :order => 'article_versions.id desc') | ... | ... |