skn_utils 3.5.2 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -83
- data/_config.yml +24 -1
- data/bin/console +0 -4
- data/lib/skn_utils/nested_result.rb +5 -5
- data/lib/skn_utils/version.rb +2 -2
- data/lib/skn_utils.rb +2 -18
- data/skn_utils.gemspec +0 -6
- data/spec/spec_helper.rb +0 -4
- metadata +3 -49
- data/lib/skn_utils/business_services/year_month.rb +0 -58
- data/lib/skn_utils/converters/hash_to_xml.rb +0 -98
- data/lib/skn_utils/exploring/action_service.rb +0 -90
- data/lib/skn_utils/exploring/commander.rb +0 -68
- data/lib/skn_utils/exploring/configuration.rb +0 -53
- data/lib/skn_utils/lists/circular_linked_list.rb +0 -161
- data/lib/skn_utils/lists/doubly_linked_list.rb +0 -139
- data/lib/skn_utils/lists/link_node.rb +0 -103
- data/lib/skn_utils/lists/linked_commons.rb +0 -216
- data/lib/skn_utils/lists/linked_list.rb +0 -122
- data/spec/lib/skn_utils/business_services/year_month_spec.rb +0 -49
- data/spec/lib/skn_utils/converters/hash_to_xml_spec.rb +0 -120
- data/spec/lib/skn_utils/exploring/action_service_spec.rb +0 -40
- data/spec/lib/skn_utils/exploring/commander_spec.rb +0 -125
- data/spec/lib/skn_utils/exploring/configuration_spec.rb +0 -52
- data/spec/lib/skn_utils/lists/Circular_linked_list_spec.rb +0 -184
- data/spec/lib/skn_utils/lists/doubly_linked_list_spec.rb +0 -182
- data/spec/lib/skn_utils/lists/linked_list_spec.rb +0 -155
- data/spec/lib/skn_utils/lists/node_based_linked_list_spec.rb +0 -86
- data/spec/support/shared_examples_for_linked_list.rb +0 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f318459d97979405431fd4e09eb85d8688707636
|
4
|
+
data.tar.gz: 350ee31b2176feae8d567d02e649eb220b2c8a0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c10cff645d8c75d49abe41ef1b438ba0e3e057f509bd9454133cb9e0bdf32840c82b7a5c861f7ec3787d8565b5f10617cb0dc2cfca9439cd27a28cbdcf31f07e
|
7
|
+
data.tar.gz: 904d521b3bc3849a8bc6e71e7f0376668ed378e7fdd887e83279486a016b8710c068ebd3c8dbe59250224de26d78a11267c19263b71816f503406975d0b00ec5
|
data/README.md
CHANGED
@@ -16,6 +16,10 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
|
|
16
16
|
|
17
17
|
|
18
18
|
## New Features
|
19
|
+
01/2018 V3.6.0
|
20
|
+
Moved Linked List to my Minimum_Heaps gem. This repo has a tag of 'lists' documententing the removal
|
21
|
+
Removed classes and utils not directly related to NestedResult
|
22
|
+
|
19
23
|
12/2017 V3.5.0
|
20
24
|
Made Nokogiri's gem install/load Optional for HashToXml class
|
21
25
|
Added SknContainer as a globally namespaced sub-class of NestedResult. SknContainer is a NestedResult which is functional wrapper over a Concurrent::Hash. Hashes can use anyObject or anyValue as their key:value pairs. This makes them perfect for use as a DI Container.
|
@@ -63,96 +67,19 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
|
|
63
67
|
|
64
68
|
## Public Components
|
65
69
|
SknUtils::NestedResult # >= V 3.0.0 Primary Key/Value Container with Dot/Hash notiation support.
|
66
|
-
SknSettings # Multi-level application Configuration class, Key/Value Container with Dot/Hash notiation support.
|
67
70
|
SknHash # Wrapper for name only, WITHOUT SknUtils namespace, inherits from SknUtils::NestedResult
|
68
71
|
SknUtils::ResultBean # Wrapper for name only, inherits from SknUtils::NestedResult
|
69
72
|
SknUtils::PageControls # Wrapper for name only, inherits from SknUtils::NestedResult
|
70
73
|
|
71
|
-
|
72
|
-
SknUtils::Converters::HashToXml # #call(hash) to convert Ruby complex hashes into XML
|
73
|
-
|
74
|
-
|
75
|
-
SknUtils::List::LinkedList # List with forward (#next) navigation, and tail/open
|
76
|
-
SknUtils::List::DoublyLinkedList # List with forward (#next) and backward (#prev) navigation, and head/tail open
|
77
|
-
SknUtils::List::CircularLinkedList # List with forward (#next) and backward (#prev) navigation, and head/tail wrapping
|
74
|
+
SknSettings # Multi-level application Configuration class, Key/Value Container with Dot/Hash notiation support.
|
78
75
|
|
76
|
+
SknUtils::Configurable # Basic one-level configuration settings module for Applications and or Gems
|
79
77
|
|
80
78
|
|
81
79
|
## Configuration Options
|
82
80
|
None required other than initialization hash
|
83
81
|
|
84
82
|
|
85
|
-
## Public Methods: SknUtils::Lists::LinkedList, SknUtils::Lists::DoublyLinkedList, and SknUtils::Lists::CircularLinkedList
|
86
|
-
#### Each concrete Class supports the following methods: Value based interface
|
87
|
-
Value based interface presumes a direct reference to the object is maintained and the following methods will be called on that
|
88
|
-
object instance as needed. Each method will generally return the value contained in the node, Nil, or the int number of nodes
|
89
|
-
remaining.
|
90
|
-
|
91
|
-
Navigation: return related value from relative positon in list, stops on first/last node for Single/Double, wraps for Circular.
|
92
|
-
|
93
|
-
#first -- returns first value in list
|
94
|
-
#next -- returns next value from current position
|
95
|
-
#current -- returns current value
|
96
|
-
#prev -- returns previous value from current position (*not supported in Single)
|
97
|
-
#last -- returns last value from list
|
98
|
-
#nth(i) -- returns value of node at +|- positon relative to current position, (*negative not supported in Singular)
|
99
|
-
#at_index(i) -- returns value of i node relative to list's head
|
100
|
-
|
101
|
-
Enumeration
|
102
|
-
#each -- yields each value in list when block given, on Enumerator object
|
103
|
-
#to_a -- returns Array of each value in the list
|
104
|
-
|
105
|
-
State
|
106
|
-
#node -- returns the current node (LinkedNode class)
|
107
|
-
#clear -- removes all elements and return number of elements removed
|
108
|
-
#empty? -- returns true if list has no elements, otherwise false
|
109
|
-
#size -- returns total count of elements in the list
|
110
|
-
#sort!(:direction, &block) -- Sort existing list in place using :direction (:asc,:desc, :default) symbol
|
111
|
-
if block is given, overrides :direction and uses custom proc to compare values
|
112
|
-
block format is: {|a,b| a >= b }; example: 'll.sort(:default) {|a,b| a <= b}'
|
113
|
-
|
114
|
-
Modification: returns number of elements in the list after the operation
|
115
|
-
|
116
|
-
#insert(value) -- inserts value after node at current positon, or appends
|
117
|
-
#append(value) -- inserts value after node at current positon
|
118
|
-
#prepend(value) -- inserts value before node at current positon
|
119
|
-
#insert_before(position_value, value) -- finds node matching position_value, then prepends new node
|
120
|
-
#insert_after(position_value, value) -- finds node matching position_value, then appends new node
|
121
|
-
#remove(value) -- finds first node matching value, then destroys it
|
122
|
-
|
123
|
-
Initialization: optional &block to identify data key
|
124
|
-
|
125
|
-
#new(*vargs, &block) -- Instansiates new list and optionally creates nodes from each comma-seperated value;
|
126
|
-
also, assigns &block as default value identifier for find and sort operations
|
127
|
-
returns a class instance.
|
128
|
-
compare_key_block example: instance = LinkedList.new({:key=>"Z"},{:key=>"S"},{:key=>"N"}) {|a| a[:key]}
|
129
|
-
|
130
|
-
#### Each concrete Class supports the following methods: Node based interface
|
131
|
-
Node based interface presumes a node is retrieved from the LinkedList, then using that/any available node all other methods
|
132
|
-
may be used. Methods in play will include the LinkedNode (#next, #value, and #prev), along with all public methods from
|
133
|
-
the main class.
|
134
|
-
|
135
|
-
Navigation: return related Node from relative positon in list, stops on first/last node for Single/Double, wraps for Circular.
|
136
|
-
|
137
|
-
#first_node -- returns first node
|
138
|
-
#next_node -- returns next node from current position
|
139
|
-
#current_node -- returns current or last accessed node
|
140
|
-
#prev_node -- returns previous node from current position (*not supported in Single)
|
141
|
-
#last_node -- returns last node in list
|
142
|
-
#node_value -- returns value of the current/receiver node: $ receiver.node_value
|
143
|
-
#node_request(method_sym, *vargs, &block)
|
144
|
-
-- executes any method on the Value based Interface, returning a node
|
145
|
-
#node_value_request(method_sym, *vargs, &block)
|
146
|
-
-- executes any method on the Value based Interface, returning result value
|
147
|
-
|
148
|
-
Initialization: optional &block to identify data key
|
149
|
-
|
150
|
-
#call(*vargs, &block) -- Instansiates new list and creates nodes from each comma-seperated value;
|
151
|
-
also, assigns &block as default value identifier for find and sort operations
|
152
|
-
returns the first node -- else class instance
|
153
|
-
compare_key_block example: node = LinkedList.call({:key=>"Z"},{:key=>"S"},{:key=>"N"}) {|a| a[:key]}
|
154
|
-
|
155
|
-
|
156
83
|
## Public Methods: SknSettings ONLY
|
157
84
|
SknSettings is global constant containing an initialized Object of SknUtils::SknConfiguration using defaults
|
158
85
|
To change the 'development'.yml default please use the following method early or in the case of Rails in 'application.rb
|
@@ -283,10 +210,10 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
|
|
283
210
|
|
284
211
|
## Installation
|
285
212
|
|
286
|
-
runtime prereqs:
|
287
|
-
|
288
|
-
|
289
|
-
|
213
|
+
runtime prereqs:
|
214
|
+
V3+ None
|
215
|
+
V2+ None
|
216
|
+
V1+ gem 'active_model', '~> 3.0'
|
290
217
|
|
291
218
|
|
292
219
|
Add this line to your application's Gemfile:
|
data/_config.yml
CHANGED
@@ -1 +1,24 @@
|
|
1
|
-
|
1
|
+
title: SknUtils
|
2
|
+
email: skoona@gmail.com
|
3
|
+
description: > # this means to ignore newlines until "baseurl:"
|
4
|
+
Ruby GEM containing utilitarian classes to help build Ruby applications. SknUtils::NestedResult is the primary class. It is
|
5
|
+
a threadsafe wrapper over Ruby's Hash with dot.notation, ?.presence, and nested deep-merge features added. I use it for application
|
6
|
+
settings via YAML files, and as a container for persistent objects.
|
7
|
+
baseurl: ""
|
8
|
+
url: https://skoona.github.io/SknServices
|
9
|
+
|
10
|
+
twitter_username: JamesScottiii
|
11
|
+
twitter:
|
12
|
+
username: jamesscottiii
|
13
|
+
|
14
|
+
theme: jekyll-theme-cayman
|
15
|
+
|
16
|
+
github_username: skoona
|
17
|
+
github:
|
18
|
+
username: skoona
|
19
|
+
|
20
|
+
# paginate: 1
|
21
|
+
author:
|
22
|
+
name: "James Scott, Jr. (a.k.a Skoona)"
|
23
|
+
url: https://keybase.io/skoona
|
24
|
+
|
data/bin/console
CHANGED
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'skn_utils'
|
5
|
-
require 'skn_utils/business_services/year_month'
|
6
|
-
require 'skn_utils/exploring/commander'
|
7
|
-
require 'skn_utils/exploring/action_service'
|
8
|
-
require 'skn_utils/exploring/configuration'
|
9
5
|
|
10
6
|
require 'pry'
|
11
7
|
Pry.start
|
@@ -93,8 +93,8 @@
|
|
93
93
|
module SknUtils
|
94
94
|
class NestedResult
|
95
95
|
|
96
|
-
def initialize(params={})
|
97
|
-
reset_from_empty!(params)
|
96
|
+
def initialize(params={}, mod=true)
|
97
|
+
reset_from_empty!(params, mod)
|
98
98
|
end
|
99
99
|
|
100
100
|
def [](attr)
|
@@ -220,7 +220,7 @@ module SknUtils
|
|
220
220
|
# Feature: attribute must exist and have a non-blank value to cause this method to return true
|
221
221
|
def attribute?(attr)
|
222
222
|
return false unless container.key?(key_as_sym(attr))
|
223
|
-
![ "", " ", nil, [],[""], [" "],
|
223
|
+
![ "", " ", nil, [],[""], [" "], self.class.new({}), [[]]].any? {|a| a == container[key_as_sym(attr)] }
|
224
224
|
end
|
225
225
|
|
226
226
|
# Feature: returns a hash of all attributes and their current values
|
@@ -282,7 +282,7 @@ module SknUtils
|
|
282
282
|
# Feature: unwrap array of array-of-hashes/object
|
283
283
|
def array_to_hash(array)
|
284
284
|
case array
|
285
|
-
when
|
285
|
+
when self.class
|
286
286
|
array.to_hash
|
287
287
|
when Array
|
288
288
|
array.map { |element| array_to_hash(element) }
|
@@ -295,7 +295,7 @@ module SknUtils
|
|
295
295
|
def translate_value(value)
|
296
296
|
case value
|
297
297
|
when Hash
|
298
|
-
|
298
|
+
self.class.new(value)
|
299
299
|
when Array
|
300
300
|
value.map { |element| translate_value(element) }
|
301
301
|
else
|
data/lib/skn_utils/version.rb
CHANGED
data/lib/skn_utils.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
require "skn_utils/version"
|
2
3
|
require 'psych'
|
3
4
|
require 'json'
|
@@ -8,7 +9,6 @@ require 'concurrent'
|
|
8
9
|
unless defined?(Rails)
|
9
10
|
begin
|
10
11
|
require 'deep_merge'
|
11
|
-
require 'nokogiri'
|
12
12
|
rescue LoadError => e
|
13
13
|
puts e.message
|
14
14
|
end
|
@@ -21,25 +21,9 @@ require 'skn_utils/null_object'
|
|
21
21
|
require 'skn_utils/notifier_base'
|
22
22
|
require 'skn_utils/skn_configuration'
|
23
23
|
require 'skn_utils/configurable'
|
24
|
-
require 'skn_utils/lists/linked_commons'
|
25
|
-
require 'skn_utils/lists/link_node'
|
26
|
-
require 'skn_utils/lists/linked_list'
|
27
|
-
require 'skn_utils/lists/doubly_linked_list'
|
28
|
-
require 'skn_utils/lists/circular_linked_list'
|
29
|
-
# require 'skn_utils/business_services/year_month'
|
30
|
-
# require 'skn_utils/exploring/commander'
|
31
|
-
# require 'skn_utils/exploring/action_service'
|
32
|
-
# require 'skn_utils/exploring/configuration'
|
33
|
-
|
34
|
-
if defined?(::Nokogiri)
|
35
|
-
begin
|
36
|
-
require 'skn_utils/converters/hash_to_xml'
|
37
|
-
rescue LoadError, StandardError
|
38
|
-
puts 'NotFound -> Converters::HashToXml class depends on Gem:NokoGiri which is not installed at this time.'
|
39
|
-
end
|
40
|
-
end
|
41
24
|
|
42
25
|
require 'skn_hash'
|
26
|
+
require 'skn_container'
|
43
27
|
require 'skn_settings'
|
44
28
|
|
45
29
|
module SknUtils
|
data/skn_utils.gemspec
CHANGED
@@ -21,11 +21,6 @@ EOF
|
|
21
21
|
spec.post_install_message = <<-EOF
|
22
22
|
This version includes modified versions of SknUtils::ResultBean, SknUtils::PageControls classes, which inherit from
|
23
23
|
SknUtils::NestedResult class. SknUtils::NestedResult replaces those original classes and consolidates their function.
|
24
|
-
|
25
|
-
Please update your existing code in consideration of the above change, or use the prior version 2.0.6.
|
26
|
-
|
27
|
-
Additionally, The gem nokogiri may be manually installed, for non-Rails applications, to enable SknUtils::HashToXml feature.
|
28
|
-
|
29
24
|
EOF
|
30
25
|
spec.homepage = "https://github.com/skoona/skn_utils"
|
31
26
|
spec.license = "MIT"
|
@@ -44,6 +39,5 @@ EOF
|
|
44
39
|
spec.add_development_dependency "pry", "~> 0"
|
45
40
|
spec.add_development_dependency "simplecov", "~> 0"
|
46
41
|
spec.add_development_dependency 'benchmark-ips', '~> 2'
|
47
|
-
spec.add_development_dependency 'nokogiri', '~> 1.8'
|
48
42
|
|
49
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,10 +12,6 @@ SimpleCov.start do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
require 'skn_utils'
|
15
|
-
require 'skn_utils/exploring/commander'
|
16
|
-
require 'skn_utils/exploring/action_service'
|
17
|
-
require 'skn_utils/exploring/configuration'
|
18
|
-
require 'skn_utils/business_services/year_month'
|
19
15
|
require 'rspec'
|
20
16
|
|
21
17
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
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: 3.
|
4
|
+
version: 3.6.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:
|
11
|
+
date: 2018-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -122,20 +122,6 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '2'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: nokogiri
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '1.8'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '1.8'
|
139
125
|
description: "The intent of the NestedResult class is to be a container for data values
|
140
126
|
composed of key/value pairs, \nwith easy access to its contents, and on-demand transformation
|
141
127
|
back to the hash (#to_hash).\n\nReview the RSpec tests, and or review the README
|
@@ -163,18 +149,8 @@ files:
|
|
163
149
|
- lib/skn_hash.rb
|
164
150
|
- lib/skn_settings.rb
|
165
151
|
- lib/skn_utils.rb
|
166
|
-
- lib/skn_utils/business_services/year_month.rb
|
167
152
|
- lib/skn_utils/configurable.rb
|
168
|
-
- lib/skn_utils/converters/hash_to_xml.rb
|
169
153
|
- lib/skn_utils/env_string_handler.rb
|
170
|
-
- lib/skn_utils/exploring/action_service.rb
|
171
|
-
- lib/skn_utils/exploring/commander.rb
|
172
|
-
- lib/skn_utils/exploring/configuration.rb
|
173
|
-
- lib/skn_utils/lists/circular_linked_list.rb
|
174
|
-
- lib/skn_utils/lists/doubly_linked_list.rb
|
175
|
-
- lib/skn_utils/lists/link_node.rb
|
176
|
-
- lib/skn_utils/lists/linked_commons.rb
|
177
|
-
- lib/skn_utils/lists/linked_list.rb
|
178
154
|
- lib/skn_utils/nested_result.rb
|
179
155
|
- lib/skn_utils/notifier_base.rb
|
180
156
|
- lib/skn_utils/null_object.rb
|
@@ -187,21 +163,11 @@ files:
|
|
187
163
|
- spec/factories/settings/test.local.yml
|
188
164
|
- spec/factories/settings/test.yml
|
189
165
|
- spec/lib/skn_settings_spec.rb
|
190
|
-
- spec/lib/skn_utils/business_services/year_month_spec.rb
|
191
166
|
- spec/lib/skn_utils/configurable_spec.rb
|
192
|
-
- spec/lib/skn_utils/converters/hash_to_xml_spec.rb
|
193
|
-
- spec/lib/skn_utils/exploring/action_service_spec.rb
|
194
|
-
- spec/lib/skn_utils/exploring/commander_spec.rb
|
195
|
-
- spec/lib/skn_utils/exploring/configuration_spec.rb
|
196
|
-
- spec/lib/skn_utils/lists/Circular_linked_list_spec.rb
|
197
|
-
- spec/lib/skn_utils/lists/doubly_linked_list_spec.rb
|
198
|
-
- spec/lib/skn_utils/lists/linked_list_spec.rb
|
199
|
-
- spec/lib/skn_utils/lists/node_based_linked_list_spec.rb
|
200
167
|
- spec/lib/skn_utils/nested_result_spec.rb
|
201
168
|
- spec/lib/skn_utils/notifier_base_spec.rb
|
202
169
|
- spec/lib/skn_utils/null_object_spec.rb
|
203
170
|
- spec/spec_helper.rb
|
204
|
-
- spec/support/shared_examples_for_linked_list.rb
|
205
171
|
homepage: https://github.com/skoona/skn_utils
|
206
172
|
licenses:
|
207
173
|
- MIT
|
@@ -209,9 +175,7 @@ metadata: {}
|
|
209
175
|
post_install_message: "This version includes modified versions of SknUtils::ResultBean,
|
210
176
|
SknUtils::PageControls classes, which inherit from \nSknUtils::NestedResult class.
|
211
177
|
\ SknUtils::NestedResult replaces those original classes and consolidates their
|
212
|
-
function. \n
|
213
|
-
or use the prior version 2.0.6.\n\nAdditionally, The gem nokogiri may be manually
|
214
|
-
installed, for non-Rails applications, to enable SknUtils::HashToXml feature.\n\n"
|
178
|
+
function. \n"
|
215
179
|
rdoc_options: []
|
216
180
|
require_paths:
|
217
181
|
- lib
|
@@ -237,18 +201,8 @@ test_files:
|
|
237
201
|
- spec/factories/settings/test.local.yml
|
238
202
|
- spec/factories/settings/test.yml
|
239
203
|
- spec/lib/skn_settings_spec.rb
|
240
|
-
- spec/lib/skn_utils/business_services/year_month_spec.rb
|
241
204
|
- spec/lib/skn_utils/configurable_spec.rb
|
242
|
-
- spec/lib/skn_utils/converters/hash_to_xml_spec.rb
|
243
|
-
- spec/lib/skn_utils/exploring/action_service_spec.rb
|
244
|
-
- spec/lib/skn_utils/exploring/commander_spec.rb
|
245
|
-
- spec/lib/skn_utils/exploring/configuration_spec.rb
|
246
|
-
- spec/lib/skn_utils/lists/Circular_linked_list_spec.rb
|
247
|
-
- spec/lib/skn_utils/lists/doubly_linked_list_spec.rb
|
248
|
-
- spec/lib/skn_utils/lists/linked_list_spec.rb
|
249
|
-
- spec/lib/skn_utils/lists/node_based_linked_list_spec.rb
|
250
205
|
- spec/lib/skn_utils/nested_result_spec.rb
|
251
206
|
- spec/lib/skn_utils/notifier_base_spec.rb
|
252
207
|
- spec/lib/skn_utils/null_object_spec.rb
|
253
208
|
- spec/spec_helper.rb
|
254
|
-
- spec/support/shared_examples_for_linked_list.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# File: <gem-root>/lib/skn_utils/business_services/year_month.rb
|
3
|
-
# Ref: http://blog.arkency.com/2014/08/using-ruby-range-with-custom-classes/
|
4
|
-
#
|
5
|
-
## Calculates YearMonth
|
6
|
-
#
|
7
|
-
# YearMonth.new(2014, 3) > YearMonth.new(2014, 1)
|
8
|
-
# => true
|
9
|
-
|
10
|
-
# YearMonth.new(2014, 1) >= YearMonth.new(2014, 1)
|
11
|
-
# => true
|
12
|
-
|
13
|
-
# YearMonth.new(2015, 1) < YearMonth.new(2014, 3)
|
14
|
-
# => false
|
15
|
-
#
|
16
|
-
module SknUtils
|
17
|
-
module BusinessServices
|
18
|
-
|
19
|
-
class YearMonth < Struct.new(:year, :month)
|
20
|
-
include Comparable
|
21
|
-
|
22
|
-
def initialize(iyear, imonth)
|
23
|
-
cleaned_year = iyear.to_i
|
24
|
-
cleaned_month = imonth.to_i
|
25
|
-
|
26
|
-
raise ArgumentError unless cleaned_year > 0
|
27
|
-
raise ArgumentError unless cleaned_month >= 1 && cleaned_month <= 12
|
28
|
-
|
29
|
-
super(cleaned_year, cleaned_month)
|
30
|
-
end
|
31
|
-
|
32
|
-
def next
|
33
|
-
if month == 12
|
34
|
-
self.class.new(year+1, 1)
|
35
|
-
else
|
36
|
-
self.class.new(year, month+1)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
alias_method :succ, :next
|
40
|
-
|
41
|
-
def <=>(other)
|
42
|
-
(year <=> other.year).nonzero? || month <=> other.month
|
43
|
-
end
|
44
|
-
|
45
|
-
# need to do some time calcs
|
46
|
-
|
47
|
-
def beginning_of
|
48
|
-
Time.parse("12:00",Date.new(year, month, 1).to_time) # strftime('%Y-%m-%d')
|
49
|
-
end
|
50
|
-
|
51
|
-
def end_of
|
52
|
-
Time.parse("12:00",Date.new(year, month, -1).to_time) # strftime('%Y-%m-%d')
|
53
|
-
end
|
54
|
-
|
55
|
-
private :year=, :month=
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
## lib/skn_utils/converters/hash_to_xml.rb
|
2
|
-
#
|
3
|
-
# Converts Simple Hash to XML, or a Complex nested hash to XML
|
4
|
-
# Ref: https://stackoverflow.com/questions/11933451/converting-nested-hash-into-xml-using-nokogiri
|
5
|
-
#
|
6
|
-
# Input Format:
|
7
|
-
# {
|
8
|
-
# someKey: someValue,
|
9
|
-
# list: {item: [1,2,3]},
|
10
|
-
# listings: {
|
11
|
-
# uri: 'topic/content/topic_value',
|
12
|
-
# '@attributes' => {secured: true}
|
13
|
-
# }
|
14
|
-
# }
|
15
|
-
#
|
16
|
-
# - produces:
|
17
|
-
# <?xml version="1.0"?>
|
18
|
-
# <root>
|
19
|
-
# <one>1</one>
|
20
|
-
# <two>2</two>
|
21
|
-
# <list>
|
22
|
-
# <item>1</item>
|
23
|
-
# <item>2</item>
|
24
|
-
# <item>3</item>
|
25
|
-
# </list>
|
26
|
-
# <listings secured="true">
|
27
|
-
# <uri>topic/content/topic_value</uri>
|
28
|
-
# </listings>
|
29
|
-
# </basic>
|
30
|
-
##
|
31
|
-
# xml_string = SknUtils::Converters::HashToXml.call(hash)
|
32
|
-
##
|
33
|
-
module SknUtils
|
34
|
-
module Converters
|
35
|
-
|
36
|
-
class HashToXml
|
37
|
-
|
38
|
-
def initialize(*args)
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.call(*vargs_with_at_least_one_hash, &block)
|
42
|
-
new().call(*vargs_with_at_least_one_hash, &block)
|
43
|
-
end
|
44
|
-
|
45
|
-
def call(*vargs, &block)
|
46
|
-
return nil if vargs.size == 0
|
47
|
-
hash = generate_xml(*vargs )
|
48
|
-
yield hash if block_given?
|
49
|
-
hash
|
50
|
-
end
|
51
|
-
|
52
|
-
protected
|
53
|
-
|
54
|
-
##
|
55
|
-
# generate xml from a hash of hashes or array of hashes
|
56
|
-
def generate_xml(data, parent = false, opt = {})
|
57
|
-
return if data.to_s.empty?
|
58
|
-
return unless data.is_a?(Hash)
|
59
|
-
|
60
|
-
unless parent
|
61
|
-
# assume that if the hash has a single key that it should be the root
|
62
|
-
root, data = (data.length == 1) ? [data.keys.first.to_s , data] : ["root", data]
|
63
|
-
builder = ::Nokogiri::XML::Builder.new(opt.merge(:encoding => 'UTF-8')) do |xml|
|
64
|
-
xml.send(root) {
|
65
|
-
generate_xml(data, xml)
|
66
|
-
}
|
67
|
-
end
|
68
|
-
|
69
|
-
return builder.to_xml
|
70
|
-
end
|
71
|
-
|
72
|
-
data.each do |label, value|
|
73
|
-
if value.is_a?(Hash)
|
74
|
-
attrs = value.fetch('@attributes', {})
|
75
|
-
# also passing 'text' as a key makes nokogiri do the same thing
|
76
|
-
text = value.fetch('@text', '')
|
77
|
-
parent.send(label, attrs, text) {
|
78
|
-
value.delete('@attributes')
|
79
|
-
value.delete('@text')
|
80
|
-
generate_xml(value, parent)
|
81
|
-
}
|
82
|
-
|
83
|
-
elsif value.is_a?(Array)
|
84
|
-
value.each do |el|
|
85
|
-
# lets trick the above into firing so we do not need to rewrite the checks
|
86
|
-
el = {label => el}
|
87
|
-
generate_xml(el, parent)
|
88
|
-
end
|
89
|
-
|
90
|
-
else
|
91
|
-
parent.send(label, value)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end # end method
|
95
|
-
|
96
|
-
end # end class
|
97
|
-
end
|
98
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
## lib/skn_utils/action_service.rb
|
2
|
-
#
|
3
|
-
# Exploratory Action/Service Class
|
4
|
-
# Ref: https://blog.lelonek.me/what-service-objects-are-not-7abef8aa2f99#.p64vudxq4
|
5
|
-
# http://sporto.github.io/blog/2012/11/15/a-pattern-for-service-objects-in-rails/
|
6
|
-
#
|
7
|
-
# Not a template or abstract class, Just an Example of an Action class
|
8
|
-
#
|
9
|
-
|
10
|
-
module SknUtils
|
11
|
-
module Exploring
|
12
|
-
class ActionService
|
13
|
-
|
14
|
-
def initialize(dependency_injection_arguments)
|
15
|
-
@thingy = dependency_injection_arguments
|
16
|
-
end
|
17
|
-
|
18
|
-
def call(*command_and_params)
|
19
|
-
puts "Called with: #{command_and_params}"
|
20
|
-
if command_and_params.first.is_a?(Symbol)
|
21
|
-
(command_and_params.size == 1 ? self.send(command_and_params.first) : self.send(command_and_params.first, command_and_params[1..-1]))
|
22
|
-
else
|
23
|
-
puts('No Action Taken')
|
24
|
-
end
|
25
|
-
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
# a bunch of private methods
|
31
|
-
def action_one
|
32
|
-
puts "#{__method__}() #{@thingy}"
|
33
|
-
true
|
34
|
-
end
|
35
|
-
|
36
|
-
def action_two(parm)
|
37
|
-
puts "#{__method__} => #{parm} #{@thingy}"
|
38
|
-
true
|
39
|
-
end
|
40
|
-
|
41
|
-
end # end class
|
42
|
-
end # end module
|
43
|
-
end # end module
|
44
|
-
|
45
|
-
|
46
|
-
# - regular execution
|
47
|
-
# action = DoSomeAction.new.(arg1, arg2)
|
48
|
-
#
|
49
|
-
# action.('Mine')
|
50
|
-
# => Called with: ["Mine"]
|
51
|
-
# => "No Action Taken"
|
52
|
-
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
53
|
-
#
|
54
|
-
# action.()
|
55
|
-
# =>Called with: []
|
56
|
-
# => "No Action Taken"
|
57
|
-
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
58
|
-
#
|
59
|
-
# action.(:action_two,'samples')
|
60
|
-
# => Called with: [:action_two, "samples"]
|
61
|
-
# => action_two(["samples"]) with Thingy: Things
|
62
|
-
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
63
|
-
#
|
64
|
-
# action.(:action_one,'samples')
|
65
|
-
# => Called with: [:action_one, "samples"]
|
66
|
-
# => action_one() Thingy: Things
|
67
|
-
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
68
|
-
#
|
69
|
-
# action.(:action_one).(:action_two,'Always')
|
70
|
-
# => Called with: [:action_one]
|
71
|
-
# => action_one() Thingy: Things
|
72
|
-
# => Called with: [:action_two, "Always"]
|
73
|
-
# => action_two(["Always"]) with Thingy: Things
|
74
|
-
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
75
|
-
#
|
76
|
-
# - with dependency injection
|
77
|
-
#
|
78
|
-
# def do_some_action
|
79
|
-
# DoSomeAction.new(http_adapter)
|
80
|
-
# end
|
81
|
-
#
|
82
|
-
# do_some_action.(arg1, arg2)
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
# - in tests
|
87
|
-
#
|
88
|
-
# let(:do_some_action) { DoSomeAction.new(fake_http_adapter) }
|
89
|
-
# it { is_expected.to be_connected }
|
90
|
-
#
|