skn_utils 4.0.0 → 4.0.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/README.md +35 -7
- data/lib/skn_utils/version.rb +1 -1
- metadata +2 -3
- data/bin/bench_linklists.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3753d9ee00c1e673e9a0871893dcb890daf35f0
|
4
|
+
data.tar.gz: d4c099ccade3b20002992624012fc5281f5e7901
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bba7536ad36ebcfb79bf9dd4f73757de8ce7c56ea99f6227dfcd5b29c3464e5c2d807c34cb1668c266aed078c80c4e15aefa98d1b75aa3606ee6edf67ad0f79
|
7
|
+
data.tar.gz: 5f41b41a42d3f15197122936145357e89109411f126c189c92f6bb33d1a240c74769e0bdccd529073934fd8d30fc58da9c9dc8740969934446ef7da5c0223a8b
|
data/README.md
CHANGED
@@ -3,18 +3,46 @@
|
|
3
3
|
|
4
4
|
# SknUtils
|
5
5
|
#### SknUtils::NestedResult class; dynamic key/value container
|
6
|
-
The intent of this gem is to be a container of data results or key/value pairs, with easy access to its contents
|
6
|
+
The intent of this gem is to be a container of nestable data results or key/value pairs, with easy access to its contents and on-demand transformation back to the creating hash (#to_hash).
|
7
7
|
|
8
|
-
Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated at runtime with an input hash. This library creates
|
9
|
-
an Object with Dot
|
10
|
-
by
|
8
|
+
A Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated at runtime with an input hash. This library creates
|
9
|
+
an Object with Dot and Hash notational accessors to each key's value. Additional key/value pairs can be added post-create
|
10
|
+
by simply assigning it; `obj.my_new_var = "some value"`
|
11
11
|
|
12
12
|
* Transforms the initialing hash into accessible object instance values, with their keys as method names.
|
13
13
|
* If the key's value is also a hash, it too will become an Object.
|
14
14
|
* if the key's value is a Array of Hashes, or Array of Arrays of Hashes, each hash element of the Arrays will become an Object.
|
15
15
|
* The current key/value (including nested) pairs are returned via #to_hash or #to_json when and if needed.
|
16
|
+
* Best described as dot notation wrapper over a Ruby (Concurrent-Ruby) Hash.
|
17
|
+
|
18
|
+
Ruby's Hash object is already extremely flexible, even more so with the addition of dot-notation. As I work more with Ruby outside of Rails, I'm finding more use cases for the capabilities of this gem. Here are a few examples:
|
19
|
+
|
20
|
+
1. Application settings containers, SknSettings. Loads Yaml file based on `ENV['RACK_ENV']` value, or specified file-key.
|
21
|
+
- Replaces Config and/or RBConfig Gems for yaml based settings
|
22
|
+
1. Substitute for Rails.root, via a little ERB/YAML/Marshal statement in settings.yml file, and a helper class
|
23
|
+
- settings.yml (YAML)
|
24
|
+
- `root: <%= Dir.pwd %>`
|
25
|
+
- enables `SknSettings.root`
|
26
|
+
- `env: !ruby/string:SknUtils::EnvStringHandler <%= ENV.fetch('RACK_ENV', 'development') %>`
|
27
|
+
- enables `SknSettings.env.production?` ...
|
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
|
+
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 displatch 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
|
+
```ruby
|
32
|
+
SknSettings.registry = {
|
33
|
+
Services::Content::Commands::RetrieveAvailableResources => method(:resources_metadata_service),
|
34
|
+
Services::Content::Commands::RetrieveResourceContent => method(:resource_content_service)
|
35
|
+
}
|
36
|
+
...
|
37
|
+
SknSettings.registry[ cmd.class ].call( cmd )
|
38
|
+
-- or --
|
39
|
+
SknSettings.registry.key?( cmd.class ) && cmd.valid? ?
|
40
|
+
SknSettings.registry[ cmd.class ].call( cmd ) :
|
41
|
+
command_not_found_action()
|
42
|
+
```
|
43
|
+
There are many more use cases for Ruby's Hash that this gem just makes easier to implement.
|
16
44
|
|
17
|
-
####
|
45
|
+
#### Available Classes
|
18
46
|
* SknSettings
|
19
47
|
* SknContainer
|
20
48
|
* SknHash
|
@@ -26,7 +54,7 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
|
|
26
54
|
* SknUtils::EnvStringHandler
|
27
55
|
* SknUtils::CoreObjectExtensions
|
28
56
|
|
29
|
-
##
|
57
|
+
## History
|
30
58
|
02/04/2018 V4.0.0
|
31
59
|
Added SknUtils::CoreObjectExtensions, this module contains those popular Rails ActiveSupport extensions like `:present?`.
|
32
60
|
- However, it is contructed with the Ruby `:refine` and `using SknUtils::CoreObjectExtensions` constraints, so as not to intefer with existing monkey-patches.
|
@@ -82,7 +110,7 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
|
|
82
110
|
|
83
111
|
|
84
112
|
## Public Components
|
85
|
-
SknUtils::NestedResult #
|
113
|
+
SknUtils::NestedResult # Primary Key/Value Container with Dot/Hash notiation support.
|
86
114
|
SknHash # Wrapper for name only, WITHOUT SknUtils namespace, inherits from SknUtils::NestedResult
|
87
115
|
SknUtils::ResultBean # Wrapper for name only, inherits from SknUtils::NestedResult
|
88
116
|
SknUtils::PageControls # Wrapper for name only, inherits from SknUtils::NestedResult
|
data/lib/skn_utils/version.rb
CHANGED
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: 4.0.
|
4
|
+
version: 4.0.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: 2018-02-
|
11
|
+
date: 2018-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -142,7 +142,6 @@ files:
|
|
142
142
|
- README.rdoc
|
143
143
|
- Rakefile
|
144
144
|
- _config.yml
|
145
|
-
- bin/bench_linklists.rb
|
146
145
|
- bin/bench_nested_result.rb
|
147
146
|
- bin/console
|
148
147
|
- lib/skn_container.rb
|
data/bin/bench_linklists.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#
|
4
|
-
# Ref: https://github.com/evanphx/benchmark-ips
|
5
|
-
#
|
6
|
-
|
7
|
-
require 'bundler/setup'
|
8
|
-
require 'skn_utils'
|
9
|
-
require 'ostruct'
|
10
|
-
require 'benchmark/ips'
|
11
|
-
|
12
|
-
class GCSuite
|
13
|
-
def warming(*)
|
14
|
-
run_gc
|
15
|
-
end
|
16
|
-
|
17
|
-
def running(*)
|
18
|
-
run_gc
|
19
|
-
end
|
20
|
-
|
21
|
-
def warmup_stats(*)
|
22
|
-
end
|
23
|
-
|
24
|
-
def add_report(*)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def run_gc
|
30
|
-
GC.enable
|
31
|
-
GC.start
|
32
|
-
GC.disable
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
suite = GCSuite.new
|
37
|
-
|
38
|
-
# Warming up --------------------------------------
|
39
|
-
# LinkedList Ops 2.297k i/100ms
|
40
|
-
# Array Ops 34.468k i/100ms
|
41
|
-
# Calculating -------------------------------------
|
42
|
-
# LinkedList Ops 17.015k (±35.2%) i/s - 71.207k in 5.100193s
|
43
|
-
# Array Ops 377.943k (± 7.3%) i/s - 1.896M in 5.048217s
|
44
|
-
#
|
45
|
-
# Comparison:
|
46
|
-
# Array Ops: 377942.7 i/s
|
47
|
-
# LinkedList Ops: 17015.4 i/s - 22.21x slower
|
48
|
-
|
49
|
-
|
50
|
-
Benchmark.ips do |x|
|
51
|
-
x.config(:suite => suite)
|
52
|
-
|
53
|
-
adders = [50, 10, 110, 6, 30, 101, 12, 33, 4]
|
54
|
-
vargs = [70, 71, 72, 73, 74, 75, 76, 77, 78, 79]
|
55
|
-
cproc = lambda {|a| a}
|
56
|
-
|
57
|
-
x.report('Array Ops') do
|
58
|
-
ary = Array.new(vargs)
|
59
|
-
# adders.each {|x| ary.push(x) }
|
60
|
-
adders.each {|x| ary.insert(5, x) }
|
61
|
-
value = ary.sort!
|
62
|
-
ary.first
|
63
|
-
ary.clear
|
64
|
-
end
|
65
|
-
|
66
|
-
x.report('Single Ops') do
|
67
|
-
ll = SknUtils::Lists::LinkedList.new(*vargs, &cproc)
|
68
|
-
# adders.each {|x| ll.insert(x) }
|
69
|
-
adders.each {|x| ll.insert_after(74, x) }
|
70
|
-
value = ll.sort!
|
71
|
-
ll.first
|
72
|
-
ll.clear
|
73
|
-
end
|
74
|
-
|
75
|
-
x.report('Double Ops') do
|
76
|
-
dll = SknUtils::Lists::DoublyLinkedList.new(*vargs, &cproc)
|
77
|
-
# adders.each {|x| dll.insert(x) }
|
78
|
-
adders.each {|x| dll.insert_after(74, x) }
|
79
|
-
value = dll.sort!
|
80
|
-
dll.first
|
81
|
-
dll.clear
|
82
|
-
end
|
83
|
-
|
84
|
-
x.report('Circulat Ops') do
|
85
|
-
cl = SknUtils::Lists::CircularLinkedList.new(*vargs, &cproc)
|
86
|
-
# adders.each {|x| cl.insert(x) }
|
87
|
-
adders.each {|x| cl.insert_after(74, x) }
|
88
|
-
value = cl.sort!
|
89
|
-
cl.first
|
90
|
-
cl.clear
|
91
|
-
end
|
92
|
-
|
93
|
-
x.compare!
|
94
|
-
end
|