created-and-updated-by 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{created-and-updated-by}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Daniels"]
@@ -1,4 +1,4 @@
1
- module CreatedAndUpdatedBy
1
+ module CreatedAndUpdatedBy
2
2
  class Stamper
3
3
  cattr_accessor :stampable, :attribute
4
4
  def self.attach(stamp_model = User, stamp_attribute = :current)
@@ -7,14 +7,18 @@ module CreatedAndUpdatedBy
7
7
  ActiveRecord::Base.send(:include, CreatedAndUpdatedBy)
8
8
  end
9
9
  end
10
- class_eval do
11
- def stamper
12
- CreatedAndUpdatedBy::Stamper.stampable.send(CreatedAndUpdatedBy::Stamper.attribute)
10
+ def self.included(base)
11
+ base.class_eval do
12
+ send :include, InstanceMethods
13
+ before_validation :set_stamps
14
+ belongs_to :updated_by, :class_name => CreatedAndUpdatedBy::Stamper.stampable.name
15
+ belongs_to :created_by, :class_name => CreatedAndUpdatedBy::Stamper.stampable.name
13
16
  end
14
- def updated_by; CreatedAndUpdatedBy::Stamper.stampable.find(updated_by_id); end
15
- def created_by; CreatedAndUpdatedBy::Stamper.stampable.find(updated_by_id); end
17
+ end
18
+ module InstanceMethods
19
+ def stamper; CreatedAndUpdatedBy::Stamper.stampable.send(CreatedAndUpdatedBy::Stamper.attribute); end
16
20
  def set_stamps
17
- self.created_by_id ||= self.updated_by_id = stamper.id if stamper && respond_to?(:created_by_id) && respond_to?(:updated_by_id)
21
+ self.created_by ||= self.updated_by = stamper if stamper && respond_to?(:created_by_id) && respond_to?(:updated_by_id)
18
22
  end
19
- end
23
+ end
20
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: created-and-updated-by
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Daniels