Commit 954aee369ea0aaf8887429e9506f8bc8740528f9

Authored by Joenio Costa
Committed by Daniela Feitosa
1 parent 239c1080

Removing duplicated code from Task models

- Removed code that is already provided by acts_as_having_settings
app/models/add_friend.rb
1 1 class AddFriend < Task
2 2  
3   - acts_as_having_settings :group_for_person, :group_for_friend, :field => :data
  3 + settings_items :group_for_person, :group_for_friend
4 4  
5 5 validates_presence_of :requestor_id, :target_id
6 6  
... ...
app/models/add_member.rb
... ... @@ -8,7 +8,7 @@ class AddMember &lt; Task
8 8 alias :organization :target
9 9 alias :organization= :target=
10 10  
11   - acts_as_having_settings :roles, :field => :data
  11 + settings_items :roles
12 12  
13 13 def perform
14 14 self.roles ||= [Profile::Roles.member(organization.environment.id).id]
... ...
app/models/approve_article.rb
1 1 class ApproveArticle < Task
2   - serialize :data, Hash
3   -
4 2 validates_presence_of :requestor_id, :target_id
5 3  
6 4 def article_title
7 5 article ? article.title : _('(The original text was removed)')
8 6 end
9 7  
10   - def data
11   - self[:data] ||= {}
12   - end
13   -
14 8 def article
15 9 Article.find_by_id data[:article_id]
16 10 end
... ... @@ -27,21 +21,7 @@ class ApproveArticle &lt; Task
27 21 data[:name] = value
28 22 end
29 23  
30   - def closing_statment
31   - data[:closing_statment]
32   - end
33   -
34   - def closing_statment= value
35   - data[:closing_statment] = value
36   - end
37   -
38   - def article_parent_id= value
39   - data[:parent_id] = value
40   - end
41   -
42   - def article_parent_id
43   - data[:parent_id]
44   - end
  24 + settings_items :closing_statment, :article_parent_id, :highlighted
45 25  
46 26 def article_parent
47 27 Article.find_by_id article_parent_id.to_i
... ... @@ -51,14 +31,6 @@ class ApproveArticle &lt; Task
51 31 self.article_parent_id = value.id
52 32 end
53 33  
54   - def highlighted= value
55   - data[:highlighted] = value
56   - end
57   -
58   - def highlighted
59   - data[:highlighted]
60   - end
61   -
62 34 def abstract= value
63 35 data[:abstract] = value
64 36 end
... ...
app/models/change_password.rb
1 1 class ChangePassword < Task
2 2  
3   - serialize :data, Hash
4   - def data
5   - self[:data] ||= {}
6   - end
7   -
8 3 attr_accessor :login, :email, :password, :password_confirmation, :environment_id
9 4  
10 5 def self.human_attribute_name(attrib)
... ... @@ -56,11 +51,6 @@ class ChangePassword &lt; Task
56 51 validates_presence_of :password_confirmation, :on => :update, :if => lambda { |change| change.status != Task::Status::CANCELLED }
57 52 validates_confirmation_of :password, :if => lambda { |change| change.status != Task::Status::CANCELLED }
58 53  
59   - def initialize(*args)
60   - super(*args)
61   - self[:data] = {}
62   - end
63   -
64 54 def title
65 55 _("Change password")
66 56 end
... ...
app/models/create_community.rb
... ... @@ -6,25 +6,11 @@ class CreateCommunity &lt; Task
6 6 alias :environment :target
7 7 alias :environment= :target=
8 8  
9   - serialize :data, Hash
10   - attr_protected :data
11   - def data
12   - self[:data] ||= Hash.new
13   - end
14   -
15 9 acts_as_having_image
16 10  
17 11 DATA_FIELDS = Community.fields + ['name', 'closed']
18   -
19 12 DATA_FIELDS.each do |field|
20   - # getter
21   - define_method(field) do
22   - self.data[field.to_sym]
23   - end
24   - # setter
25   - define_method("#{field}=") do |value|
26   - self.data[field.to_sym] = value
27   - end
  13 + settings_items field.to_sym
28 14 end
29 15  
30 16 def validate
... ...
app/models/create_enterprise.rb
... ... @@ -12,22 +12,8 @@ class CreateEnterprise &lt; Task
12 12 N_('Management information')
13 13  
14 14 DATA_FIELDS = Enterprise.fields + %w[name identifier region_id]
15   -
16   - serialize :data, Hash
17   - attr_protected :data
18   - def data
19   - self[:data] ||= Hash.new
20   - end
21   -
22 15 DATA_FIELDS.each do |field|
23   - # getter
24   - define_method(field) do
25   - self.data[field.to_sym]
26   - end
27   - # setter
28   - define_method("#{field}=") do |value|
29   - self.data[field.to_sym] = value
30   - end
  16 + settings_items field.to_sym
31 17 end
32 18  
33 19 # checks for virtual attributes
... ...
app/models/enterprise_activation.rb
... ... @@ -2,7 +2,6 @@ class EnterpriseActivation &lt; Task
2 2  
3 3 class RequestorRequired < Exception; end
4 4  
5   - acts_as_having_settings :field => :data
6 5 settings_items :enterprise_id, :integer
7 6  
8 7 validates_presence_of :enterprise_id
... ...
app/models/invitation.rb
1 1 class Invitation < Task
2 2  
3   - acts_as_having_settings :field => :data
4 3 settings_items :message, :friend_name, :friend_email
5 4  
6 5 validates_presence_of :requestor_id
... ...
app/models/suggest_article.rb
... ... @@ -2,9 +2,6 @@ class SuggestArticle &lt; Task
2 2  
3 3 has_captcha
4 4  
5   - serialize :data, Hash
6   - acts_as_having_settings :field => :data
7   -
8 5 validates_presence_of :target_id, :article_name, :email, :name, :article_body
9 6  
10 7 settings_items :email, :type => String
... ...
app/models/ticket.rb
1 1 class Ticket < Task
2   - acts_as_having_settings :field => :data
3 2 settings_items :title, :message
4 3 end
... ...