jeremyw-paper_trail 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,10 @@ class CreateVersions < ActiveRecord::Migration
7
7
  t.string :whodunnit
8
8
  t.text :object
9
9
  t.datetime :created_at
10
+ t.integer :user_id, :null => true
10
11
  end
11
12
  add_index :versions, [:item_type, :item_id]
13
+ add_index :versions, :user_id
12
14
  end
13
15
 
14
16
  def self.down
@@ -1,7 +1,25 @@
1
1
  class Version < ActiveRecord::Base
2
2
  belongs_to :item, :polymorphic => true
3
+ belongs_to :user
4
+ before_save :set_user_id
3
5
  validates_presence_of :event
4
6
 
7
+ named_scope :for_disease, lambda { |disease|
8
+ { :joins => :users.
9
+ :conditions => {'users.disease_id' => disease}
10
+ }
11
+ }
12
+
13
+ named_scope :for_item_type, lambda { |item_types|
14
+ { :conditions => { :item_type => item_types } }
15
+ }
16
+
17
+ named_scope :created_after, lambda { |time|
18
+ { :conditions => ['created_at > ?', time] }
19
+ }
20
+
21
+ named_scope :by_created_at_ascending, :order => 'created_at asc'
22
+
5
23
  def reify
6
24
  unless object.nil?
7
25
  # Attributes
@@ -56,4 +74,10 @@ class Version < ActiveRecord::Base
56
74
  :order => 'id ASC').index(self)
57
75
  end
58
76
 
77
+ private
78
+
79
+ def set_user_id
80
+ self.user_id = self.whodunnit.to_i if self.whodunnit.to_s =~ /^\d+$/
81
+ return true
82
+ end
59
83
  end
data/paper_trail.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{paper_trail}
5
- s.version = "1.2.5"
5
+ s.version = "1.2.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andy Stewart", "Jeremy Weiskotten", "Joe Lind"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeremyw-paper_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart