lite-regulation 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.fasterer.yml +19 -0
- data/.gitignore +11 -0
- data/.rspec +4 -0
- data/.rubocop.yml +24 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +137 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +8 -0
- data/_config.yml +1 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +21 -0
- data/docs/ACTIVATION.md +41 -0
- data/docs/CONTAINMENT.md +41 -0
- data/docs/EXPIRATION.md +45 -0
- data/docs/QUARANTINE.md +41 -0
- data/docs/SUSPENSION.md +41 -0
- data/docs/VISIBILITY.md +41 -0
- data/lib/lite/regulation.rb +11 -0
- data/lib/lite/regulation/activation.rb +46 -0
- data/lib/lite/regulation/base.rb +13 -0
- data/lib/lite/regulation/containment.rb +46 -0
- data/lib/lite/regulation/expiration.rb +69 -0
- data/lib/lite/regulation/quarantine.rb +46 -0
- data/lib/lite/regulation/railtie.rb +20 -0
- data/lib/lite/regulation/suspension.rb +46 -0
- data/lib/lite/regulation/version.rb +9 -0
- data/lib/lite/regulation/visibility.rb +46 -0
- data/lite-regulation.gemspec +53 -0
- metadata +244 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lite
|
4
|
+
module Regulation
|
5
|
+
module Quarantine
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
scope :quarantined, -> { where.not(quarantined_at: nil) }
|
11
|
+
scope :unquarantined, -> { where(quarantined_at: nil) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def quarantine!
|
15
|
+
return true if quarantined?
|
16
|
+
|
17
|
+
update(quarantined_at: Time.current)
|
18
|
+
end
|
19
|
+
|
20
|
+
def quarantined?
|
21
|
+
!unquarantined?
|
22
|
+
end
|
23
|
+
|
24
|
+
def quarantined_at_or_time
|
25
|
+
return quarantined_at if quarantined?
|
26
|
+
|
27
|
+
Lite::Regulation::Base.timestamp
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_quarantine
|
31
|
+
I18n.t("lite.regulation.quarantine.#{:un if unquarantined?}quarantined")
|
32
|
+
end
|
33
|
+
|
34
|
+
def unquarantine!
|
35
|
+
return true if unquarantined?
|
36
|
+
|
37
|
+
update(quarantined_at: nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
def unquarantined?
|
41
|
+
quarantined_at.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lite
|
4
|
+
module Regulation
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
|
7
|
+
initializer 'lite-regulation' do |app|
|
8
|
+
Lite::Regulation::Railtie.instance_eval do
|
9
|
+
[app.config.i18n.available_locales].flatten.each do |locale|
|
10
|
+
path = File.expand_path("../../../config/locales/#{locale}.yml", __FILE__)
|
11
|
+
next if !File.file?(path) || I18n.load_path.include?(path)
|
12
|
+
|
13
|
+
I18n.load_path << path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lite
|
4
|
+
module Regulation
|
5
|
+
module Suspension
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
scope :suspended, -> { where.not(suspended_at: nil) }
|
11
|
+
scope :unsuspended, -> { where(suspended_at: nil) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def suspend!
|
15
|
+
return true if suspended?
|
16
|
+
|
17
|
+
update(suspended_at: Time.current)
|
18
|
+
end
|
19
|
+
|
20
|
+
def suspended?
|
21
|
+
!unsuspended?
|
22
|
+
end
|
23
|
+
|
24
|
+
def suspended_at_or_time
|
25
|
+
return suspended_at if unsuspended?
|
26
|
+
|
27
|
+
Lite::Regulation::Base.timestamp
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_suspension
|
31
|
+
I18n.t("lite.regulation.suspension.#{:un if unsuspended?}suspended")
|
32
|
+
end
|
33
|
+
|
34
|
+
def unsuspend!
|
35
|
+
return true if unsuspended?
|
36
|
+
|
37
|
+
update(suspended_at: nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
def unsuspended?
|
41
|
+
suspended_at.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lite
|
4
|
+
module Regulation
|
5
|
+
module Visibility
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
scope :invisible, -> { where.not(invisible_at: nil) }
|
11
|
+
scope :visible, -> { where(invisible_at: nil) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def invisible!
|
15
|
+
return true if invisible?
|
16
|
+
|
17
|
+
update(invisible_at: Time.current)
|
18
|
+
end
|
19
|
+
|
20
|
+
def visible!
|
21
|
+
return true if visible?
|
22
|
+
|
23
|
+
update(invisible_at: nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
def invisible?
|
27
|
+
!visible?
|
28
|
+
end
|
29
|
+
|
30
|
+
def invisible_at_or_time
|
31
|
+
return invisible_at if invisible?
|
32
|
+
|
33
|
+
Lite::Regulation::Base.timestamp
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_visibility
|
37
|
+
I18n.t("lite.regulation.visibility.#{:in if invisible?}visible")
|
38
|
+
end
|
39
|
+
|
40
|
+
def visible?
|
41
|
+
invisible_at.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'lite/regulation/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'lite-regulation'
|
9
|
+
spec.version = Lite::Regulation::VERSION
|
10
|
+
spec.authors = ['Juan Gomez']
|
11
|
+
spec.email = %w[j.gomez@drexed.com]
|
12
|
+
|
13
|
+
spec.summary = 'Collection of mixins to regulate the state of a database record'
|
14
|
+
spec.homepage = 'http://drexed.github.io/lite-regulation'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata.merge(
|
21
|
+
'allowed_push_host' => 'https://rubygems.org',
|
22
|
+
'changelog_uri' => 'https://github.com/drexed/lite-regulation/blob/master/CHANGELOG.md',
|
23
|
+
'homepage_uri' => spec.homepage,
|
24
|
+
'source_code_uri' => 'https://github.com/drexed/lite-regulation'
|
25
|
+
)
|
26
|
+
else
|
27
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
28
|
+
'public gem pushes.'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = %w[lib]
|
39
|
+
|
40
|
+
spec.add_runtime_dependency 'activerecord'
|
41
|
+
spec.add_runtime_dependency 'activesupport'
|
42
|
+
|
43
|
+
spec.add_development_dependency 'bundler'
|
44
|
+
spec.add_development_dependency 'database_cleaner'
|
45
|
+
spec.add_development_dependency 'fasterer'
|
46
|
+
spec.add_development_dependency 'rake'
|
47
|
+
spec.add_development_dependency 'rspec'
|
48
|
+
spec.add_development_dependency 'rspec-rails'
|
49
|
+
spec.add_development_dependency 'rubocop'
|
50
|
+
spec.add_development_dependency 'rubocop-performance'
|
51
|
+
spec.add_development_dependency 'rubocop-rspec'
|
52
|
+
spec.add_development_dependency 'sqlite3'
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lite-regulation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juan Gomez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
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: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: database_cleaner
|
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: fasterer
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-performance
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: sqlite3
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description:
|
182
|
+
email:
|
183
|
+
- j.gomez@drexed.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".fasterer.yml"
|
189
|
+
- ".gitignore"
|
190
|
+
- ".rspec"
|
191
|
+
- ".rubocop.yml"
|
192
|
+
- ".travis.yml"
|
193
|
+
- CHANGELOG.md
|
194
|
+
- CODE_OF_CONDUCT.md
|
195
|
+
- Gemfile
|
196
|
+
- Gemfile.lock
|
197
|
+
- LICENSE.txt
|
198
|
+
- README.md
|
199
|
+
- Rakefile
|
200
|
+
- _config.yml
|
201
|
+
- bin/console
|
202
|
+
- bin/setup
|
203
|
+
- config/locales/en.yml
|
204
|
+
- docs/ACTIVATION.md
|
205
|
+
- docs/CONTAINMENT.md
|
206
|
+
- docs/EXPIRATION.md
|
207
|
+
- docs/QUARANTINE.md
|
208
|
+
- docs/SUSPENSION.md
|
209
|
+
- docs/VISIBILITY.md
|
210
|
+
- lib/lite/regulation.rb
|
211
|
+
- lib/lite/regulation/activation.rb
|
212
|
+
- lib/lite/regulation/base.rb
|
213
|
+
- lib/lite/regulation/containment.rb
|
214
|
+
- lib/lite/regulation/expiration.rb
|
215
|
+
- lib/lite/regulation/quarantine.rb
|
216
|
+
- lib/lite/regulation/railtie.rb
|
217
|
+
- lib/lite/regulation/suspension.rb
|
218
|
+
- lib/lite/regulation/version.rb
|
219
|
+
- lib/lite/regulation/visibility.rb
|
220
|
+
- lite-regulation.gemspec
|
221
|
+
homepage: http://drexed.github.io/lite-regulation
|
222
|
+
licenses:
|
223
|
+
- MIT
|
224
|
+
metadata: {}
|
225
|
+
post_install_message:
|
226
|
+
rdoc_options: []
|
227
|
+
require_paths:
|
228
|
+
- lib
|
229
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
230
|
+
requirements:
|
231
|
+
- - ">="
|
232
|
+
- !ruby/object:Gem::Version
|
233
|
+
version: '0'
|
234
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
|
+
requirements:
|
236
|
+
- - ">="
|
237
|
+
- !ruby/object:Gem::Version
|
238
|
+
version: '0'
|
239
|
+
requirements: []
|
240
|
+
rubygems_version: 3.0.4
|
241
|
+
signing_key:
|
242
|
+
specification_version: 4
|
243
|
+
summary: Collection of mixins to regulate the state of a database record
|
244
|
+
test_files: []
|