tins 1.36.0 → 1.37.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3d0d3b142299555332881bdd390e8cb2fc4137cbbb92864e96c835790d1f943
4
- data.tar.gz: c287721ce6b44fb9a1cc4faed1eee2d6f0df250a92c389e811bc033b9c24a48a
3
+ metadata.gz: '049e3bf81de447eec53664f5555656602906bbd44a5f98b2e0e953318aadff77'
4
+ data.tar.gz: 14debef966e248366ec1ef72b39b8ccc094a91049ed6cd44e9ee2550c607ae02
5
5
  SHA512:
6
- metadata.gz: 6a950643986122ff5e47e419657dbe5f76ffe1d1c80927ab9767297672a5296d08b84479b0ae03fcf7d5112c5297cdc3d8993425488c203321615dad441d7c6d
7
- data.tar.gz: abec6e88bb19153688f7e5c8069c3ac13fcff850aa9860f4924b360bdb53608d82deabbb8d0d35a234ff84e8149869861fe94b8963ba1187e7ae252d1bafe7af
6
+ metadata.gz: c93d9b5b23c3305f422f0efd81e0828591682331532b51f4de1a84e305f77bb3f9374abcf8b725cd665a74ef352cabb525f49b4dfa68fc78f5568e87a5e78012
7
+ data.tar.gz: 4b8d5d1da5bffb1b26449f96aa0f292a28582e5409d734ba5cdc18c428a2e6b57f577662773b776abcbb5464d505ae6726b60bba54f2142ddf5a32faae5fd9e9
data/CHANGES.md CHANGED
@@ -1,11 +1,29 @@
1
1
  # Changes
2
2
 
3
+ ## 2024-10-19 v1.37.0
4
+
5
+ * Add support for module prepended blocks in **Tins::Concern**:
6
+ * Added `prepend_features` method to Tins concern
7
+ * Updated ConcernTest to test prepend feature
8
+ * Raise StandardError for duplicate block definitions for included and
9
+ prepended blocks
10
+ * Added `class_methods` method to Tins concern:
11
+ * Added `class_methods` method to lib/tins/concern.rb
12
+ - Creates or retrieves ClassMethods module for defining class-level methods
13
+ * Updated tests in `tests/concern_test.rb`
14
+ - Added test for new `baz1` and `baz2` methods
15
+ + Tested availability of `bar`, `baz1`, and `baz2` methods on A
16
+
17
+ ## 2024-10-11 v1.36.1
18
+
19
+ * Fixed a typo in the code
20
+
3
21
  ## 2024-10-11 v1.36.0
4
22
 
5
23
  ### Significant Changes
6
24
 
7
25
  * Refactor bfs method in `hash_bfs.rb`:
8
- + Rename `include_nodes` variable to `visit_interal`
26
+ + Rename `include_nodes` variable to `visit_internal`
9
27
  + Update test cases in `hash_bfs_test.rb` to use new method signature
10
28
  + Update method signature and docstring to reflect new behavior
11
29
  * Update hash conversion logic:
data/lib/tins/concern.rb CHANGED
@@ -19,12 +19,48 @@ module Tins
19
19
  end
20
20
  end
21
21
 
22
+ def prepend_features(base)
23
+ if base.instance_variable_defined?("@_dependencies")
24
+ base.instance_variable_get("@_dependencies") << self
25
+ false
26
+ else
27
+ return false if base < self
28
+ @_dependencies.each { |dep| base.send(:include, dep) }
29
+ super
30
+ base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
31
+ base.class_eval(&@_prepended_block) if instance_variable_defined?("@_prepended_block")
32
+ Thread.current[:tin_concern_args] = nil
33
+ true
34
+ end
35
+ end
36
+
22
37
  def included(base = nil, &block)
23
38
  if base.nil?
39
+ instance_variable_defined?(:@_included_block) and
40
+ raise StandardError, "included block already defined"
24
41
  @_included_block = block
25
42
  else
26
43
  super
27
44
  end
28
45
  end
46
+
47
+ def prepended(base = nil, &block)
48
+ if base.nil?
49
+ instance_variable_defined?(:@_prepended_block) and
50
+ raise StandardError, "prepended block already defined"
51
+ @_prepended_block = block
52
+ else
53
+ super
54
+ end
55
+ end
56
+
57
+ def class_methods(&block)
58
+ modul = const_get(:ClassMethods) if const_defined?(:ClassMethods, false)
59
+ unless modul
60
+ modul = Module.new
61
+ const_set(:ClassMethods, modul)
62
+ end
63
+ modul.module_eval(&block)
64
+ end
29
65
  end
30
66
  end
data/lib/tins/hash_bfs.rb CHANGED
@@ -9,7 +9,7 @@ module Tins
9
9
  # The bfs method performs a breadth-first search on the object's structure,
10
10
  # visiting all elements and yielding their indices and values to the block.
11
11
  #
12
- # @param visit_interal [ true, false ] whether to visit internal hashes or arrays
12
+ # @param visit_internal [ true, false ] whether to visit internal hashes or arrays
13
13
  # @yield [ index, value ] yields each element's index and value to the block
14
14
  #
15
15
  # @raise [ ArgumentError ] if no &block argument was provided
@@ -17,7 +17,7 @@ module Tins
17
17
  # @example bfs { |index, value| … } # performs a breadth-first search on the object's structure
18
18
  #
19
19
  # @return [ self ] returns the receiver
20
- def bfs(visit_interal: false, &block)
20
+ def bfs(visit_internal: false, &block)
21
21
  block or raise ArgumentError, 'require &block argument'
22
22
  self.seen = {}
23
23
  queue = []
@@ -31,13 +31,13 @@ module Tins
31
31
  object.each do |k, v|
32
32
  queue.push([ k, convert_to_hash_or_ary(v) ])
33
33
  end
34
- visit_interal or next
34
+ visit_internal or next
35
35
  when Array === object
36
36
  seen[object.__id__] = true
37
37
  object.each_with_index do |v, i|
38
38
  queue.push([ i, convert_to_hash_or_ary(v) ])
39
39
  end
40
- visit_interal or next
40
+ visit_internal or next
41
41
  end
42
42
  block.(index, object)
43
43
  end
data/lib/tins/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Tins
2
2
  # Tins version
3
- VERSION = '1.36.0'
3
+ VERSION = '1.37.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -8,27 +8,65 @@ class ConcernTest < Test::Unit::TestCase
8
8
  $included = self
9
9
  end
10
10
 
11
+ prepended do
12
+ $prepended = self
13
+ end
14
+
11
15
  def foo
12
16
  :foo
13
17
  end
14
18
 
19
+ class_methods do
20
+ def baz1
21
+ :baz1
22
+ end
23
+ end
24
+
15
25
  module ClassMethods
16
26
  def bar
17
27
  :bar
18
28
  end
19
29
  end
30
+
31
+ class_methods do
32
+ def baz2
33
+ :baz2
34
+ end
35
+ end
20
36
  end
21
37
 
22
38
  $included = nil
39
+ $prepended = nil
23
40
 
24
41
  class A
25
42
  include AC
26
43
  end
27
44
 
28
- def test_concern
45
+ class B
46
+ prepend AC
47
+ end
48
+
49
+ def test_concern_include
29
50
  a = A.new
30
51
  assert_equal A, $included
31
52
  assert_equal :foo, a.foo
32
53
  assert_equal :bar, A.bar
54
+ assert_equal :baz1, A.baz1
55
+ assert_equal :baz2, A.baz2
56
+ assert_raise(StandardError) do
57
+ AC.module_eval { included {} }
58
+ end
59
+ end
60
+
61
+ def test_concern_prepend
62
+ a = B.new
63
+ assert_equal B, $prepended
64
+ assert_equal :foo, a.foo
65
+ assert_equal :bar, B.bar
66
+ assert_equal :baz1, B.baz1
67
+ assert_equal :baz2, B.baz2
68
+ assert_raise(StandardError) do
69
+ AC.module_eval { prepended {} }
70
+ end
33
71
  end
34
72
  end
@@ -15,7 +15,7 @@ module Tins
15
15
 
16
16
  def test_with_nodes
17
17
  results = []
18
- @hash.bfs(visit_interal: true) { |*a| results.push(a) }
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(visit_interal: true) { |*a| results.push(a) }
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.36.0 ruby lib
2
+ # stub: tins 1.37.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "tins".freeze
6
- s.version = "1.36.0".freeze
6
+ s.version = "1.37.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"
11
+ s.date = "2024-10-19"
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]
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.specification_version = 4
25
25
 
26
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.18.0".freeze])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.19".freeze])
27
27
  s.add_development_dependency(%q<all_images>.freeze, [">= 0".freeze])
28
28
  s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
29
29
  s.add_development_dependency(%q<term-ansicolor>.freeze, [">= 0".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.36.0
4
+ version: 1.37.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 00:00:00.000000000 Z
11
+ date: 2024-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.18.0
19
+ version: '1.19'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.18.0
26
+ version: '1.19'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: all_images
29
29
  requirement: !ruby/object:Gem::Requirement