date_scopable 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in date_scopable.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "date_scopable/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "date_scopable"
7
+ s.version = DateScopable::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Anton Zolotov"]
10
+ s.email = ["anton@zolotov.eu"]
11
+ s.homepage = "https://github.com/azolotov/date_scopable"
12
+ s.summary = %q{Convenient scopes for retrieving ActiveRecord models by date}
13
+ s.description = %q{Convenient scopes for retrieving ActiveRecord models by date}
14
+
15
+ s.rubyforge_project = "date_scopable"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,74 @@
1
+ module DateScopable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ ##
6
+ # Date Scopes
7
+ #
8
+ # returns all objects created on a specific day or
9
+ # within a specific range of days
10
+ #
11
+ # User.today
12
+ # User.yesterday
13
+ # User.on Date.parse("4/7/2011")
14
+ # User.last_7_days
15
+ # User.last_month
16
+ # User.between(Date.parse("4/1/2011"), Date.parse("4/5/2011"))
17
+ #
18
+ # Usage: Ensure that the path to this module is autoloadable in
19
+ # config/application.rb
20
+ #
21
+ # config.autoload_paths += %W(#{Rails.root}/lib)
22
+ #
23
+ # then, include it in your models
24
+ #
25
+ # class User < ActiveRecord::Base
26
+ # include DateScopable
27
+ #
28
+ # # ...
29
+ # end
30
+
31
+ ##
32
+ # Show all objects created today
33
+ #
34
+ scope :today, lambda {
35
+ where("created_at > ?", Time.now.beginning_of_day)
36
+ }
37
+
38
+ ##
39
+ # Show all objects created yesterday
40
+ #
41
+ scope :yesterday, lambda {
42
+ where("created_at > ? AND created_at < ?", Date.yesterday.beginning_of_day, Date.yesterday.end_of_day)
43
+ }
44
+
45
+ ##
46
+ # Show all objects created on a specific day
47
+ #
48
+ scope :on, lambda { |day|
49
+ where("created_at > ? AND created_At < ?", day.beginning_of_day, day.end_of_day)
50
+ }
51
+
52
+ ##
53
+ # Show all objects created in the last seven days
54
+ #
55
+ scope :last_7_days, lambda {
56
+ where("created_at > ?", 1.week.ago.beginning_of_day)
57
+ }
58
+
59
+ ##
60
+ # Show all objects created last month
61
+ #
62
+ scope :last_month, lambda {
63
+ where("created_at > ?", 1.month.ago.beginning_of_day)
64
+ }
65
+
66
+ ##
67
+ # show all objects created between two specific days
68
+ #
69
+ scope :between, lambda { |start, finish|
70
+ where("created_at > ? AND created_at < ?", start.beginning_of_day, finish.end_of_day)
71
+ }
72
+ end
73
+
74
+ end
@@ -0,0 +1,3 @@
1
+ module DateScopable
2
+ VERSION = "0.0.2"
3
+ end
data/readme.md ADDED
@@ -0,0 +1,26 @@
1
+ ## DateScopable
2
+
3
+ DateScopable provides convenient scopes for Rails ActiveRecord models:
4
+
5
+ User.today
6
+ User.yesterday
7
+ User.on Date.parse("4/7/2011")
8
+ User.last_7_days
9
+ User.last_month
10
+ User.between(Date.parse("4/1/2011"), Date.parse("4/5/2011"))
11
+
12
+ ## Usage
13
+
14
+ # Gemfile
15
+ gem "date_scopable"
16
+
17
+ $ bundle install
18
+
19
+ # In your models
20
+ class User < ActiveRecord::Base
21
+ include DateScopable
22
+
23
+ # the rest of your model
24
+ end
25
+
26
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: date_scopable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Anton Zolotov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-25 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Convenient scopes for retrieving ActiveRecord models by date
23
+ email:
24
+ - anton@zolotov.eu
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - date_scopable.gemspec
36
+ - lib/date_scopable.rb
37
+ - lib/date_scopable/version.rb
38
+ - readme.md
39
+ has_rdoc: true
40
+ homepage: https://github.com/azolotov/date_scopable
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: date_scopable
69
+ rubygems_version: 1.5.0
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Convenient scopes for retrieving ActiveRecord models by date
73
+ test_files: []
74
+