tins 1.35.0 → 1.36.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/CHANGES.md +13 -2
- data/lib/tins/hash_bfs.rb +26 -10
- data/lib/tins/version.rb +1 -1
- data/tests/hash_bfs_test.rb +2 -2
- data/tins.gemspec +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d0d3b142299555332881bdd390e8cb2fc4137cbbb92864e96c835790d1f943
|
4
|
+
data.tar.gz: c287721ce6b44fb9a1cc4faed1eee2d6f0df250a92c389e811bc033b9c24a48a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a950643986122ff5e47e419657dbe5f76ffe1d1c80927ab9767297672a5296d08b84479b0ae03fcf7d5112c5297cdc3d8993425488c203321615dad441d7c6d
|
7
|
+
data.tar.gz: abec6e88bb19153688f7e5c8069c3ac13fcff850aa9860f4924b360bdb53608d82deabbb8d0d35a234ff84e8149869861fe94b8963ba1187e7ae252d1bafe7af
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2024-10-11 v1.36.0
|
4
|
+
|
5
|
+
### Significant Changes
|
6
|
+
|
7
|
+
* Refactor bfs method in `hash_bfs.rb`:
|
8
|
+
+ Rename `include_nodes` variable to `visit_interal`
|
9
|
+
+ Update test cases in `hash_bfs_test.rb` to use new method signature
|
10
|
+
+ Update method signature and docstring to reflect new behavior
|
11
|
+
* Update hash conversion logic:
|
12
|
+
+ Rename method parameter from `v` to `object`
|
13
|
+
+ Use `object` instead of `v` consistently throughout the method
|
14
|
+
+ Add documentation for new method name and behavior
|
15
|
+
|
3
16
|
## 2024-10-10 v1.35.0
|
4
17
|
|
5
18
|
### New Features
|
@@ -23,8 +36,6 @@
|
|
23
36
|
|
24
37
|
## 2024-09-30 v1.34.0
|
25
38
|
|
26
|
-
### Changes in **1.34.0**
|
27
|
-
|
28
39
|
* **Secure write functionality updated**
|
29
40
|
+ Added support for `Pathname` objects in `secure_write`
|
30
41
|
+ Updated `File.new` call to use `to_s` method on filename
|
data/lib/tins/hash_bfs.rb
CHANGED
@@ -6,10 +6,21 @@ module Tins
|
|
6
6
|
|
7
7
|
thread_local :seen
|
8
8
|
|
9
|
-
|
9
|
+
# The bfs method performs a breadth-first search on the object's structure,
|
10
|
+
# visiting all elements and yielding their indices and values to the block.
|
11
|
+
#
|
12
|
+
# @param visit_interal [ true, false ] whether to visit internal hashes or arrays
|
13
|
+
# @yield [ index, value ] yields each element's index and value to the block
|
14
|
+
#
|
15
|
+
# @raise [ ArgumentError ] if no &block argument was provided
|
16
|
+
#
|
17
|
+
# @example bfs { |index, value| … } # performs a breadth-first search on the object's structure
|
18
|
+
#
|
19
|
+
# @return [ self ] returns the receiver
|
20
|
+
def bfs(visit_interal: false, &block)
|
10
21
|
block or raise ArgumentError, 'require &block argument'
|
11
22
|
self.seen = {}
|
12
|
-
queue
|
23
|
+
queue = []
|
13
24
|
queue.push([ nil, self ])
|
14
25
|
while (index, object = queue.shift)
|
15
26
|
case
|
@@ -20,13 +31,13 @@ module Tins
|
|
20
31
|
object.each do |k, v|
|
21
32
|
queue.push([ k, convert_to_hash_or_ary(v) ])
|
22
33
|
end
|
23
|
-
|
34
|
+
visit_interal or next
|
24
35
|
when Array === object
|
25
36
|
seen[object.__id__] = true
|
26
37
|
object.each_with_index do |v, i|
|
27
38
|
queue.push([ i, convert_to_hash_or_ary(v) ])
|
28
39
|
end
|
29
|
-
|
40
|
+
visit_interal or next
|
30
41
|
end
|
31
42
|
block.(index, object)
|
32
43
|
end
|
@@ -35,14 +46,19 @@ module Tins
|
|
35
46
|
self.seen = nil
|
36
47
|
end
|
37
48
|
|
38
|
-
|
49
|
+
# Converts the given object into a hash or array if possible
|
50
|
+
#
|
51
|
+
# @param object [Object] The object to convert
|
52
|
+
#
|
53
|
+
# @return [Hash, Array, Object] The converted object or itself if not convertible
|
54
|
+
def convert_to_hash_or_ary(object)
|
39
55
|
case
|
40
|
-
when
|
41
|
-
|
42
|
-
when
|
43
|
-
|
56
|
+
when object.respond_to?(:to_hash)
|
57
|
+
object.to_hash
|
58
|
+
when object.respond_to?(:to_ary)
|
59
|
+
object.to_ary
|
44
60
|
else
|
45
|
-
|
61
|
+
object
|
46
62
|
end
|
47
63
|
end
|
48
64
|
end
|
data/lib/tins/version.rb
CHANGED
data/tests/hash_bfs_test.rb
CHANGED
@@ -15,7 +15,7 @@ module Tins
|
|
15
15
|
|
16
16
|
def test_with_nodes
|
17
17
|
results = []
|
18
|
-
@hash.bfs(
|
18
|
+
@hash.bfs(visit_interal: true) { |*a| results.push(a) }
|
19
19
|
assert_equal(
|
20
20
|
[[nil, {a:"foo", b:[{c:"baz"}, {d:"quux"}, ["blub"]]}], [:a, "foo"],
|
21
21
|
[:b, [{c:"baz"}, {d:"quux"}, ["blub"]]], [0, {c:"baz"}], [1, {d:"quux"}],
|
@@ -27,7 +27,7 @@ module Tins
|
|
27
27
|
def test_with_nodes_with_circle
|
28
28
|
results = []
|
29
29
|
@hash[:b].last << @hash
|
30
|
-
@hash.bfs(
|
30
|
+
@hash.bfs(visit_interal: true) { |*a| results.push(a) }
|
31
31
|
assert_equal 9, results.size
|
32
32
|
end
|
33
33
|
end
|
data/tins.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: tins 1.
|
2
|
+
# stub: tins 1.36.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "tins".freeze
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.36.0".freeze
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2024-10-
|
11
|
+
s.date = "2024-10-11"
|
12
12
|
s.description = "All the stuff that isn't good/big enough for a real library.".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.extra_rdoc_files = ["README.md".freeze, "lib/dslkit.rb".freeze, "lib/dslkit/polite.rb".freeze, "lib/dslkit/rude.rb".freeze, "lib/spruz.rb".freeze, "lib/tins.rb".freeze, "lib/tins/alias.rb".freeze, "lib/tins/annotate.rb".freeze, "lib/tins/ask_and_send.rb".freeze, "lib/tins/attempt.rb".freeze, "lib/tins/bijection.rb".freeze, "lib/tins/case_predicate.rb".freeze, "lib/tins/complete.rb".freeze, "lib/tins/concern.rb".freeze, "lib/tins/count_by.rb".freeze, "lib/tins/date_dummy.rb".freeze, "lib/tins/date_time_dummy.rb".freeze, "lib/tins/deep_const_get.rb".freeze, "lib/tins/deep_dup.rb".freeze, "lib/tins/deprecate.rb".freeze, "lib/tins/dslkit.rb".freeze, "lib/tins/duration.rb".freeze, "lib/tins/expose.rb".freeze, "lib/tins/extract_last_argument_options.rb".freeze, "lib/tins/file_binary.rb".freeze, "lib/tins/find.rb".freeze, "lib/tins/generator.rb".freeze, "lib/tins/go.rb".freeze, "lib/tins/hash_bfs.rb".freeze, "lib/tins/hash_symbolize_keys_recursive.rb".freeze, "lib/tins/hash_union.rb".freeze, "lib/tins/if_predicate.rb".freeze, "lib/tins/implement.rb".freeze, "lib/tins/limited.rb".freeze, "lib/tins/lines_file.rb".freeze, "lib/tins/lru_cache.rb".freeze, "lib/tins/memoize.rb".freeze, "lib/tins/method_description.rb".freeze, "lib/tins/minimize.rb".freeze, "lib/tins/module_group.rb".freeze, "lib/tins/named_set.rb".freeze, "lib/tins/null.rb".freeze, "lib/tins/once.rb".freeze, "lib/tins/p.rb".freeze, "lib/tins/partial_application.rb".freeze, "lib/tins/proc_compose.rb".freeze, "lib/tins/proc_prelude.rb".freeze, "lib/tins/range_plus.rb".freeze, "lib/tins/require_maybe.rb".freeze, "lib/tins/responding.rb".freeze, "lib/tins/secure_write.rb".freeze, "lib/tins/sexy_singleton.rb".freeze, "lib/tins/string_byte_order_mark.rb".freeze, "lib/tins/string_camelize.rb".freeze, "lib/tins/string_underscore.rb".freeze, "lib/tins/string_version.rb".freeze, "lib/tins/subhash.rb".freeze, "lib/tins/temp_io.rb".freeze, "lib/tins/temp_io_enum.rb".freeze, "lib/tins/terminal.rb".freeze, "lib/tins/thread_local.rb".freeze, "lib/tins/time_dummy.rb".freeze, "lib/tins/timed_cache.rb".freeze, "lib/tins/to.rb".freeze, "lib/tins/to_proc.rb".freeze, "lib/tins/token.rb".freeze, "lib/tins/uniq_by.rb".freeze, "lib/tins/unit.rb".freeze, "lib/tins/version.rb".freeze, "lib/tins/write.rb".freeze, "lib/tins/xt.rb".freeze, "lib/tins/xt/annotate.rb".freeze, "lib/tins/xt/ask_and_send.rb".freeze, "lib/tins/xt/attempt.rb".freeze, "lib/tins/xt/blank.rb".freeze, "lib/tins/xt/case_predicate.rb".freeze, "lib/tins/xt/complete.rb".freeze, "lib/tins/xt/concern.rb".freeze, "lib/tins/xt/count_by.rb".freeze, "lib/tins/xt/date_dummy.rb".freeze, "lib/tins/xt/date_time_dummy.rb".freeze, "lib/tins/xt/deep_const_get.rb".freeze, "lib/tins/xt/deep_dup.rb".freeze, "lib/tins/xt/deprecate.rb".freeze, "lib/tins/xt/dslkit.rb".freeze, "lib/tins/xt/expose.rb".freeze, "lib/tins/xt/extract_last_argument_options.rb".freeze, "lib/tins/xt/file_binary.rb".freeze, "lib/tins/xt/full.rb".freeze, "lib/tins/xt/hash_bfs.rb".freeze, "lib/tins/xt/hash_symbolize_keys_recursive.rb".freeze, "lib/tins/xt/hash_union.rb".freeze, "lib/tins/xt/if_predicate.rb".freeze, "lib/tins/xt/implement.rb".freeze, "lib/tins/xt/irb.rb".freeze, "lib/tins/xt/method_description.rb".freeze, "lib/tins/xt/named.rb".freeze, "lib/tins/xt/null.rb".freeze, "lib/tins/xt/p.rb".freeze, "lib/tins/xt/partial_application.rb".freeze, "lib/tins/xt/proc_compose.rb".freeze, "lib/tins/xt/proc_prelude.rb".freeze, "lib/tins/xt/range_plus.rb".freeze, "lib/tins/xt/require_maybe.rb".freeze, "lib/tins/xt/responding.rb".freeze, "lib/tins/xt/secure_write.rb".freeze, "lib/tins/xt/sexy_singleton.rb".freeze, "lib/tins/xt/string.rb".freeze, "lib/tins/xt/string_byte_order_mark.rb".freeze, "lib/tins/xt/string_camelize.rb".freeze, "lib/tins/xt/string_underscore.rb".freeze, "lib/tins/xt/string_version.rb".freeze, "lib/tins/xt/subhash.rb".freeze, "lib/tins/xt/temp_io.rb".freeze, "lib/tins/xt/time_dummy.rb".freeze, "lib/tins/xt/time_freezer.rb".freeze, "lib/tins/xt/to.rb".freeze, "lib/tins/xt/uniq_by.rb".freeze, "lib/tins/xt/write.rb".freeze]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|