lite-regulations 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/.gitattributes +2 -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/regulations.rb +11 -0
- data/lib/lite/regulations/activation.rb +46 -0
- data/lib/lite/regulations/base.rb +13 -0
- data/lib/lite/regulations/containment.rb +46 -0
- data/lib/lite/regulations/expiration.rb +69 -0
- data/lib/lite/regulations/quarantine.rb +46 -0
- data/lib/lite/regulations/railtie.rb +22 -0
- data/lib/lite/regulations/suspension.rb +46 -0
- data/lib/lite/regulations/version.rb +9 -0
- data/lib/lite/regulations/visibility.rb +46 -0
- data/lite-regulations.gemspec +53 -0
- metadata +245 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lite
|
4
|
+
module Regulations
|
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::Regulations::Base.timestamp
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_quarantine
|
31
|
+
I18n.t("lite.regulations.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,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/railtie'
|
4
|
+
|
5
|
+
module Lite
|
6
|
+
module Regulations
|
7
|
+
class Railtie < ::Rails::Railtie
|
8
|
+
|
9
|
+
initializer 'lite-regulations' do |app|
|
10
|
+
Lite::Regulations::Railtie.instance_eval do
|
11
|
+
[app.config.i18n.available_locales].flatten.each do |locale|
|
12
|
+
path = File.expand_path("../../../config/locales/#{locale}.yml", __FILE__)
|
13
|
+
next if !File.file?(path) || I18n.load_path.include?(path)
|
14
|
+
|
15
|
+
I18n.load_path << path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lite
|
4
|
+
module Regulations
|
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::Regulations::Base.timestamp
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_suspension
|
31
|
+
I18n.t("lite.regulations.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 Regulations
|
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::Regulations::Base.timestamp
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_visibility
|
37
|
+
I18n.t("lite.regulations.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/regulations/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'lite-regulations'
|
9
|
+
spec.version = Lite::Regulations::VERSION
|
10
|
+
spec.authors = ['Juan Gomez']
|
11
|
+
spec.email = %w[j.gomez@drexed.com]
|
12
|
+
|
13
|
+
spec.summary = 'Collection of mixins to control the state of a database record'
|
14
|
+
spec.homepage = 'http://drexed.github.io/lite-regulations'
|
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-regulations/blob/master/CHANGELOG.md',
|
23
|
+
'homepage_uri' => spec.homepage,
|
24
|
+
'source_code_uri' => 'https://github.com/drexed/lite-regulations'
|
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,245 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lite-regulations
|
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-08-13 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
|
+
- ".gitattributes"
|
190
|
+
- ".gitignore"
|
191
|
+
- ".rspec"
|
192
|
+
- ".rubocop.yml"
|
193
|
+
- ".travis.yml"
|
194
|
+
- CHANGELOG.md
|
195
|
+
- CODE_OF_CONDUCT.md
|
196
|
+
- Gemfile
|
197
|
+
- Gemfile.lock
|
198
|
+
- LICENSE.txt
|
199
|
+
- README.md
|
200
|
+
- Rakefile
|
201
|
+
- _config.yml
|
202
|
+
- bin/console
|
203
|
+
- bin/setup
|
204
|
+
- config/locales/en.yml
|
205
|
+
- docs/ACTIVATION.md
|
206
|
+
- docs/CONTAINMENT.md
|
207
|
+
- docs/EXPIRATION.md
|
208
|
+
- docs/QUARANTINE.md
|
209
|
+
- docs/SUSPENSION.md
|
210
|
+
- docs/VISIBILITY.md
|
211
|
+
- lib/lite/regulations.rb
|
212
|
+
- lib/lite/regulations/activation.rb
|
213
|
+
- lib/lite/regulations/base.rb
|
214
|
+
- lib/lite/regulations/containment.rb
|
215
|
+
- lib/lite/regulations/expiration.rb
|
216
|
+
- lib/lite/regulations/quarantine.rb
|
217
|
+
- lib/lite/regulations/railtie.rb
|
218
|
+
- lib/lite/regulations/suspension.rb
|
219
|
+
- lib/lite/regulations/version.rb
|
220
|
+
- lib/lite/regulations/visibility.rb
|
221
|
+
- lite-regulations.gemspec
|
222
|
+
homepage: http://drexed.github.io/lite-regulations
|
223
|
+
licenses:
|
224
|
+
- MIT
|
225
|
+
metadata: {}
|
226
|
+
post_install_message:
|
227
|
+
rdoc_options: []
|
228
|
+
require_paths:
|
229
|
+
- lib
|
230
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - ">="
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '0'
|
235
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - ">="
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '0'
|
240
|
+
requirements: []
|
241
|
+
rubygems_version: 3.0.4
|
242
|
+
signing_key:
|
243
|
+
specification_version: 4
|
244
|
+
summary: Collection of mixins to control the state of a database record
|
245
|
+
test_files: []
|