time_scopes 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in time_scopes.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,52 +1,2 @@
1
- require 'rubygems'
2
- require 'rake/gempackagetask'
3
- require 'rake/testtask'
4
-
5
- module TimeScopes
6
- module Version
7
-
8
- MAJOR = 0
9
- MINOR = 1
10
- TINY = 0
11
-
12
- def self.to_s # :nodoc:
13
- [MAJOR, MINOR, TINY].join('.')
14
- end
15
-
16
- end
17
- end
18
-
19
- spec = Gem::Specification.new do |s|
20
- s.name = 'time_scopes'
21
- s.version = TimeScopes::Version.to_s
22
- s.has_rdoc = false
23
- s.extra_rdoc_files = %w(README.rdoc)
24
- s.rdoc_options = %w(--main README.rdoc)
25
- s.summary = "Useful scopes for ActiveRecord based on Date/DateTime columns"
26
- s.author = 'Tomasz Mazur'
27
- s.email = 'defkode@gmail.com'
28
- s.homepage = 'http://trix.pl'
29
- s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
30
- # s.executables = ['trixy_scopes']
31
-
32
- s.add_dependency('activerecord', '~> 3.0.0')
33
- end
34
-
35
- Rake::GemPackageTask.new(spec) do |pkg|
36
- pkg.gem_spec = spec
37
- end
38
-
39
- Rake::TestTask.new do |t|
40
- t.libs << 'test'
41
- t.test_files = FileList["test/**/*_test.rb"]
42
- t.verbose = true
43
- end
44
-
45
- desc 'Generate the gemspec for the Gem (useful when serving from Github)'
46
- task :gemspec do
47
- file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
48
- File.open(file, 'w') {|f| f << spec.to_ruby }
49
- puts "Created gemspec: #{file}"
50
- end
51
-
52
- task :github => :gemspec
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -1 +1,40 @@
1
- require 'time_scopes/time_scopes'
1
+ module TimeScopes
2
+ def self.included(klass)
3
+
4
+ klass.class_eval do
5
+ return unless klass.table_exists?
6
+
7
+ connection = ActiveRecord::Base.connection
8
+ adapter = connection.adapter_name
9
+
10
+ table_name = klass.table_name
11
+ quoted_table_name = klass.quoted_table_name
12
+
13
+ klass.columns.each do |column|
14
+ column_name = column.name
15
+
16
+ quoted_column_name = [quoted_table_name, connection.quote_column_name(column_name)].join(".")
17
+
18
+ if [:date, :datetime].include?(column.type)
19
+ if column_name.last(3) == "_at"
20
+ aliased = column_name.chomp("_at")
21
+
22
+ scope "#{aliased}_today", lambda { where("#{quoted_column_name} > ?", Time.zone.now.beginning_of_day) }
23
+ scope "#{aliased}_yesterday", lambda { where("#{quoted_column_name} BETWEEN ? AND ?", Time.zone.now.yesterday.beginning_of_day, Time.zone.now.yesterday.end_of_day) }
24
+ scope "#{aliased}_between", lambda { |from, to| where("#{quoted_column_name} BETWEEN ? AND ?", from, to) }
25
+ scope "not_#{aliased}_between", lambda { |from, to| where("#{quoted_column_name} NOT BETWEEN ? AND ?", from, to) }
26
+ scope "#{aliased}_before", lambda { |datetime| where("#{quoted_column_name} < ?", datetime) }
27
+ scope "#{aliased}_after", lambda { |datetime| where("#{quoted_column_name} > ?", datetime) }
28
+
29
+ scope "#{aliased}_in_last_week", lambda { where("#{quoted_column_name} > ?", 1.week.ago) }
30
+ scope "#{aliased}_in_last_month", lambda { where("#{quoted_column_name} > ?", 1.month.ago) }
31
+ scope "#{aliased}_in_last_year", lambda { where("#{quoted_column_name} > ?", 1.year.ago) }
32
+ scope "#{aliased}_in_month", lambda { |datetime| where("#{quoted_column_name} BETWEEN ? AND ?", datetime.beginning_of_month, datetime.end_of_month) }
33
+ scope "#{aliased}_in_day", lambda { |datetime| where("#{quoted_column_name} BETWEEN ? AND ?", datetime.beginning_of_day, datetime.end_of_day) }
34
+ scope "#{aliased}_ago", lambda { |period_count, period_type| where("#{quoted_column_name} > ?", period_count.send(period_type).ago) }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module TimeScopes
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "time_scopes/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "time_scopes"
7
+ s.version = TimeScopes::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Tomasz Mazur"]
10
+ s.email = ["defkode@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/time_scopes"
12
+ s.summary = %q{Useful scopes for ActiveRecord based on Date/DateTime columns}
13
+ s.description = %q{Useful scopes for ActiveRecord based on Date/DateTime columns}
14
+
15
+ s.rubyforge_project = "time_scopes"
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
+
22
+ s.add_dependency("activerecord", ">= 3.0.0")
23
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_scopes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tomasz Mazur
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-28 00:00:00 +02:00
18
+ date: 2010-11-05 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  hash: 7
30
30
  segments:
@@ -34,27 +34,29 @@ dependencies:
34
34
  version: 3.0.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
- description:
38
- email: defkode@gmail.com
37
+ description: Useful scopes for ActiveRecord based on Date/DateTime columns
38
+ email:
39
+ - defkode@gmail.com
39
40
  executables: []
40
41
 
41
42
  extensions: []
42
43
 
43
- extra_rdoc_files:
44
- - README.rdoc
44
+ extra_rdoc_files: []
45
+
45
46
  files:
46
- - README.rdoc
47
+ - .gitignore
48
+ - Gemfile
47
49
  - Rakefile
48
- - lib/time_scopes/time_scopes.rb
49
50
  - lib/time_scopes.rb
51
+ - lib/time_scopes/version.rb
52
+ - time_scopes.gemspec
50
53
  has_rdoc: true
51
- homepage: http://trix.pl
54
+ homepage: http://rubygems.org/gems/time_scopes
52
55
  licenses: []
53
56
 
54
57
  post_install_message:
55
- rdoc_options:
56
- - --main
57
- - README.rdoc
58
+ rdoc_options: []
59
+
58
60
  require_paths:
59
61
  - lib
60
62
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
79
  version: "0"
78
80
  requirements: []
79
81
 
80
- rubyforge_project:
82
+ rubyforge_project: time_scopes
81
83
  rubygems_version: 1.3.7
82
84
  signing_key:
83
85
  specification_version: 3
@@ -1,25 +0,0 @@
1
- == TrixyScopes
2
-
3
- Useful scopes for ActiveRecord based on Date/DateTime columns
4
-
5
-
6
- == Installation
7
-
8
-
9
- gem install time_scopes
10
-
11
-
12
- include TimeScopes module into your ActiveRecord model:
13
-
14
-
15
- class Product < ActiveRecord::Base
16
-
17
- include TimeScopes
18
-
19
- (...)
20
-
21
- end
22
-
23
- == Copyright
24
-
25
- Copyright (c) 2010 Tomasz Mazur, released under the MIT license
@@ -1,42 +0,0 @@
1
- module TimeScopes
2
-
3
- def self.included(klass)
4
-
5
- klass.class_eval do
6
- return unless klass.table_exists?
7
-
8
- connection = ActiveRecord::Base.connection
9
- adapter = connection.adapter_name
10
-
11
- table_name = klass.table_name
12
- quoted_table_name = klass.quoted_table_name
13
-
14
- klass.columns.each do |column|
15
- column_name = column.name
16
-
17
- quoted_column_name = [quoted_table_name, connection.quote_column_name(column_name)].join(".")
18
-
19
- if column.type == :datetime
20
- if column_name.last(3) == "_at"
21
- aliased = column_name.chomp("_at")
22
-
23
- scope "#{aliased}_today", lambda { where("#{quoted_column_name} > ?", Time.zone.now.beginning_of_day) }
24
- scope "#{aliased}_yesterday", lambda { where("#{quoted_column_name} BETWEEN ? AND ?", Time.zone.now.yesterday.beginning_of_day, Time.zone.now.yesterday.end_of_day) }
25
- scope "#{aliased}_between", lambda { |from, to| where("#{quoted_column_name} BETWEEN ? AND ?", from, to) }
26
- scope "not_#{aliased}_between", lambda { |from, to| where("#{quoted_column_name} NOT BETWEEN ? AND ?", from, to) }
27
- scope "#{aliased}_before", lambda { |datetime| where("#{quoted_column_name} < ?", datetime) }
28
- scope "#{aliased}_after", lambda { |datetime| where("#{quoted_column_name} > ?", datetime) }
29
-
30
- scope "#{aliased}_in_last_week", lambda { where("#{quoted_column_name} > ?", 1.week.ago) }
31
- scope "#{aliased}_in_last_month", lambda { where("#{quoted_column_name} > ?", 1.month.ago) }
32
- scope "#{aliased}_in_last_year", lambda { where("#{quoted_column_name} > ?", 1.year.ago) }
33
- scope "#{aliased}_in_month", lambda { |datetime| where("#{quoted_column_name} BETWEEN ? AND ?", datetime.beginning_of_month, datetime.end_of_month) }
34
- scope "#{aliased}_in_day", lambda { |datetime| where("#{quoted_column_name} BETWEEN ? AND ?", datetime.beginning_of_day, datetime.end_of_day) }
35
- scope "#{aliased}_ago", lambda { |period_count, period_type| where("#{quoted_column_name} > ?", period_count.send(period_type).ago) }
36
- end
37
- end
38
- end
39
- end
40
-
41
- end
42
- end