Permalink
Browse files

Set the entry group searching against all existing filters

  • Loading branch information...
1 parent 4b37f78 commit 5345abf5322ee17fcc6530344d2f8d61aff851d3 @rogercampos committed Mar 17, 2012
Showing with 9 additions and 2 deletions.
  1. +6 −0 app/models/entry.rb
  2. +3 −2 app/models/filter.rb
View
@@ -27,6 +27,7 @@ class Entry < ActiveRecord::Base
after_destroy :fix_top_entries
before_destroy :check_unconfirmed
after_update :expire_cache
+ before_save :set_group_by_filters
scope :ordered, order("entries.cashed_at DESC").order("entries.order DESC")
scope :reversed, order("entries.cashed_at ASC").order("entries.order ASC")
@@ -204,4 +205,9 @@ def import_cannot_be_zero
def expire_cache
Rails.cache.delete("graph_user_#{account.owner}_month_#{cashed_at.month}")
end
+
+ def set_group_by_filters
+ return unless group.nil?
+ self.group = Filter.matching_group(concept, account.filters)
+ end
end
View
@@ -6,10 +6,11 @@ class Filter < ActiveRecord::Base
validate :group_inside_account
def matches_with?(str)
- ( str =~ /#{matching_regexp}/ ) ? self : false
+ ( str =~ /#{matching_regexp}/ ) ? self : nil
end
- def self.matching_group?(str, filters)
+ def self.matching_group(str, filters)
+ return nil if filters.empty?
filters.detect{|x| x.matches_with?(str)}.try(:group)
end

0 comments on commit 5345abf

Please sign in to comment.