skn_utils 5.1.2 → 5.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +66 -4
- data/lib/skn_utils/configurable.rb +12 -5
- data/lib/skn_utils/version.rb +1 -1
- data/spec/lib/skn_utils/configurable_spec.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab0d406a18ec9195e66f548bf411ac0180f3c5e9
|
4
|
+
data.tar.gz: 940e9429c70622331c953c03029b31f1af5cae27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c4dd21348287fb7503b4b30ca15443ca2b1bfe188f9b4e89b22c520e45fde18008b2f3c08df1d505ee6e287a806df14abaaf6e382467e586f7ba8309d66af9
|
7
|
+
data.tar.gz: a0821fe5d46bd2bb5cefa7829a77b0081383691fdd4ac0c75a9012294d34803da742c7ac1aacc8594b4b86a17c6a21e5d957c80ac0eb9d5f314755985a8286ec
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Ruby's Hash object is already extremely flexible, even more so with the addition
|
|
27
27
|
- enables `SknSettings.env.production?` ...
|
28
28
|
1. Since SknSettings is by necessity a global constant, it can serve as Session Storage to keep system objects; like a ROM-RB instance.
|
29
29
|
1. In-Memory Key-Store, use it to cache active user objects, or active Integration passwords, and/or objects that are not serializable.
|
30
|
-
1. Command registries used to
|
30
|
+
1. Command registries used to dispatch command requests to proper command handler. see example app [SknBase](https://github.com/skoona/skn_base/blob/master/strategy/services/content/command_handler.rb)
|
31
31
|
```ruby
|
32
32
|
SknSettings.registry = {
|
33
33
|
Services::Content::Commands::RetrieveAvailableResources => method(:resources_metadata_service),
|
@@ -60,6 +60,10 @@ There are many more use cases for Ruby's Hash that this gem just makes easier to
|
|
60
60
|
|
61
61
|
|
62
62
|
## History
|
63
|
+
10/17/2018 V5.1.3
|
64
|
+
Enhanced SknUtils::Configurable to include a #registry method/value at its root, like Clas.registry or Class.root
|
65
|
+
- Right now these are Class methods only, will update them to survive #new later.
|
66
|
+
|
63
67
|
10/15/2018 V5.1.1
|
64
68
|
Enhanced SknSettings to match 95% of the (Rb)Config.gem public API.
|
65
69
|
|
@@ -143,7 +147,7 @@ There are many more use cases for Ruby's Hash that this gem just makes easier to
|
|
143
147
|
SknUtils::PageControls # Wrapper for name only, inherits from SknUtils::NestedResult
|
144
148
|
SknUtils::DottedHash # Wrapper for name only, inherits from SknUtils::NestedResult
|
145
149
|
|
146
|
-
SknUtils::Configurable # Basic one-level configuration
|
150
|
+
SknUtils::Configurable # Basic one-level class configuration Module
|
147
151
|
|
148
152
|
SknSettings # Multi-level application Configuration class, Key/Value Container with Dot/Hash notiation support.
|
149
153
|
|
@@ -153,8 +157,66 @@ There are many more use cases for Ruby's Hash that this gem just makes easier to
|
|
153
157
|
SknFailure # Three attribute value containers for return codes -- #success, #message, #value
|
154
158
|
|
155
159
|
|
156
|
-
##
|
157
|
-
|
160
|
+
## Public Methods: SknUtils::Configurable module
|
161
|
+
For making an arbitrary class configurable and then specifying those configuration values using a clean and simple DSL.
|
162
|
+
```ruby
|
163
|
+
################
|
164
|
+
Inside Target component
|
165
|
+
################
|
166
|
+
class MyApp
|
167
|
+
include SknUtils::Configurable.with(:app_id, :title, :cookie_name) # or {root_enable: false})
|
168
|
+
# ... default=true for root|env|logger
|
169
|
+
end
|
170
|
+
|
171
|
+
################
|
172
|
+
Inside Initializer
|
173
|
+
################
|
174
|
+
MyApp.configure do
|
175
|
+
app_id "my_app"
|
176
|
+
title "My App"
|
177
|
+
cookie_name { "#{app_id}_session" }
|
178
|
+
end
|
179
|
+
|
180
|
+
################
|
181
|
+
During Definition
|
182
|
+
################
|
183
|
+
class MyApp
|
184
|
+
include SknUtils::Configurable.with(:app_id, :title, :cookie_name, {root_enable: true})
|
185
|
+
# ...
|
186
|
+
configure do
|
187
|
+
app_id "my_app"
|
188
|
+
title "My App"
|
189
|
+
cookie_name { "#{app_id}_session" }
|
190
|
+
end
|
191
|
+
|
192
|
+
self.logger = Logger.new
|
193
|
+
self.env = ENV.fetch('RACK_ENV', 'development')
|
194
|
+
self.root = Dir.pwd
|
195
|
+
end
|
196
|
+
|
197
|
+
################
|
198
|
+
Usage:
|
199
|
+
################
|
200
|
+
MyApp.config.app_id # ==> "my_app"
|
201
|
+
MyApp.logger # ==> <Logger.class>
|
202
|
+
MyApp.registry # ==> <SknRegistry.instance> or user assigned object
|
203
|
+
MyApp.env.test? # ==> true
|
204
|
+
|
205
|
+
###############
|
206
|
+
Syntax
|
207
|
+
###############
|
208
|
+
Main Class Attrs
|
209
|
+
- root = application rood directory as Pathname
|
210
|
+
- env = string value from RACK_ENV
|
211
|
+
- registry = SknRegistry instance
|
212
|
+
- logger = Assigned Logger instance
|
213
|
+
#with(*user_attrs, enable_root: true|false) - defaults to enable of Main Class Attrs
|
214
|
+
|
215
|
+
# ##
|
216
|
+
# User-Defined Attrs
|
217
|
+
# ##
|
218
|
+
MyThing.with(:name1, :name2, ...)
|
219
|
+
```
|
158
220
|
|
159
221
|
|
160
222
|
## Public Methods: SknContainer ONLY
|
@@ -37,8 +37,8 @@ module SknUtils
|
|
37
37
|
# end
|
38
38
|
#
|
39
39
|
# self.logger = Logger.new
|
40
|
-
# self.env
|
41
|
-
# self.root
|
40
|
+
# self.env = ENV.fetch('RACK_ENV', 'development')
|
41
|
+
# self.root = Dir.pwd
|
42
42
|
# end
|
43
43
|
#
|
44
44
|
#################
|
@@ -52,9 +52,10 @@ module SknUtils
|
|
52
52
|
# Syntax
|
53
53
|
# ###############
|
54
54
|
# Main Class Attrs
|
55
|
-
# - root
|
56
|
-
# - env
|
57
|
-
# -
|
55
|
+
# - root = application rood directory as Pathname
|
56
|
+
# - env = string value from RACK_ENV
|
57
|
+
# - registry = SknRegistry instance
|
58
|
+
# - logger = Assigned Logger instance
|
58
59
|
# #with(*user_attrs, enable_root: true|false) - defaults to enable of Main Class Attrs
|
59
60
|
# ##
|
60
61
|
# User-Defined Attrs
|
@@ -103,6 +104,12 @@ module SknUtils
|
|
103
104
|
if _app_main
|
104
105
|
# Enable Rails<Like>.env and Rails.logger like feature:
|
105
106
|
# - MyClass.env.production? or MyClass.logger or MyClass.root
|
107
|
+
def registry
|
108
|
+
@__registry ||= ::SknRegistry.new
|
109
|
+
end
|
110
|
+
def registry=(obj_instance)
|
111
|
+
@__registry = obj_instance
|
112
|
+
end
|
106
113
|
def env
|
107
114
|
@__env ||= ::SknUtils::EnvStringHandler.new( ENV.fetch('RACK_ENV', 'development') )
|
108
115
|
end
|
data/lib/skn_utils/version.rb
CHANGED
@@ -4,10 +4,11 @@
|
|
4
4
|
|
5
5
|
class MyApp
|
6
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=, and #logger=
|
7
|
+
# - and accept defaults for #env=, #root=, #registry=, and #logger=
|
8
8
|
|
9
9
|
# notice: self.logger=, the self is required when assigning values
|
10
10
|
self.logger = Object.new
|
11
|
+
self.registry = Object.new
|
11
12
|
|
12
13
|
configure do
|
13
14
|
app_id 'some app'
|
@@ -50,6 +51,9 @@ describe SknUtils::Configurable, "Gem Configuration module." do
|
|
50
51
|
it "MyApp.logger returns expected value. " do
|
51
52
|
expect( MyApp.logger ).to be_instance_of(Object) # eq('No Logger Assigned.')
|
52
53
|
end
|
54
|
+
it "MyApp.registry returns expected value. " do
|
55
|
+
expect( MyApp.registry ).to be_instance_of(Object)
|
56
|
+
end
|
53
57
|
end
|
54
58
|
|
55
59
|
context "Module & Class Operational Features. " do
|