shibaraku 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +64 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/shibaraku.rb +6 -0
- data/lib/shibaraku/active_record_ext.rb +72 -0
- data/lib/shibaraku/version.rb +3 -0
- data/shibaraku.gemspec +27 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 723c458eb55e34fe194391b5928d7e5f43c5b1e0
|
4
|
+
data.tar.gz: f56f79deef90c18ecce1436feb637aa3467eb8f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5b2674a7e33a7a5b32d4176139e25b735b04b9eba6d158a2e3e12b03a5f0b853ff6b49635f2157c3ab090ad86aded6329dbc3320b77c6fea63ab09121055f16
|
7
|
+
data.tar.gz: 01c8a21e0e3ea91c22ca208dce953097b6553ca80c5d188617d8a55b6d788275599cd32461ef2d15a45bb919d67cb3801663c615e09004466337a52c92d4b387
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
## Shibaraku master (unreleased)
|
2
|
+
[full changelog](https://github.com/onk/shibaraku/compare/v1.1.0...master)
|
3
|
+
|
4
|
+
|
5
|
+
## Shibaraku v1.1.0 (2015-10-18)
|
6
|
+
[full changelog](https://github.com/onk/shibaraku/compare/v0.0.4...v1.1.0)
|
7
|
+
|
8
|
+
* rubygems.org に公開するため歴史を改ざん
|
9
|
+
* `bundle gem shibaraku` をやり直して最新に追随した
|
10
|
+
|
11
|
+
|
12
|
+
## Shibaraku v0.0.4 (2015-03-06)
|
13
|
+
[full changelog](https://github.com/onk/shibaraku/compare/v0.0.3...v0.0.4)
|
14
|
+
|
15
|
+
* `.in_time` および `#in_time?` の第一引数(`user`) を省略可能にした
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Campaign.in_time
|
19
|
+
# => select start_at <= now < end_at records
|
20
|
+
|
21
|
+
Campaign.in_time(normal_user)
|
22
|
+
# => select start_at <= now < end_at records
|
23
|
+
|
24
|
+
Campaign.in_time(super_user)
|
25
|
+
# => select test_start_at <= now < test_end_at records
|
26
|
+
```
|
27
|
+
|
28
|
+
|
29
|
+
## Shibaraku v0.0.3 (2014-12-16)
|
30
|
+
[full changelog](https://github.com/onk/shibaraku/compare/v0.0.2...v0.0.3)
|
31
|
+
|
32
|
+
* カラム名が `start_at` / `end_at` 決め打ちだったので、`started_at` 等をオプションで渡せるようにした
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class Event
|
36
|
+
shibaraku start_at: :started_at, end_at: :ended_at
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
* 運営ユーザは test_start_at を見る、という運用に対応した
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
Campaign.in_time(normal_user)
|
44
|
+
# => select start_at <= now < end_at records
|
45
|
+
|
46
|
+
Campaign.in_time(super_user)
|
47
|
+
# => select test_start_at <= now < test_end_at records
|
48
|
+
```
|
49
|
+
|
50
|
+
**Breaking Change**
|
51
|
+
メソッドの第1引数に `super_user?` が呼べるオブジェクトを渡すように変更しました。
|
52
|
+
全体的にアプリケーション側のコードの修正が必要です。
|
53
|
+
|
54
|
+
|
55
|
+
## Shibaraku v0.0.2 (2014-12-05)
|
56
|
+
|
57
|
+
[full changelog](https://github.com/onk/shibaraku/compare/v0.0.1...v0.0.2)
|
58
|
+
|
59
|
+
* 終了時刻の 00:00 は分かりづらいので前日の 23:59 と返すメソッドを用意 (@onk)
|
60
|
+
|
61
|
+
|
62
|
+
## Shibaraku v0.0.1 (2014-11-18)
|
63
|
+
|
64
|
+
* Initial Release
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Takafumi ONAKA
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
暫
|
2
|
+
================================
|
3
|
+
|
4
|
+
ActiveRecord で start_at/end_at がある model を扱う gem です
|
5
|
+
|
6
|
+
|
7
|
+
Usage
|
8
|
+
--------------------------------
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
# create_table :campaigns do |t|
|
12
|
+
# t.datetime :start_at
|
13
|
+
# t.datetime :end_at
|
14
|
+
# end
|
15
|
+
class Campaign < ActiveRecord::Base
|
16
|
+
shibaraku
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
Campaign.in_time
|
22
|
+
# => SELECT start_at <= now < end_at records
|
23
|
+
|
24
|
+
Campaign.in_time(super_user)
|
25
|
+
# => SELECT test_start_at <= now < test_end_at records
|
26
|
+
```
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
campaign = Campaign.create(start_at: 1.hour.ago, end_at: 1.hour.since)
|
30
|
+
campaign.in_time? # => true
|
31
|
+
```
|
32
|
+
|
33
|
+
License
|
34
|
+
--------------------------------
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "shibaraku"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/shibaraku.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Shibaraku
|
2
|
+
module ActiveRecordExt
|
3
|
+
def self.included(model)
|
4
|
+
model.class_eval {
|
5
|
+
class_attribute :shibaraku_start_at_column
|
6
|
+
class_attribute :shibaraku_end_at_column
|
7
|
+
}
|
8
|
+
model.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
# Class methods injected into ActiveRecord::Base
|
12
|
+
module ClassMethods
|
13
|
+
def shibaraku(options = {})
|
14
|
+
self.shibaraku_start_at_column = options[:start_at] || :start_at
|
15
|
+
self.shibaraku_end_at_column = options[:end_at] || :end_at
|
16
|
+
include Shibaraku::ActiveRecordExt::Core
|
17
|
+
end
|
18
|
+
|
19
|
+
def shibaraku_start_at_column_name(user)
|
20
|
+
name = self.shibaraku_start_at_column
|
21
|
+
name = test_column_name(name) if user && user.super_user?
|
22
|
+
name
|
23
|
+
end
|
24
|
+
|
25
|
+
def shibaraku_end_at_column_name(user)
|
26
|
+
name = self.shibaraku_end_at_column
|
27
|
+
name = test_column_name(name) if user && user.super_user?
|
28
|
+
name
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_column_name(name)
|
32
|
+
define_attribute_methods
|
33
|
+
test_name = "test_#{name}"
|
34
|
+
self.method_defined?(test_name) ? test_name : name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module Core
|
39
|
+
def self.included(model)
|
40
|
+
model.extend ClassMethods
|
41
|
+
end
|
42
|
+
|
43
|
+
def shibaraku_start_at(user)
|
44
|
+
public_send(self.class.shibaraku_start_at_column_name(user))
|
45
|
+
end
|
46
|
+
|
47
|
+
def shibaraku_end_at(user)
|
48
|
+
public_send(self.class.shibaraku_end_at_column_name(user))
|
49
|
+
end
|
50
|
+
|
51
|
+
module ClassMethods
|
52
|
+
def in_time(user = nil, now = Time.current)
|
53
|
+
start_at = shibaraku_start_at_column_name(user)
|
54
|
+
end_at = shibaraku_end_at_column_name(user)
|
55
|
+
where("(#{start_at} IS NULL OR #{start_at} <= :now) AND (#{end_at} IS NULL OR :now < #{end_at})", now: now)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def in_time?(user = nil, now = Time.current)
|
60
|
+
(shibaraku_start_at(user).nil? || shibaraku_start_at(user) <= now) && (shibaraku_end_at(user).nil? || now < shibaraku_end_at(user))
|
61
|
+
end
|
62
|
+
|
63
|
+
def human_readable_end_at(user = nil)
|
64
|
+
if shibaraku_end_at(user) && shibaraku_end_at(user) == shibaraku_end_at(user).beginning_of_day
|
65
|
+
shibaraku_end_at(user) - 1.second
|
66
|
+
else
|
67
|
+
shibaraku_end_at(user)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/shibaraku.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 "shibaraku/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shibaraku"
|
8
|
+
spec.version = Shibaraku::VERSION
|
9
|
+
spec.authors = ["Takafumi ONAKA"]
|
10
|
+
spec.email = ["takafumi.onaka@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Manage model with a period on ActiveRecord."
|
13
|
+
spec.description = "Manage model with a period on ActiveRecord."
|
14
|
+
spec.homepage = "https://github.com/onk/shibaraku"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "rails"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "mysql2"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shibaraku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takafumi ONAKA
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-17 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
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: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Manage model with a period on ActiveRecord.
|
84
|
+
email:
|
85
|
+
- takafumi.onaka@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- CHANGELOG.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/shibaraku.rb
|
100
|
+
- lib/shibaraku/active_record_ext.rb
|
101
|
+
- lib/shibaraku/version.rb
|
102
|
+
- shibaraku.gemspec
|
103
|
+
homepage: https://github.com/onk/shibaraku
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.5.0
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Manage model with a period on ActiveRecord.
|
127
|
+
test_files: []
|