tins 1.35.0 → 1.36.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +17 -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: 74ccd9381ab74305d467c86810271be1033c7f68b777cdb4c561b3b5bfb5152a
|
4
|
+
data.tar.gz: 977fa807b40ee00176d7ecde2c363d871acc8c476988e34b682d3d8b19e7ef20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c689f798c3679f290db513c4203b4c19b92696606e76feee88b27d0959b0d4ec09d9f7aac80c1d502d3e44d205da82715678b5b629ba51f669264a75bb8c77ce
|
7
|
+
data.tar.gz: 5bf30172063f7b6406247b15ff340fd65e2421799fa93c9d52ab69de315ba71b12550ffdabff42d0d6dc801a69c1bcc5679afdcaec090558886890d05edd7bf2
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2024-10-11 v1.36.1
|
4
|
+
|
5
|
+
* Fixed a typo in the code
|
6
|
+
|
7
|
+
## 2024-10-11 v1.36.0
|
8
|
+
|
9
|
+
### Significant Changes
|
10
|
+
|
11
|
+
* Refactor bfs method in `hash_bfs.rb`:
|
12
|
+
+ Rename `include_nodes` variable to `visit_internal`
|
13
|
+
+ Update test cases in `hash_bfs_test.rb` to use new method signature
|
14
|
+
+ Update method signature and docstring to reflect new behavior
|
15
|
+
* Update hash conversion logic:
|
16
|
+
+ Rename method parameter from `v` to `object`
|
17
|
+
+ Use `object` instead of `v` consistently throughout the method
|
18
|
+
+ Add documentation for new method name and behavior
|
19
|
+
|
3
20
|
## 2024-10-10 v1.35.0
|
4
21
|
|
5
22
|
### New Features
|
@@ -23,8 +40,6 @@
|
|
23
40
|
|
24
41
|
## 2024-09-30 v1.34.0
|
25
42
|
|
26
|
-
### Changes in **1.34.0**
|
27
|
-
|
28
43
|
* **Secure write functionality updated**
|
29
44
|
+ Added support for `Pathname` objects in `secure_write`
|
30
45
|
+ 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_internal [ 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_internal: 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_internal 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_internal 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_internal: 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_internal: 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.1 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.1".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.1
|
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
|