Skip to content

Commit

Permalink
New and resolved state set through scope
Browse files Browse the repository at this point in the history
  • Loading branch information
avishekjana committed Jan 31, 2016
1 parent 4428cad commit 3428b82
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions app/models/rscratch/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Rscratch
class Exception < ActiveRecord::Base

if Rails::VERSION::MAJOR == 3
attr_accessible :action, :app_environment, :controller, :exception, :message, :new_occurance_count, :total_occurance_count
attr_accessible :action, :app_environment, :controller, :exception, :message, :new_occurance_count, :total_occurance_count, :status
end

STATUS = %w(new under_development resolved)
Expand All @@ -16,14 +16,15 @@ class Exception < ActiveRecord::Base
validates :controller , presence: true
validates :action , presence: true
validates :app_environment , presence: true
validates :status, presence: true, :inclusion => {:in => STATUS}
validates :status , presence: true, :inclusion => {:in => STATUS}

### => Model Scopes
scope :by_exception, lambda {|exc|where(["exception=?", exc])}
scope :by_message, lambda {|msg|where(["message=?", msg])}
scope :by_controller, lambda {|con|where(["controller=?", con])}
scope :by_action, lambda {|act|where(["action=?", act])}
scope :by_environment, lambda {|env|where(["app_environment=?", env])}
scope :by_status, lambda {|status|where(["status=?", status])}

# => Dynamic methods for exception statuses
STATUS.each do |status|
Expand All @@ -32,15 +33,6 @@ class Exception < ActiveRecord::Base
end
end

# => Dynamically defining these custom finder methods
class << self
STATUS.each do |status|
define_method "#{status}" do
where(["status=?", status])
end
end
end

# Log an exception
def self.log(exc,request)
_exception = self.find_or_add_exception(exc,request.filtered_parameters["controller"].camelize,request.filtered_parameters["action"],Rails.env.camelize)
Expand Down

0 comments on commit 3428b82

Please sign in to comment.