skn_utils 5.4.0 → 5.4.1
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/lib/skn_container.rb +2 -1
- data/lib/skn_failure.rb +2 -0
- data/lib/skn_hash.rb +2 -0
- data/lib/skn_registry.rb +2 -0
- data/lib/skn_settings.rb +2 -0
- data/lib/skn_success.rb +2 -0
- data/lib/skn_utils/configurable.rb +18 -6
- data/lib/skn_utils/configuration.rb +2 -0
- data/lib/skn_utils/core_extensions.rb +2 -0
- data/lib/skn_utils/dotted_hash.rb +1 -0
- data/lib/skn_utils/env_string_handler.rb +2 -0
- data/lib/skn_utils/nested_result.rb +2 -0
- data/lib/skn_utils/notifier_base.rb +2 -0
- data/lib/skn_utils/null_object.rb +2 -0
- data/lib/skn_utils/page_controls.rb +2 -0
- data/lib/skn_utils/result_bean.rb +2 -0
- data/lib/skn_utils/version.rb +3 -1
- data/lib/skn_utils/wrappable.rb +32 -0
- data/lib/skn_utils.rb +3 -0
- data/skn_utils.gemspec +1 -0
- data/spec/lib/skn_utils/configurable_spec.rb +23 -36
- data/spec/lib/skn_utils/wrappers_spec.rb +80 -0
- data/spec/support/configurables.rb +36 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a38f9d3fd144a0b4d591b492fd5dd4ba2c9e448a
|
4
|
+
data.tar.gz: 9d5bdceb553ee84f17d37c8f8b3c06d1126f831e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1d14426f03a6b19cb668f596ccf777352e78295c3c36c7dbe11b56939e90e0b79adb3676b09ab16a61f3167b8089c2f97a40ef846185ac17b527bac04edab04
|
7
|
+
data.tar.gz: 296386960a3ee3d438334fb1a0ded9ae275632ce5bbf6f486cbdbdab18b5904d6f82c9b33373a0632e7c14e34156230ba2b6c1c9008c27305ba7541f15b0435b
|
data/lib/skn_container.rb
CHANGED
data/lib/skn_failure.rb
CHANGED
data/lib/skn_registry.rb
CHANGED
data/lib/skn_settings.rb
CHANGED
data/lib/skn_success.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
# File: <gem-root>/lib/skn_utils/configurable.rb
|
3
5
|
# Ref: https://www.toptal.com/ruby/ruby-dsl-metaprogramming-guide
|
@@ -25,7 +27,7 @@ module SknUtils
|
|
25
27
|
# end
|
26
28
|
#
|
27
29
|
#################
|
28
|
-
# During Definition
|
30
|
+
# -or- During Definition
|
29
31
|
#################
|
30
32
|
# class MyApp
|
31
33
|
# include SknUtils::Configurable.with(:app_id, :title, :cookie_name, {root_enable: true})
|
@@ -36,6 +38,7 @@ module SknUtils
|
|
36
38
|
# cookie_name { "#{app_id}_session" }
|
37
39
|
# end
|
38
40
|
#
|
41
|
+
# # these are the root_enable default settings
|
39
42
|
# self.logger = Logger.new
|
40
43
|
# self.env = ENV.fetch('RACK_ENV', 'development')
|
41
44
|
# self.root = Dir.pwd
|
@@ -65,9 +68,9 @@ module SknUtils
|
|
65
68
|
|
66
69
|
module Configurable
|
67
70
|
|
68
|
-
def self.with(*
|
71
|
+
def self.with(*config_attrs, **root_options)
|
69
72
|
_not_provided = Object.new
|
70
|
-
|
73
|
+
_root_options = root_options.empty? || root_options.values.any?{|v| v == true}
|
71
74
|
|
72
75
|
# Define the config class/module methods
|
73
76
|
config_class = Class.new do
|
@@ -79,7 +82,7 @@ module SknUtils
|
|
79
82
|
instance_variable_set("@#{attr}", val)
|
80
83
|
end
|
81
84
|
|
82
|
-
|
85
|
+
config_attrs.each do |attr|
|
83
86
|
define_method attr do |value = _not_provided, &block|
|
84
87
|
if value === _not_provided && block.nil?
|
85
88
|
result = instance_variable_get("@#{attr}")
|
@@ -90,7 +93,7 @@ module SknUtils
|
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
93
|
-
attr_writer *
|
96
|
+
attr_writer *config_attrs
|
94
97
|
end
|
95
98
|
|
96
99
|
# Define the runtime access methods
|
@@ -101,7 +104,7 @@ module SknUtils
|
|
101
104
|
def configure(&block)
|
102
105
|
config.instance_eval(&block)
|
103
106
|
end
|
104
|
-
if
|
107
|
+
if _root_options
|
105
108
|
# Enable Rails<Like>.env and Rails.logger like feature:
|
106
109
|
# - MyClass.env.production? or MyClass.logger or MyClass.root
|
107
110
|
def registry
|
@@ -142,3 +145,12 @@ module SknUtils
|
|
142
145
|
|
143
146
|
end # end module
|
144
147
|
end # End module
|
148
|
+
|
149
|
+
#
|
150
|
+
# def [](key)
|
151
|
+
# @internal_var[key]
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# def []=(key, value)
|
155
|
+
# @internal_var[key] = value
|
156
|
+
# end
|
data/lib/skn_utils/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ##
|
4
|
+
#
|
5
|
+
# Ref: https://blog.appsignal.com/2018/10/02/ruby-magic-class-level-instance-variables.html
|
6
|
+
|
7
|
+
module SknUtils
|
8
|
+
|
9
|
+
module Wrappable
|
10
|
+
def wrap(mod)
|
11
|
+
wrappers << mod
|
12
|
+
end
|
13
|
+
|
14
|
+
def wrappers
|
15
|
+
@wrappers ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def inherited_wrappers
|
19
|
+
ancestors
|
20
|
+
.grep(Wrappable)
|
21
|
+
.reverse
|
22
|
+
.flat_map(&:wrappers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def new(*arguments, &block)
|
26
|
+
instance = allocate
|
27
|
+
inherited_wrappers.each { |mod|instance.singleton_class.include(mod) }
|
28
|
+
instance.send(:initialize, *arguments, &block)
|
29
|
+
instance
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/skn_utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
|
2
4
|
require "skn_utils/version"
|
3
5
|
require 'psych'
|
@@ -25,6 +27,7 @@ require 'skn_utils/null_object'
|
|
25
27
|
require 'skn_utils/notifier_base'
|
26
28
|
require 'skn_utils/configuration'
|
27
29
|
require 'skn_utils/configurable'
|
30
|
+
require 'skn_utils/wrappable'
|
28
31
|
|
29
32
|
require 'skn_hash'
|
30
33
|
require 'skn_registry'
|
data/skn_utils.gemspec
CHANGED
@@ -2,51 +2,20 @@
|
|
2
2
|
# spec/lib/skn_utils/configurable_spec.rb
|
3
3
|
#
|
4
4
|
|
5
|
-
|
6
|
-
include SknUtils::Configurable.with( :app_id, :title, :cookie_name, enable_root: true) # No options hash defaults to true
|
7
|
-
# - and accept defaults for #env=, #root=, #registry=, and #logger=
|
8
|
-
|
9
|
-
# notice: self.logger=, the self is required when assigning values
|
10
|
-
self.logger = Object.new
|
11
|
-
self.registry = Object.new
|
12
|
-
|
13
|
-
configure do
|
14
|
-
app_id 'some app'
|
15
|
-
title 'My Title'
|
16
|
-
cookie_name 'Chocolate'
|
17
|
-
end
|
18
|
-
|
19
|
-
def null_value
|
20
|
-
@app_id.dup
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module MyMod
|
25
|
-
include SknUtils::Configurable.with(:app_id, :title, :cookie_name, enable_root: false)
|
26
|
-
|
27
|
-
def self.null_value
|
28
|
-
@app_id.dup
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
MyMod.configure do
|
33
|
-
app_id 'some module'
|
34
|
-
title 'Some Title'
|
35
|
-
cookie_name 'Caramel'
|
36
|
-
end
|
5
|
+
require "support/configurables"
|
37
6
|
|
38
7
|
|
39
8
|
describe SknUtils::Configurable, "Gem Configuration module." do
|
40
9
|
|
41
10
|
let(:my_app) { MyApp.new }
|
42
11
|
|
43
|
-
context "Top Level AppClass Extra Operational Features. " do
|
12
|
+
context "MyApp: Top Level AppClass Extra Operational Features. " do
|
44
13
|
|
45
14
|
it "MyApp.env.test? returns expected value. " do
|
46
15
|
expect( MyApp.env.test? ).to be true
|
47
16
|
end
|
48
17
|
it "MyApp.root returns expected value. " do
|
49
|
-
expect( MyApp.root
|
18
|
+
expect( MyApp.root ).to eq( Dir.pwd )
|
50
19
|
end
|
51
20
|
it "MyApp.logger returns expected value. " do
|
52
21
|
expect( MyApp.logger ).to be_instance_of(Object) # eq('No Logger Assigned.')
|
@@ -60,9 +29,11 @@ describe SknUtils::Configurable, "Gem Configuration module." do
|
|
60
29
|
|
61
30
|
it "my_app#config.title returns expected value. " do
|
62
31
|
expect( MyApp.config.title ).to eq( "My Title" )
|
32
|
+
expect( MyApp.config[:title] ).to eq( "My Title" )
|
63
33
|
end
|
64
|
-
it "my_app#config
|
65
|
-
expect( MyApp.config
|
34
|
+
it "my_app#config[:value] accepts and returns expected value. " do
|
35
|
+
expect( MyApp.config[:value]="New Attribute" ).to eq( "New Attribute" )
|
36
|
+
expect( MyApp.config[:value] ).to eq( "New Attribute" )
|
66
37
|
end
|
67
38
|
|
68
39
|
it "MyMod#config.app_id returns expected value. " do
|
@@ -70,6 +41,11 @@ describe SknUtils::Configurable, "Gem Configuration module." do
|
|
70
41
|
end
|
71
42
|
it "MyMod#config.cookie_name returns expected value. " do
|
72
43
|
expect( MyMod.config.cookie_name ).to eq( 'Caramel' )
|
44
|
+
expect( MyMod.config[:cookie_name] ).to eq( 'Caramel' )
|
45
|
+
end
|
46
|
+
it "MyMod#config[:value] accepts and returns expected value. " do
|
47
|
+
expect( MyMod.config[:value]="New Attribute" ).to eq( "New Attribute" )
|
48
|
+
expect( MyMod.config[:value] ).to eq( "New Attribute" )
|
73
49
|
end
|
74
50
|
|
75
51
|
it "MyMod#logger raises NoMethodError as expected. " do
|
@@ -78,4 +54,15 @@ describe SknUtils::Configurable, "Gem Configuration module." do
|
|
78
54
|
|
79
55
|
end
|
80
56
|
|
57
|
+
context "#config instance vars are accessable as expected. " do
|
58
|
+
|
59
|
+
it "MyApp#null_value to return expected value" do
|
60
|
+
expect(my_app.null_value).to eq "some app"
|
61
|
+
expect{ MyApp.null_value }.to raise_error(NoMethodError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "MyMod#null_value to return expected value" do
|
65
|
+
expect( MyMod.null_value ).to eq "some module"
|
66
|
+
end
|
67
|
+
end
|
81
68
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# ##
|
2
|
+
#
|
3
|
+
|
4
|
+
module Powered
|
5
|
+
def make_noise
|
6
|
+
puts "Powering up"
|
7
|
+
super
|
8
|
+
puts "Shutting down"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Machine
|
13
|
+
extend SknUtils::Wrappable
|
14
|
+
|
15
|
+
wrap Powered
|
16
|
+
|
17
|
+
def make_noise
|
18
|
+
puts "Buzzzzzz"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
module Logging
|
24
|
+
def make_noise
|
25
|
+
puts "Started making noise"
|
26
|
+
super
|
27
|
+
puts "Finished making noise"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Bird
|
32
|
+
extend SknUtils::Wrappable
|
33
|
+
|
34
|
+
wrap Logging
|
35
|
+
|
36
|
+
def make_noise
|
37
|
+
puts "Chirp, chirp!"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
module Flying
|
43
|
+
def make_noise
|
44
|
+
super
|
45
|
+
puts "Is flying away"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Pigeon < Bird
|
50
|
+
wrap Flying
|
51
|
+
|
52
|
+
def make_noise
|
53
|
+
puts "Coo!"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'SknUtils::Wrappable Module Handles Inheritance properly ' do
|
58
|
+
|
59
|
+
it '#make_noise handles Bird module. ' do
|
60
|
+
expect do
|
61
|
+
obj = Bird.new
|
62
|
+
obj.make_noise
|
63
|
+
end.to output("Started making noise\nChirp, chirp!\nFinished making noise\n").to_stdout
|
64
|
+
end
|
65
|
+
|
66
|
+
it '#make_noise handles Pigeon module. ' do
|
67
|
+
expect do
|
68
|
+
obj = Pigeon.new
|
69
|
+
obj.make_noise
|
70
|
+
end.to output("Started making noise\nCoo!\nFinished making noise\nIs flying away\n").to_stdout
|
71
|
+
end
|
72
|
+
|
73
|
+
it '#make_noise handles Machine module. ' do
|
74
|
+
expect do
|
75
|
+
obj = Machine.new
|
76
|
+
obj.make_noise
|
77
|
+
end.to output("Powering up\nBuzzzzzz\nShutting down\n").to_stdout
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
##
|
2
|
+
# spec/support/configurables.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
class MyApp
|
6
|
+
include SknUtils::Configurable.with( :app_id, :title, :cookie_name, enable_root: true) # No options hash defaults to true
|
7
|
+
# - and accept defaults for #env=, #root=, #registry=, and #logger=
|
8
|
+
|
9
|
+
# notice: self.logger=, the self is required when assigning values
|
10
|
+
self.logger = Object.new
|
11
|
+
self.registry = Object.new
|
12
|
+
|
13
|
+
configure do
|
14
|
+
app_id 'some app'
|
15
|
+
title 'My Title'
|
16
|
+
cookie_name 'Chocolate'
|
17
|
+
end
|
18
|
+
|
19
|
+
def null_value
|
20
|
+
self.class.config.app_id.dup
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module MyMod
|
25
|
+
include SknUtils::Configurable.with(:app_id, :title, :cookie_name, enable_root: false)
|
26
|
+
|
27
|
+
def self.null_value
|
28
|
+
config.app_id.dup
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
MyMod.configure do
|
33
|
+
app_id 'some module'
|
34
|
+
title 'Some Title'
|
35
|
+
cookie_name 'Caramel'
|
36
|
+
end
|
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.
|
4
|
+
version: 5.4.1
|
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:
|
11
|
+
date: 2019-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- lib/skn_utils/page_controls.rb
|
184
184
|
- lib/skn_utils/result_bean.rb
|
185
185
|
- lib/skn_utils/version.rb
|
186
|
+
- lib/skn_utils/wrappable.rb
|
186
187
|
- skn_utils.gemspec
|
187
188
|
- spec/factories/environments/development.yml
|
188
189
|
- spec/factories/environments/production.yml
|
@@ -202,7 +203,9 @@ files:
|
|
202
203
|
- spec/lib/skn_utils/null_object_spec.rb
|
203
204
|
- spec/lib/skn_utils/registry_spec.rb
|
204
205
|
- spec/lib/skn_utils/success_failure_value_container_spec.rb
|
206
|
+
- spec/lib/skn_utils/wrappers_spec.rb
|
205
207
|
- spec/spec_helper.rb
|
208
|
+
- spec/support/configurables.rb
|
206
209
|
homepage: https://github.com/skoona/skn_utils
|
207
210
|
licenses:
|
208
211
|
- MIT
|
@@ -250,4 +253,6 @@ test_files:
|
|
250
253
|
- spec/lib/skn_utils/null_object_spec.rb
|
251
254
|
- spec/lib/skn_utils/registry_spec.rb
|
252
255
|
- spec/lib/skn_utils/success_failure_value_container_spec.rb
|
256
|
+
- spec/lib/skn_utils/wrappers_spec.rb
|
253
257
|
- spec/spec_helper.rb
|
258
|
+
- spec/support/configurables.rb
|