stampable 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
- Gemfile.lock
4
3
  pkg/*
5
4
  .idea/*
5
+ Gemfile.lock
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- Stampable gem
2
- =============
1
+ Stampable gem [![Build Status](https://secure.travis-ci.org/anandagrawal84/stampable.png?branch=master)](http://travis-ci.org/anandagrawal84/stampable)
2
+ =====================
3
3
 
4
4
  Overview
5
- --------
5
+ ---------
6
6
 
7
7
  The Stampable gem is used to stamp ActiveRecord model with current user. This is a simple gem that stores who modified/created the record in a single field.
8
8
 
@@ -58,3 +58,9 @@ To specify a default user add following
58
58
  ```ruby
59
59
  Stampable::Base.config = {:default_user => 'robot'}
60
60
  ```
61
+
62
+ To skip the modification of stampable fields by some particular users, ex default is background_job
63
+
64
+ ```ruby
65
+ Stampable::Base.config = {:except_user_list => ['background_job','user1']}
66
+ ```
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -5,7 +5,7 @@ module Stampable
5
5
  end
6
6
 
7
7
  def self.config
8
- @config || {:stamp_field => :modified_by}
8
+ @config || {:stamp_field => :modified_by, :except_user_list => ['background_job']}
9
9
  end
10
10
 
11
11
  def self.included(klass)
@@ -15,6 +15,7 @@ module Stampable
15
15
  def set_modified_by
16
16
  return unless changed?
17
17
  user_name = Thread.current['current_user'] || Stampable::Base.config[:default_user]
18
+ return if Stampable::Base.config[:except_user_list].include?(user_name)
18
19
  stamp_writer = (Stampable::Base.config[:stamp_field].to_s + '=').to_sym
19
20
  send(stamp_writer, user_name) if respond_to?(stamp_writer)
20
21
  end
@@ -1,3 +1,3 @@
1
1
  module Stampable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -73,4 +73,17 @@ describe Stampable do
73
73
  model.touched_by.should == 'user'
74
74
  model.modified_by.should == nil
75
75
  end
76
+
77
+ it 'should not update the user if it belongs to except user list' do
78
+ Stampable::Base.config.merge({:except_user_list=>["job"]})
79
+
80
+ model = ActiveRecordModel.new
81
+ model.modified_by = 'some user'
82
+ Thread.current['current_user'] = 'job'
83
+
84
+ model.invoke_before_save
85
+
86
+ model.modified_by.should == 'some user'
87
+ end
88
+
76
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stampable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-23 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70299779041960 !ruby/object:Gem::Requirement
16
+ requirement: &70098752699180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70299779041960
24
+ version_requirements: *70098752699180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70299779041480 !ruby/object:Gem::Requirement
27
+ requirement: &70098752698200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70299779041480
35
+ version_requirements: *70098752698200
36
36
  description: Stamp any ActiveRecord model with last created/updated by
37
37
  email:
38
38
  - anand.agrawal84@gmail.com
@@ -42,7 +42,9 @@ extensions: []
42
42
  extra_rdoc_files: []
43
43
  files:
44
44
  - .gitignore
45
+ - .travis.yml
45
46
  - Gemfile
47
+ - Gemfile.lock
46
48
  - README.md
47
49
  - Rakefile
48
50
  - lib/stampable.rb
@@ -62,18 +64,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
64
  - - ! '>='
63
65
  - !ruby/object:Gem::Version
64
66
  version: '0'
65
- segments:
66
- - 0
67
- hash: -1196288843142832157
68
67
  required_rubygems_version: !ruby/object:Gem::Requirement
69
68
  none: false
70
69
  requirements:
71
70
  - - ! '>='
72
71
  - !ruby/object:Gem::Version
73
72
  version: '0'
74
- segments:
75
- - 0
76
- hash: -1196288843142832157
77
73
  requirements: []
78
74
  rubyforge_project: stampable
79
75
  rubygems_version: 1.8.12