acts_as_expirable 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b899168c5eb93007211f94db8bb907b43eb629c9
4
+ data.tar.gz: a0975e616f04ec8409f158d007ecbf958ac86ead
5
+ SHA512:
6
+ metadata.gz: 751c14d25cfd54b0484ef5782412ebfadf8981918fc7070da93a7894e214cf3826b07ef8cf022d24f409e813e1d26e46cc2fbef94263f3515368f368555591fb
7
+ data.tar.gz: 9d45a7a348d6a0c3dec36704cd2bbf8864a0cc31b9ae682c537254427dd5150b60d625c09c9935b6d4529a46abe07762f27babd81c13568ef43b796864c71956
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ Gemfile.lock
11
+
12
+ *.swp
13
+ *.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Default: run acts_as_expirable unit tests.'
5
+ task :default => :test
6
+
7
+ desc 'Test the acts_as_expirable plugin.'
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.pattern = 'test/**/*_test.rb'
11
+ t.verbose = true
12
+ end
@@ -0,0 +1,24 @@
1
+ $:.push File.dirname(__FILE__) + '/lib'
2
+ require 'acts_as_expirable/version'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = %q{acts_as_expirable}
6
+ gem.authors = ["Jeff Ching"]
7
+ gem.date = %q{2012-10-15}
8
+ gem.description = %q{With ActsAsExpirable, you can mark ActiveRecord records as expired and programmatically find expired record.}
9
+ gem.summary = "Basic expiry for Rails."
10
+ gem.email = %q{ching.jeff@gmail.com}
11
+ gem.homepage = 'http://github.com/chingor13/acts_as_expirable'
12
+ gem.license = 'MIT'
13
+
14
+ gem.add_runtime_dependency 'rails', '>= 3.0'
15
+ gem.add_development_dependency 'sqlite3'
16
+ gem.add_development_dependency 'mysql2', '~> 0.3.7'
17
+
18
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ gem.files = `git ls-files`.split("\n")
20
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ gem.name = "acts_as_expirable"
22
+ gem.require_paths = ['lib']
23
+ gem.version = ActsAsExpirable::VERSION
24
+ end
@@ -0,0 +1,2 @@
1
+ require 'acts_as_expirable/expirable'
2
+ ActiveRecord::Base.send(:include, ActsAsExpirable)
@@ -0,0 +1,84 @@
1
+ module ActsAsExpirable
2
+ def self.included(base)
3
+ base.extend(ClassMethods)
4
+ end
5
+
6
+ def self.cleanup!
7
+ expirable_classes.each do |klass|
8
+ klass.unscoped.destroy_expired
9
+ end
10
+ end
11
+
12
+ def self.expirable_classes
13
+ @expirable_classes ||= []
14
+ end
15
+
16
+ def self.register_expirable(klass)
17
+ @expirable_classes ||= []
18
+ @expirable_classes << klass
19
+ end
20
+
21
+ module ClassMethods
22
+ def acts_as_expirable(options = {})
23
+ ActsAsExpirable.register_expirable(self)
24
+
25
+ configuration = { :column => "expires_at" }
26
+ configuration.update(options) if options.is_a?(Hash)
27
+
28
+ class_eval %{
29
+ include ActsAsExpirable::InstanceMethods
30
+
31
+ scope :expired, where('#{configuration[:column]} <= UTC_TIMESTAMP()')
32
+ scope :unexpired, where('#{configuration[:column]} IS NULL OR #{configuration[:column]} > UTC_TIMESTAMP()')
33
+
34
+ class << self
35
+ def expiry_column
36
+ '#{configuration[:column]}'
37
+ end
38
+
39
+ def destroy_expired
40
+ expired.destroy_all
41
+ end
42
+
43
+ def delete_expired
44
+ expired.delete_all
45
+ end
46
+
47
+ def default_scope
48
+ unexpired
49
+ end
50
+ end
51
+ }
52
+
53
+ case configuration[:default]
54
+ when Proc
55
+ before_validation configuration[:default], :on => :create do
56
+ write_attribute(configuration[:column], configuration[:default].call(self)) if read_attribute(configuration[:column]).nil?
57
+ true
58
+ end
59
+ when NilClass
60
+ else
61
+ before_validation :on => :create do
62
+ write_attribute(configuration[:column], configuration[:default]) if read_attribute(configuration[:column]).nil?
63
+ true
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ module InstanceMethods
70
+ def expire
71
+ write_attribute(self.class.expiry_column, Time.now)
72
+ end
73
+
74
+ def expire!
75
+ update_attribute(self.class.expiry_column, Time.now)
76
+ end
77
+
78
+ def expired?
79
+ expire_time = read_attribute(self.class.expiry_column)
80
+ return false if expire_time.nil?
81
+ expire_time <= Time.now
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module ActsAsExpirable
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_expirable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Ching
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2012-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mysql2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.7
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.7
55
+ description: With ActsAsExpirable, you can mark ActiveRecord records as expired and
56
+ programmatically find expired record.
57
+ email: ching.jeff@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Rakefile
65
+ - acts_as_expirable.gemspec
66
+ - lib/acts_as_expirable.rb
67
+ - lib/acts_as_expirable/expirable.rb
68
+ - lib/acts_as_expirable/version.rb
69
+ homepage: http://github.com/chingor13/acts_as_expirable
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Basic expiry for Rails.
93
+ test_files: []