ruzai 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +1 -3
- data/lib/ruzai/configurable.rb +12 -0
- data/lib/ruzai/suspender.rb +41 -0
- data/lib/ruzai/version.rb +1 -1
- data/lib/ruzai.rb +2 -40
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b63b91ac1e789ecfe3d8117d191593ff93af8e32
|
4
|
+
data.tar.gz: 3c37a5d7fdfdbaa6b92fe2c64804bc8ee9040180
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b124f2c4a94ae75166cf9d5decb428f0d4c24ee591cef413ff8b8355106feea1a5436a37b99b90e08b86c2a9ac2388b2df43e343d1cba1a6f2431e68c3e30d7
|
7
|
+
data.tar.gz: ea5625deb2a5076bc4453b4c8c691cf2e8be2f12d256a36e21914683a76b8f55f9e9d3526434938ca80617afc4690d10dd548f271c35229179966fd9e8fcae7f
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Ruzai
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
[![Build Status](https://travis-ci.org/ryonext/ruzai.svg?branch=master)](https://travis-ci.org/ryonext/ruzai)
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
|
4
|
+
module Ruzai
|
5
|
+
include ActiveSupport::Configurable
|
6
|
+
config_accessor :suspention_duration, :respawn_limit
|
7
|
+
|
8
|
+
self.configure do |config|
|
9
|
+
config.suspention_duration = 2.weeks
|
10
|
+
config.respawn_limit = 5
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "ruzai/version"
|
2
|
+
require "active_record"
|
3
|
+
|
4
|
+
module Ruzai
|
5
|
+
attr_accessor :suspention_expired_at, :suspended_count
|
6
|
+
def suspended?
|
7
|
+
return true if (self.suspended_count || 0) > Ruzai.respawn_limit
|
8
|
+
return false unless suspention_expired_at
|
9
|
+
self.suspention_expired_at > Time.now
|
10
|
+
end
|
11
|
+
|
12
|
+
def suspended_until
|
13
|
+
return nil unless suspention_expired_at
|
14
|
+
remains = (self.suspention_expired_at - Time.now).to_i
|
15
|
+
|
16
|
+
# If time remains between 1 second ~ 23 hours 59 seconds, it displays '1 day'
|
17
|
+
(( remains / 1.day ) + 1 ).day
|
18
|
+
end
|
19
|
+
|
20
|
+
def suspend!
|
21
|
+
self.suspended_count ||=0
|
22
|
+
self.suspended_count += 1
|
23
|
+
self.suspention_expired_at = Ruzai.suspention_duration.from_now
|
24
|
+
self.save!
|
25
|
+
end
|
26
|
+
|
27
|
+
def ban!
|
28
|
+
self.suspended_count = Ruzai.respawn_limit + 1
|
29
|
+
self.save!
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove_suspention!
|
33
|
+
self.suspention_expired_at = nil
|
34
|
+
self.save!
|
35
|
+
end
|
36
|
+
|
37
|
+
def suspended_before?
|
38
|
+
return false unless self.suspention_expired_at
|
39
|
+
self.suspention_expired_at < Time.now
|
40
|
+
end
|
41
|
+
end
|
data/lib/ruzai/version.rb
CHANGED
data/lib/ruzai.rb
CHANGED
@@ -1,41 +1,3 @@
|
|
1
1
|
require "ruzai/version"
|
2
|
-
require "
|
3
|
-
require "
|
4
|
-
require "active_record"
|
5
|
-
|
6
|
-
module Ruzai
|
7
|
-
attr_accessor :suspention_expired_at, :suspended_count
|
8
|
-
include ActiveSupport::Configurable
|
9
|
-
config_accessor :suspention_duration, :respawn_limit
|
10
|
-
|
11
|
-
self.configure do |config|
|
12
|
-
config.suspention_duration = 2.weeks
|
13
|
-
config.respawn_limit = 5
|
14
|
-
end
|
15
|
-
|
16
|
-
def suspended?
|
17
|
-
return true if (self.suspended_count || 0) > Ruzai.respawn_limit
|
18
|
-
return false unless suspention_expired_at
|
19
|
-
self.suspention_expired_at > Time.now
|
20
|
-
end
|
21
|
-
|
22
|
-
def suspended_until
|
23
|
-
return nil unless suspention_expired_at
|
24
|
-
remains = (self.suspention_expired_at - Time.now).to_i
|
25
|
-
|
26
|
-
# If time remains between 1 second ~ 23 hours 59 seconds, it displays '1 day'
|
27
|
-
(( remains / 1.day ) + 1 ).day
|
28
|
-
end
|
29
|
-
|
30
|
-
def suspend!
|
31
|
-
self.suspended_count ||=0
|
32
|
-
self.suspended_count += 1
|
33
|
-
self.suspention_expired_at = Ruzai.suspention_duration.from_now
|
34
|
-
self.save!
|
35
|
-
end
|
36
|
-
|
37
|
-
def ban!
|
38
|
-
self.suspended_count = Ruzai.respawn_limit + 1
|
39
|
-
self.save!
|
40
|
-
end
|
41
|
-
end
|
2
|
+
require "ruzai/configurable"
|
3
|
+
require "ruzai/suspender"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruzai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryonext
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -135,6 +135,8 @@ files:
|
|
135
135
|
- lib/generators/ruzai/install_generator.rb
|
136
136
|
- lib/generators/ruzai/templates/ruzai_parameters.rb
|
137
137
|
- lib/ruzai.rb
|
138
|
+
- lib/ruzai/configurable.rb
|
139
|
+
- lib/ruzai/suspender.rb
|
138
140
|
- lib/ruzai/version.rb
|
139
141
|
- ruzai.gemspec
|
140
142
|
homepage: https://github.com/ryonext/ruzai
|