today 0.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/lib/today/active_record.rb +34 -0
- data/lib/today/array.rb +42 -0
- data/lib/today/version.rb +3 -0
- data/lib/today.rb +7 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/data.rb +4 -0
- data/spec/support/models.rb +3 -0
- data/spec/support/schema.rb +8 -0
- data/spec/today/active_record_spec.rb +40 -0
- data/spec/today/array_spec.rb +82 -0
- data/spec/today.sqlite3 +0 -0
- data/today.gemspec +27 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3940204e3ad8cb39960767946b482334a1459957
|
4
|
+
data.tar.gz: 822e45a2be7adce0ae955dd4ebcfa74e8aaa8b36
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8121bee4acb154bf1ce841eae25e7a65170f5d2c98c8760c2bbb13465c932960f673af0d223d48c67d528f5f2b8f3629a486192cb4d195977156ea72e80f7919
|
7
|
+
data.tar.gz: dd3b653d29d3ed6aa967cb2342936f04cd27e453d3996d047f580ad9972dc80b5b19dbab557c6d1e4719c27b7d660baf9ec3e66031eba1f82598e8b0c57a07ad
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kim,SeongJun
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Today
|
2
|
+
|
3
|
+
Easy fetch today's happen from database, array
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'today'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install today
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
###ActiveRecord
|
21
|
+
Post.today
|
22
|
+
Post.today(:updated_at)
|
23
|
+
Post.today(:created_at, Time.now)
|
24
|
+
Post.today(at: Time.now)
|
25
|
+
Post.today(key: updated_at, at: Time.now)
|
26
|
+
###Array
|
27
|
+
Post.all.to_a.today
|
28
|
+
Post.all.to_a.today(:updated_at)
|
29
|
+
Post.all.to_a.today(:created_at, Time.now)
|
30
|
+
Post.all.to_a.today(at: Time.now)
|
31
|
+
Post.all.to_a.today(key: updated_at, at: Time.now)
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/today/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
|
4
|
+
module Today
|
5
|
+
module ActiveRecord
|
6
|
+
# usage
|
7
|
+
# today
|
8
|
+
# today(:updated_at)
|
9
|
+
# today(:created_at, Time.now)
|
10
|
+
# today(at: Time.now)
|
11
|
+
# today(key: updated_at, at: Time.now)
|
12
|
+
def today *argv
|
13
|
+
if argv.first.is_a? Hash
|
14
|
+
key = argv[0][:key] || :created_at
|
15
|
+
at = argv[0][:at] || Date.today
|
16
|
+
else
|
17
|
+
key = argv[0] || :created_at
|
18
|
+
at = argv[1] || Date.today
|
19
|
+
end
|
20
|
+
|
21
|
+
where("DATE(#{key.to_s}) = DATE(?)", at)
|
22
|
+
end
|
23
|
+
|
24
|
+
def yesterday key=:created_at
|
25
|
+
at = Date.today - 1
|
26
|
+
today(key, at)
|
27
|
+
end
|
28
|
+
|
29
|
+
def tomorrow key=:created_at
|
30
|
+
at = Date.today + 1
|
31
|
+
today(key, at)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/today/array.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Today
|
4
|
+
module Array
|
5
|
+
|
6
|
+
# usage
|
7
|
+
# today
|
8
|
+
# today(:updated_at)
|
9
|
+
# today(:created_at, Time.now)
|
10
|
+
# today(at: Time.now)
|
11
|
+
# today(key: updated_at, at: Time.now)
|
12
|
+
def today *argv
|
13
|
+
if argv.first.is_a? Hash
|
14
|
+
key = argv[0][:key] || :created_at
|
15
|
+
at = argv[0][:at] || Date.today
|
16
|
+
else
|
17
|
+
key = argv[0] || :created_at
|
18
|
+
at = argv[1] || Date.today
|
19
|
+
end
|
20
|
+
|
21
|
+
return self if self.length == 0
|
22
|
+
|
23
|
+
self.select do |elem|
|
24
|
+
if elem.is_a? Hash
|
25
|
+
Date.parse(elem[key].to_s) == at
|
26
|
+
else
|
27
|
+
Date.parse(elem.send(key).to_s) == at
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def yesterday key=:created_at
|
33
|
+
at = Date.today - 1
|
34
|
+
today(key, at)
|
35
|
+
end
|
36
|
+
|
37
|
+
def tomorrow key=:created_at
|
38
|
+
at = Date.today + 1
|
39
|
+
today(key, at)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/today.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
Post.create(id: 1, created_at: Date.today, updated_at: Date.today-1)
|
2
|
+
Post.create(id: 2, created_at: Date.today-1, updated_at: Date.today)
|
3
|
+
Post.create(id: 3, created_at: Date.today, updated_at: Date.today-1)
|
4
|
+
Post.create(id: 4, created_at: Date.today-1, updated_at: Date.today)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
ActiveRecord::Base
|
3
|
+
.establish_connection(
|
4
|
+
adapter: "sqlite3",
|
5
|
+
database: File.dirname(__FILE__) + "/../today.sqlite3"
|
6
|
+
)
|
7
|
+
|
8
|
+
load File.dirname(__FILE__) + '/../support/schema.rb'
|
9
|
+
load File.dirname(__FILE__) + '/../support/data.rb'
|
10
|
+
|
11
|
+
describe Today do
|
12
|
+
describe ActiveRecord do
|
13
|
+
context :today do
|
14
|
+
it "shoud return created_at today objects" do
|
15
|
+
Post.today.ids.should == Post.where(id: [1, 3]).ids
|
16
|
+
Post.today.count.should == 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "shoud return updated_at today objects" do
|
20
|
+
Post.today(:updated_at).ids.should == Post.where(id: [2, 4]).ids
|
21
|
+
Post.today(:updated_at).count.should == 2
|
22
|
+
end
|
23
|
+
|
24
|
+
it "shoud return created_at yesterday objects" do
|
25
|
+
at = Date.today - 1
|
26
|
+
Post.today(at: at).ids.should == Post.where(id: [2, 4]).ids
|
27
|
+
Post.today.count.should == 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context :yesterday do
|
32
|
+
it "shoud return created_at yesterday objects" do
|
33
|
+
Post.yesterday.ids.should == Post.where(id: [2, 4]).ids
|
34
|
+
Post.yesterday.count.should == 2
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
class Something
|
4
|
+
attr_accessor :id, :created_at
|
5
|
+
def initialize id, created_at
|
6
|
+
@id = id
|
7
|
+
@created_at = created_at
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Today do
|
12
|
+
describe Array do
|
13
|
+
let :today do
|
14
|
+
Date.today
|
15
|
+
end
|
16
|
+
let :yesterday do
|
17
|
+
Date.today - 1
|
18
|
+
end
|
19
|
+
context "#today" do
|
20
|
+
it "should return only today hash array" do
|
21
|
+
arr = [
|
22
|
+
{ id: 1, created_at: yesterday },
|
23
|
+
{ id: 2, created_at: today },
|
24
|
+
{ id: 3, created_at: yesterday },
|
25
|
+
{ id: 4, created_at: today },
|
26
|
+
]
|
27
|
+
arr.today.should == [
|
28
|
+
{ id: 2, created_at: today },
|
29
|
+
{ id: 4, created_at: today }
|
30
|
+
]
|
31
|
+
|
32
|
+
arr.today(at: yesterday).should == [
|
33
|
+
{ id: 1, created_at: yesterday },
|
34
|
+
{ id: 3, created_at: yesterday }
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return empty array" do
|
39
|
+
[].today.should == []
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return object array" do
|
43
|
+
today_list = [
|
44
|
+
Something.new(1, today),
|
45
|
+
Something.new(2, yesterday),
|
46
|
+
Something.new(3, today),
|
47
|
+
Something.new(4, yesterday)
|
48
|
+
].today
|
49
|
+
today_list[0].id.should == 1
|
50
|
+
today_list[1].id.should == 3
|
51
|
+
today_list.length.should == 2
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should raise error when could't find by key" do
|
56
|
+
expect do
|
57
|
+
[
|
58
|
+
Something.new(1, today),
|
59
|
+
Something.new(2, yesterday),
|
60
|
+
Something.new(3, today),
|
61
|
+
Something.new(4, yesterday)
|
62
|
+
].today(:updated_at)
|
63
|
+
end.to raise_error
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context '#yesterday' do
|
68
|
+
it "should return only yesterday hash array" do
|
69
|
+
yesterday_list = [
|
70
|
+
Something.new(1, today),
|
71
|
+
Something.new(2, yesterday),
|
72
|
+
Something.new(3, today),
|
73
|
+
Something.new(4, yesterday)
|
74
|
+
].yesterday
|
75
|
+
yesterday_list[0].id.should == 2
|
76
|
+
yesterday_list[1].id.should == 4
|
77
|
+
yesterday_list.length.should == 2
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/spec/today.sqlite3
ADDED
Binary file
|
data/today.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'today/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "today"
|
8
|
+
spec.version = Today::VERSION
|
9
|
+
spec.authors = ["Kim,SeongJun"]
|
10
|
+
spec.email = ["me@kimseongjun.co.kr"]
|
11
|
+
spec.summary = %q{Easy fetch today's happen from database, array}
|
12
|
+
spec.description = %q{Easy fetch today's happen from database, array}
|
13
|
+
spec.homepage = "https://github.com/victorkim/today"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'activerecord', '~> 4.0.1'
|
24
|
+
spec.add_development_dependency "sqlite3-ruby"
|
25
|
+
spec.add_development_dependency 'rspec', '~> 2.4'
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: today
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kim,SeongJun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.0.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3-ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.4'
|
83
|
+
description: Easy fetch today's happen from database, array
|
84
|
+
email:
|
85
|
+
- me@kimseongjun.co.kr
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/today.rb
|
96
|
+
- lib/today/active_record.rb
|
97
|
+
- lib/today/array.rb
|
98
|
+
- lib/today/version.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
- spec/support/data.rb
|
101
|
+
- spec/support/models.rb
|
102
|
+
- spec/support/schema.rb
|
103
|
+
- spec/today.sqlite3
|
104
|
+
- spec/today/active_record_spec.rb
|
105
|
+
- spec/today/array_spec.rb
|
106
|
+
- today.gemspec
|
107
|
+
homepage: https://github.com/victorkim/today
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.2.0
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Easy fetch today's happen from database, array
|
131
|
+
test_files:
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/support/data.rb
|
134
|
+
- spec/support/models.rb
|
135
|
+
- spec/support/schema.rb
|
136
|
+
- spec/today.sqlite3
|
137
|
+
- spec/today/active_record_spec.rb
|
138
|
+
- spec/today/array_spec.rb
|
139
|
+
has_rdoc:
|