created-and-updated-by 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -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.0.1"
8
+ s.version = "0.1.0"
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,34 +1,20 @@
1
- module CreatedAndUpdatedBy
2
-
1
+ module CreatedAndUpdatedBy
3
2
  class Stamper
4
3
  cattr_accessor :stampable, :attribute
5
4
  def self.attach(stamp_model = User, stamp_attribute = :current)
6
5
  raise ArgumentError, "#{stamp_model.name} does not respond to #{stamp_attribute}" unless stamp_model.respond_to?(stamp_attribute)
7
6
  self.stampable, self.attribute = stamp_model, stamp_attribute
8
- ActiveRecord::Base.extend CreatedAndUpdatedBy
9
- ActiveRecord::Base.send(:acts_as_stampable)
7
+ ActiveRecord::Base.send(:include, CreatedAndUpdatedBy)
10
8
  end
11
9
  end
12
-
13
- def acts_as_stampable
14
- class_eval do
15
- send :include, InstanceMethods
16
- before_validation :set_stamps
17
- belongs_to :updated_by, :class_name => CreatedAndUpdatedBy::Stamper.stampable.name
18
- belongs_to :created_by, :class_name => CreatedAndUpdatedBy::Stamper.stampable.name
19
- end
20
- end
21
-
22
- module InstanceMethods
10
+ class_eval do
23
11
  def stamper
24
12
  CreatedAndUpdatedBy::Stamper.stampable.send(CreatedAndUpdatedBy::Stamper.attribute)
25
13
  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
26
16
  def set_stamps
27
- if stamper && respond_to?(:created_by_id) && respond_to?(:updated_by_id)
28
- self.created_by ||= stamper
29
- self.updated_by = stamper
30
- end
17
+ self.created_by_id ||= self.updated_by_id = stamper.id if stamper && respond_to?(:created_by_id) && respond_to?(:updated_by_id)
31
18
  end
32
- end
33
-
19
+ end
34
20
  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.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Daniels