Commit 954aee369ea0aaf8887429e9506f8bc8740528f9
Committed by
Daniela Feitosa
1 parent
239c1080
Exists in
master
and in
28 other branches
Removing duplicated code from Task models
- Removed code that is already provided by acts_as_having_settings
Showing
10 changed files
with
5 additions
and
77 deletions
Show diff stats
app/models/add_friend.rb
app/models/add_member.rb
| @@ -8,7 +8,7 @@ class AddMember < Task | @@ -8,7 +8,7 @@ class AddMember < Task | ||
| 8 | alias :organization :target | 8 | alias :organization :target |
| 9 | alias :organization= :target= | 9 | alias :organization= :target= |
| 10 | 10 | ||
| 11 | - acts_as_having_settings :roles, :field => :data | 11 | + settings_items :roles |
| 12 | 12 | ||
| 13 | def perform | 13 | def perform |
| 14 | self.roles ||= [Profile::Roles.member(organization.environment.id).id] | 14 | self.roles ||= [Profile::Roles.member(organization.environment.id).id] |
app/models/approve_article.rb
| 1 | class ApproveArticle < Task | 1 | class ApproveArticle < Task |
| 2 | - serialize :data, Hash | ||
| 3 | - | ||
| 4 | validates_presence_of :requestor_id, :target_id | 2 | validates_presence_of :requestor_id, :target_id |
| 5 | 3 | ||
| 6 | def article_title | 4 | def article_title |
| 7 | article ? article.title : _('(The original text was removed)') | 5 | article ? article.title : _('(The original text was removed)') |
| 8 | end | 6 | end |
| 9 | 7 | ||
| 10 | - def data | ||
| 11 | - self[:data] ||= {} | ||
| 12 | - end | ||
| 13 | - | ||
| 14 | def article | 8 | def article |
| 15 | Article.find_by_id data[:article_id] | 9 | Article.find_by_id data[:article_id] |
| 16 | end | 10 | end |
| @@ -27,21 +21,7 @@ class ApproveArticle < Task | @@ -27,21 +21,7 @@ class ApproveArticle < Task | ||
| 27 | data[:name] = value | 21 | data[:name] = value |
| 28 | end | 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 | def article_parent | 26 | def article_parent |
| 47 | Article.find_by_id article_parent_id.to_i | 27 | Article.find_by_id article_parent_id.to_i |
| @@ -51,14 +31,6 @@ class ApproveArticle < Task | @@ -51,14 +31,6 @@ class ApproveArticle < Task | ||
| 51 | self.article_parent_id = value.id | 31 | self.article_parent_id = value.id |
| 52 | end | 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 | def abstract= value | 34 | def abstract= value |
| 63 | data[:abstract] = value | 35 | data[:abstract] = value |
| 64 | end | 36 | end |
app/models/change_password.rb
| 1 | class ChangePassword < Task | 1 | class ChangePassword < Task |
| 2 | 2 | ||
| 3 | - serialize :data, Hash | ||
| 4 | - def data | ||
| 5 | - self[:data] ||= {} | ||
| 6 | - end | ||
| 7 | - | ||
| 8 | attr_accessor :login, :email, :password, :password_confirmation, :environment_id | 3 | attr_accessor :login, :email, :password, :password_confirmation, :environment_id |
| 9 | 4 | ||
| 10 | def self.human_attribute_name(attrib) | 5 | def self.human_attribute_name(attrib) |
| @@ -56,11 +51,6 @@ class ChangePassword < Task | @@ -56,11 +51,6 @@ class ChangePassword < Task | ||
| 56 | validates_presence_of :password_confirmation, :on => :update, :if => lambda { |change| change.status != Task::Status::CANCELLED } | 51 | validates_presence_of :password_confirmation, :on => :update, :if => lambda { |change| change.status != Task::Status::CANCELLED } |
| 57 | validates_confirmation_of :password, :if => lambda { |change| change.status != Task::Status::CANCELLED } | 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 | def title | 54 | def title |
| 65 | _("Change password") | 55 | _("Change password") |
| 66 | end | 56 | end |
app/models/create_community.rb
| @@ -6,25 +6,11 @@ class CreateCommunity < Task | @@ -6,25 +6,11 @@ class CreateCommunity < Task | ||
| 6 | alias :environment :target | 6 | alias :environment :target |
| 7 | alias :environment= :target= | 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 | acts_as_having_image | 9 | acts_as_having_image |
| 16 | 10 | ||
| 17 | DATA_FIELDS = Community.fields + ['name', 'closed'] | 11 | DATA_FIELDS = Community.fields + ['name', 'closed'] |
| 18 | - | ||
| 19 | DATA_FIELDS.each do |field| | 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 | end | 14 | end |
| 29 | 15 | ||
| 30 | def validate | 16 | def validate |
app/models/create_enterprise.rb
| @@ -12,22 +12,8 @@ class CreateEnterprise < Task | @@ -12,22 +12,8 @@ class CreateEnterprise < Task | ||
| 12 | N_('Management information') | 12 | N_('Management information') |
| 13 | 13 | ||
| 14 | DATA_FIELDS = Enterprise.fields + %w[name identifier region_id] | 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 | DATA_FIELDS.each do |field| | 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 | end | 17 | end |
| 32 | 18 | ||
| 33 | # checks for virtual attributes | 19 | # checks for virtual attributes |
app/models/enterprise_activation.rb
| @@ -2,7 +2,6 @@ class EnterpriseActivation < Task | @@ -2,7 +2,6 @@ class EnterpriseActivation < Task | ||
| 2 | 2 | ||
| 3 | class RequestorRequired < Exception; end | 3 | class RequestorRequired < Exception; end |
| 4 | 4 | ||
| 5 | - acts_as_having_settings :field => :data | ||
| 6 | settings_items :enterprise_id, :integer | 5 | settings_items :enterprise_id, :integer |
| 7 | 6 | ||
| 8 | validates_presence_of :enterprise_id | 7 | validates_presence_of :enterprise_id |
app/models/invitation.rb
app/models/suggest_article.rb
| @@ -2,9 +2,6 @@ class SuggestArticle < Task | @@ -2,9 +2,6 @@ class SuggestArticle < Task | ||
| 2 | 2 | ||
| 3 | has_captcha | 3 | has_captcha |
| 4 | 4 | ||
| 5 | - serialize :data, Hash | ||
| 6 | - acts_as_having_settings :field => :data | ||
| 7 | - | ||
| 8 | validates_presence_of :target_id, :article_name, :email, :name, :article_body | 5 | validates_presence_of :target_id, :article_name, :email, :name, :article_body |
| 9 | 6 | ||
| 10 | settings_items :email, :type => String | 7 | settings_items :email, :type => String |
app/models/ticket.rb