skn_utils 5.1.3 → 5.2.0
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 +4 -4
- data/README.rdoc +145 -0
- data/lib/skn_utils/version.rb +2 -2
- data/lib/skn_utils.rb +25 -0
- data/skn_utils.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6626371d3c94b3bc3907c2076960641a49019628
|
4
|
+
data.tar.gz: 51fc2a420168d5d9d760cccc4dae8a2d7dbd4d13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eee749ed9ad4ccc4f4fd7c5c9d464fd459650d197b3c30acbbeace7799b88ebff4e1774e3a75ad8ed24e3f0a0fdfd9f0f3ea213eca6b67ed0797610f4caac73
|
7
|
+
data.tar.gz: dda45c33fa7e7d6509f6369fb84504fb0f146baa698fffe3b5c42c95bb73b02d9d168509f0b380d259d5118dd5cacd3424715556d6f09b195e4c3663daa38885
|
data/README.rdoc
CHANGED
@@ -232,3 +232,148 @@ $ bin/console
|
|
232
232
|
|
233
233
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
234
234
|
|
235
|
+
=== Notes:
|
236
|
+
```ruby
|
237
|
+
class ApplicationSchema < Dry::Validation::Schema
|
238
|
+
configure do |config|
|
239
|
+
option :record
|
240
|
+
option :machine_repository, Machine
|
241
|
+
option :user_repository, User
|
242
|
+
option :temporary_token_repository, TemporaryToken
|
243
|
+
|
244
|
+
config.messages_file = 'config/locales/validations.yml'
|
245
|
+
end
|
246
|
+
|
247
|
+
...
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
module Sessions
|
252
|
+
AuthenticateUserSchema = Dry::Validation.Schema(ApplicationSchema) do
|
253
|
+
required(:email).filled(:str?)
|
254
|
+
required(:password).filled(:str?)
|
255
|
+
|
256
|
+
validate(exists?: :email) do |email|
|
257
|
+
user_repository.find_by(email: email).present?
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
```
|
262
|
+
|
263
|
+
from: Andy Holland @AMHOL, roda-action
|
264
|
+
```ruby
|
265
|
+
class Roda
|
266
|
+
ContainerError = Class.new(::Exception)
|
267
|
+
|
268
|
+
module RodaPlugins
|
269
|
+
# The container plugin allows your application to
|
270
|
+
# act as a container, you can register values
|
271
|
+
# with your application (container) and resolve them later.
|
272
|
+
#
|
273
|
+
# If you register something that responds to call, the result of
|
274
|
+
# call will be returned each time you resolve it.
|
275
|
+
#
|
276
|
+
# Example:
|
277
|
+
#
|
278
|
+
# plugin :container
|
279
|
+
#
|
280
|
+
# class UserRepository
|
281
|
+
# def self.first
|
282
|
+
# { name: 'Jack' }
|
283
|
+
# end
|
284
|
+
# end
|
285
|
+
#
|
286
|
+
# MyApplication.register(:user_repository, UserRepository)
|
287
|
+
# MyApplication.resolve(:user_repository).first
|
288
|
+
#
|
289
|
+
# class PersonRepository
|
290
|
+
# def first
|
291
|
+
# { name: 'Gill' }
|
292
|
+
# end
|
293
|
+
# end
|
294
|
+
#
|
295
|
+
# MyApplication.register(:person_repository, -> { PersonRepository.new })
|
296
|
+
# MyApplication.resolve(:person_repository).first
|
297
|
+
module Container
|
298
|
+
class Container < RodaCache
|
299
|
+
def register(key, contents = nil, options = {}, &block)
|
300
|
+
if block_given?
|
301
|
+
item = block
|
302
|
+
options = contents if contents.is_a?(::Hash)
|
303
|
+
else
|
304
|
+
item = contents
|
305
|
+
end
|
306
|
+
|
307
|
+
self[key] = Content.new(item, options)
|
308
|
+
end
|
309
|
+
|
310
|
+
def resolve(key)
|
311
|
+
content = self.fetch(key) do
|
312
|
+
fail ::Roda::ContainerError, "Nothing registered with the name #{key}"
|
313
|
+
end
|
314
|
+
|
315
|
+
content.call
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
class Content
|
320
|
+
attr_reader :item, :options
|
321
|
+
|
322
|
+
def initialize(item, options = {})
|
323
|
+
@item, @options = item, {
|
324
|
+
call: item.is_a?(::Proc)
|
325
|
+
}.merge(options)
|
326
|
+
end
|
327
|
+
|
328
|
+
def call
|
329
|
+
if options[:call] == true
|
330
|
+
item.call
|
331
|
+
else
|
332
|
+
item
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
module ClassMethods
|
338
|
+
attr_reader :container
|
339
|
+
private :container
|
340
|
+
|
341
|
+
def self.extended(subclass)
|
342
|
+
subclass.instance_variable_set(:@container, Container.new)
|
343
|
+
super
|
344
|
+
end
|
345
|
+
|
346
|
+
def inherited(subclass)
|
347
|
+
subclass.instance_variable_set(:@container, container)
|
348
|
+
super
|
349
|
+
end
|
350
|
+
|
351
|
+
def instance
|
352
|
+
Thread.current[:__container__]
|
353
|
+
end
|
354
|
+
|
355
|
+
def register(key, contents = nil, options = {}, &block)
|
356
|
+
container.register(key, contents, options, &block)
|
357
|
+
end
|
358
|
+
|
359
|
+
def resolve(key)
|
360
|
+
container.resolve(key)
|
361
|
+
end
|
362
|
+
|
363
|
+
def detach_container
|
364
|
+
@container = container.dup
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
module InstanceMethods
|
369
|
+
def call(*args, &block)
|
370
|
+
Thread.current[:__container__] = self.class.send(:container).dup
|
371
|
+
super
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
register_plugin(:container, Container)
|
377
|
+
end
|
378
|
+
end
|
379
|
+
```
|
data/lib/skn_utils/version.rb
CHANGED
data/lib/skn_utils.rb
CHANGED
@@ -6,6 +6,7 @@ require 'erb'
|
|
6
6
|
require 'date'
|
7
7
|
require 'time'
|
8
8
|
require 'concurrent'
|
9
|
+
require 'colorize'
|
9
10
|
unless defined?(Rails)
|
10
11
|
begin
|
11
12
|
require 'deep_merge'
|
@@ -31,6 +32,30 @@ require 'skn_registry'
|
|
31
32
|
require 'skn_container'
|
32
33
|
require 'skn_settings'
|
33
34
|
|
35
|
+
|
36
|
+
|
34
37
|
module SknUtils
|
35
38
|
|
39
|
+
# Random Utils
|
40
|
+
# Retries block up to :retries times with a :pause_between, and returns Success/Failure object
|
41
|
+
#
|
42
|
+
def self.catch_exceptions(retries=3, pause_between=3, &block)
|
43
|
+
retry_count ||= 1
|
44
|
+
attempts = retries
|
45
|
+
begin
|
46
|
+
|
47
|
+
SknSuccess.( yield )
|
48
|
+
|
49
|
+
rescue StandardError => error
|
50
|
+
Kernel.puts "#{retry_count} - #{error.class.name}:#{error.message}".light_blue.italic
|
51
|
+
if retry_count <= attempts
|
52
|
+
retry_count+= 1
|
53
|
+
sleep(pause_between)
|
54
|
+
retry
|
55
|
+
else
|
56
|
+
SknFailure.( "RETRY ATTEMPTS FAILED - #{error.class.name}:#{error.message}" )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end # end method
|
60
|
+
|
36
61
|
end
|
data/skn_utils.gemspec
CHANGED
@@ -33,6 +33,7 @@ EOF
|
|
33
33
|
spec.add_runtime_dependency 'deep_merge', '~> 1'
|
34
34
|
spec.add_runtime_dependency 'concurrent-ruby', '~> 1'
|
35
35
|
spec.add_runtime_dependency 'thor', '~> 0'
|
36
|
+
spec.add_runtime_dependency 'colorize', '~> 0'
|
36
37
|
|
37
38
|
spec.add_development_dependency "bundler", "~> 1"
|
38
39
|
spec.add_development_dependency "rake", "~> 10"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skn_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Scott Jr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|