From 01c1557140a250a7c55269fa415fe842175e66ff Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 26 Mar 2010 16:16:04 -0300 Subject: [PATCH] Refactor Article#copy --- app/models/article.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 78ae5dd..27f669a 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -269,14 +269,27 @@ class Article < ActiveRecord::Base def copy(options) - attrs = attributes.reject! { |key, value| article_attr_blacklist.include?(key) } + attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } attrs.merge!(options) self.class.create(attrs) end - def article_attr_blacklist - ['id', 'profile_id', 'parent_id', 'slug', 'path', 'updated_at', 'created_at', 'last_changed_by_id', 'version', 'lock_version', 'type', 'children_count', 'comments_count', 'hits'] - end + ATTRIBUTES_NOT_COPIED = [ + :id, + :profile_id, + :parent_id, + :slug, + :path, + :updated_at, + :created_at, + :last_changed_by_id, + :version, + :lock_version, + :type, + :children_count, + :comments_count, + :hits, + ] def self.find_by_old_path(old_path) find(:first, :include => :versions, :conditions => ['article_versions.path = ?', old_path], :order => 'article_versions.id desc') -- libgit2 0.21.2