timequery 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a976cfe859af2b42f18581035cbbf1436e2bc3c5
4
+ data.tar.gz: 7b2e226f67fca1fbcda090a9df22b045d6bff9ac
5
+ SHA512:
6
+ metadata.gz: ed2b4339890c7f50959b13a4c55a80b39f8c36f629945d75f7c35401a8276d8f34032c635eda8fa150d62da93c39a25c9e02176bb931be4ace8753f62a0a3843
7
+ data.tar.gz: fdb91f28c2bd3ad181d680d12ed27d428af7838830732dcfbefe46fc87afc8388610e2b897ecafe4ca471a2be9f637fe42267cab356eebf020adf0e2cb4a0621
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 mars
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Timequery
2
+ time range query
3
+
4
+ ## Usage
5
+ auto extend below methods on ActiveRecord::Base
6
+ ```
7
+ between_range_column column_name, begin_at, end_at
8
+ day_range_column column_name, time = Time.current
9
+ week_range_column column_name, time = Time.current
10
+ month_range_column column_name, time = Time.current
11
+ year_range_column column_name, time = Time.current
12
+ ```
13
+
14
+ ## Installation
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'timequery', github: 'wuyuedefeng/timequery'
19
+ ```
20
+
21
+ And then execute:
22
+ ```bash
23
+ $ bundle
24
+ ```
25
+
26
+ Or install it yourself as:
27
+ ```bash
28
+ $ gem install timequery
29
+ ```
30
+
31
+ ## Contributing
32
+ Contribution directions go here.
33
+
34
+ ## License
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Timequery'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :timequery do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,3 @@
1
+ module Timequery
2
+ VERSION = '0.1.0'
3
+ end
data/lib/timequery.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Timequery
2
+
3
+ module ClassMethods
4
+ def between_range_column column_name, begin_at, end_at
5
+ self.where("#{self.table_name}.#{column_name} BETWEEN ? AND ?", begin_at, end_at)
6
+ end
7
+
8
+ def day_range_column column_name, time = Time.current
9
+ between_range_column(column_name, time.beginning_of_day, time.end_of_day)
10
+ end
11
+
12
+ def week_range_column column_name, time = Time.current
13
+ between_range_column(column_name, time.beginning_of_week, time.end_of_week)
14
+ end
15
+
16
+ def month_range_column column_name, time = Time.current
17
+ between_range_column(column_name, time.beginning_of_month, time.end_of_month)
18
+ end
19
+
20
+ def year_range_column column_name, time = Time.current
21
+ between_range_column(column_name, time.beginning_of_year, time.end_of_year)
22
+ end
23
+ end
24
+
25
+ # module InstanceMethods
26
+ # end
27
+
28
+ def self.included klass
29
+ klass.send :extend, ClassMethods
30
+ # klass.send :include, InstanceMethods
31
+ end
32
+ end
33
+
34
+ class ActiveRecord::Base
35
+ include Timequery
36
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timequery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mars
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-07 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: 5.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
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
+ description: time model range query.
42
+ email:
43
+ - 578595193@qq.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/tasks/timequery_tasks.rake
52
+ - lib/timequery.rb
53
+ - lib/timequery/version.rb
54
+ homepage: https://github.com/wuyuedefeng/timequery
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.6.13
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: time model range query.
78
+ test_files: []