tins 1.43.0 → 1.44.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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +21 -0
  3. data/README.md +158 -6
  4. data/Rakefile +19 -16
  5. data/examples/let.rb +8 -40
  6. data/examples/mail.rb +0 -1
  7. data/examples/turing.rb +3 -1
  8. data/lib/tins/alias.rb +1 -0
  9. data/lib/tins/annotate.rb +37 -27
  10. data/lib/tins/ask_and_send.rb +41 -0
  11. data/lib/tins/attempt.rb +39 -0
  12. data/lib/tins/bijection.rb +34 -0
  13. data/lib/tins/case_predicate.rb +21 -0
  14. data/lib/tins/complete.rb +16 -0
  15. data/lib/tins/concern.rb +64 -0
  16. data/lib/tins/date_dummy.rb +36 -4
  17. data/lib/tins/date_time_dummy.rb +34 -2
  18. data/lib/tins/deep_dup.rb +9 -2
  19. data/lib/tins/deprecate.rb +12 -0
  20. data/lib/tins/dslkit.rb +559 -83
  21. data/lib/tins/duration.rb +120 -5
  22. data/lib/tins/expose.rb +54 -5
  23. data/lib/tins/extract_last_argument_options.rb +9 -0
  24. data/lib/tins/file_binary.rb +104 -21
  25. data/lib/tins/find.rb +114 -11
  26. data/lib/tins/generator.rb +10 -2
  27. data/lib/tins/go.rb +81 -4
  28. data/lib/tins/hash_bfs.rb +4 -2
  29. data/lib/tins/hash_symbolize_keys_recursive.rb +62 -4
  30. data/lib/tins/hash_union.rb +47 -2
  31. data/lib/tins/if_predicate.rb +31 -0
  32. data/lib/tins/implement.rb +50 -0
  33. data/lib/tins/limited.rb +54 -5
  34. data/lib/tins/lines_file.rb +81 -2
  35. data/lib/tins/lru_cache.rb +54 -17
  36. data/lib/tins/memoize.rb +86 -58
  37. data/lib/tins/method_description.rb +87 -4
  38. data/lib/tins/minimize.rb +39 -11
  39. data/lib/tins/module_group.rb +27 -2
  40. data/lib/tins/named_set.rb +20 -0
  41. data/lib/tins/null.rb +86 -15
  42. data/lib/tins/once.rb +61 -4
  43. data/lib/tins/p.rb +44 -8
  44. data/lib/tins/partial_application.rb +66 -7
  45. data/lib/tins/proc_compose.rb +58 -1
  46. data/lib/tins/proc_prelude.rb +97 -10
  47. data/lib/tins/range_plus.rb +30 -2
  48. data/lib/tins/require_maybe.rb +36 -0
  49. data/lib/tins/responding.rb +39 -0
  50. data/lib/tins/secure_write.rb +24 -4
  51. data/lib/tins/sexy_singleton.rb +45 -48
  52. data/lib/tins/string_byte_order_mark.rb +33 -2
  53. data/lib/tins/string_camelize.rb +31 -2
  54. data/lib/tins/string_underscore.rb +33 -2
  55. data/lib/tins/string_version.rb +179 -10
  56. data/lib/tins/subhash.rb +35 -10
  57. data/lib/tins/temp_io.rb +7 -0
  58. data/lib/tins/temp_io_enum.rb +19 -0
  59. data/lib/tins/terminal.rb +31 -9
  60. data/lib/tins/thread_local.rb +67 -5
  61. data/lib/tins/time_dummy.rb +46 -21
  62. data/lib/tins/to.rb +15 -0
  63. data/lib/tins/to_proc.rb +17 -4
  64. data/lib/tins/token.rb +56 -1
  65. data/lib/tins/unit.rb +288 -149
  66. data/lib/tins/version.rb +1 -1
  67. data/lib/tins/write.rb +14 -3
  68. data/lib/tins/xt/blank.rb +81 -2
  69. data/lib/tins/xt/concern.rb +51 -0
  70. data/lib/tins/xt/full.rb +56 -11
  71. data/lib/tins/xt/irb.rb +46 -2
  72. data/lib/tins/xt/method_description.rb +0 -12
  73. data/lib/tins/xt/minimize.rb +7 -0
  74. data/lib/tins/xt/named.rb +71 -16
  75. data/lib/tins/xt/proc_compose.rb +4 -0
  76. data/lib/tins/xt/subhash.rb +11 -0
  77. data/lib/tins/xt/time_freezer.rb +43 -6
  78. data/lib/tins/xt.rb +1 -3
  79. data/lib/tins.rb +16 -3
  80. data/tests/duration_test.rb +4 -0
  81. data/tests/from_module_test.rb +30 -2
  82. data/tests/implement_test.rb +6 -8
  83. data/tests/lines_file_test.rb +2 -0
  84. data/tests/lru_cache_test.rb +12 -0
  85. data/tests/method_description_test.rb +14 -20
  86. data/tests/partial_application_test.rb +4 -0
  87. data/tests/proc_prelude_test.rb +1 -1
  88. data/tests/scope_test.rb +1 -1
  89. data/tests/string_version_test.rb +2 -0
  90. data/tests/test_helper.rb +5 -2
  91. data/tests/to_test.rb +6 -6
  92. data/tins.gemspec +9 -9
  93. metadata +23 -46
  94. data/.contexts/code_comment.rb +0 -26
  95. data/.contexts/full.rb +0 -31
  96. data/.contexts/lib.rb +0 -26
  97. data/.contexts/yard.md +0 -92
  98. data/.github/workflows/codeql-analysis.yml +0 -72
  99. data/lib/tins/count_by.rb +0 -21
  100. data/lib/tins/deep_const_get.rb +0 -64
  101. data/lib/tins/timed_cache.rb +0 -51
  102. data/lib/tins/uniq_by.rb +0 -23
  103. data/lib/tins/xt/count_by.rb +0 -7
  104. data/lib/tins/xt/deep_const_get.rb +0 -7
  105. data/lib/tins/xt/uniq_by.rb +0 -25
  106. data/tests/count_by_test.rb +0 -17
  107. data/tests/deep_const_get_test.rb +0 -37
  108. data/tests/uniq_by_test.rb +0 -31
  109. /data/{COPYING → LICENSE} +0 -0
@@ -1,72 +0,0 @@
1
- # For most projects, this workflow file will not need changing; you simply need
2
- # to commit it to your repository.
3
- #
4
- # You may wish to alter this file to override the set of languages analyzed,
5
- # or to provide custom queries or build logic.
6
- #
7
- # ******** NOTE ********
8
- # We have attempted to detect the languages in your repository. Please check
9
- # the `language` matrix defined below to confirm you have the correct set of
10
- # supported CodeQL languages.
11
- #
12
- name: "CodeQL"
13
-
14
- on:
15
- push:
16
- branches: [ master ]
17
- pull_request:
18
- # The branches below must be a subset of the branches above
19
- branches: [ master ]
20
- schedule:
21
- - cron: '37 18 * * 5'
22
-
23
- jobs:
24
- analyze:
25
- name: Analyze
26
- runs-on: ubuntu-latest
27
- permissions:
28
- actions: read
29
- contents: read
30
- security-events: write
31
-
32
- strategy:
33
- fail-fast: false
34
- matrix:
35
- language: [ 'ruby' ]
36
- # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
- # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38
-
39
- steps:
40
- - name: Checkout repository
41
- uses: actions/checkout@v3
42
-
43
- # Initializes the CodeQL tools for scanning.
44
- - name: Initialize CodeQL
45
- uses: github/codeql-action/init@v2
46
- with:
47
- languages: ${{ matrix.language }}
48
- # If you wish to specify custom queries, you can do so here or in a config file.
49
- # By default, queries listed here will override any specified in a config file.
50
- # Prefix the list here with "+" to use these queries and those in the config file.
51
-
52
- # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53
- # queries: security-extended,security-and-quality
54
-
55
-
56
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57
- # If this step fails, then you should remove it and run the build manually (see below)
58
- - name: Autobuild
59
- uses: github/codeql-action/autobuild@v2
60
-
61
- # ℹ️ Command-line programs to run using the OS shell.
62
- # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63
-
64
- # If the Autobuild fails above, remove it and uncomment the following three lines.
65
- # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66
-
67
- # - run: |
68
- # echo "Run, Build Application using script"
69
- # ./location_of_script_within_repo/buildscript.sh
70
-
71
- - name: Perform CodeQL Analysis
72
- uses: github/codeql-action/analyze@v2
data/lib/tins/count_by.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'tins/string_version'
2
-
3
- module Tins
4
- module CountBy
5
- if Tins::StringVersion.compare(RUBY_VERSION, :<=, "1.8")
6
- def count_by(&block)
7
- block ||= lambda { |x| true }
8
- inject(0) { |s, e| s += 1 if block.call(e); s }
9
- end
10
- else
11
- require 'tins/deprecate'
12
- extend Tins::Deprecate
13
-
14
- deprecate method:
15
- def count_by(&block)
16
- count(&block)
17
- end,
18
- new_method: :count
19
- end
20
- end
21
- end
@@ -1,64 +0,0 @@
1
- require 'tins/string_version'
2
-
3
- module Tins
4
- module DeepConstGet
5
- class << self
6
- if ::Object.method(:const_defined?).arity == 1
7
- # :nocov:
8
- # We do not create coverage on 1.8
9
- def const_defined_in?(modul, constant)
10
- modul.const_defined?(constant)
11
- end
12
- # :nocov:
13
- else
14
- require 'tins/deprecate'
15
- extend Tins::Deprecate
16
-
17
- deprecate method:
18
- def const_defined_in?(modul, constant)
19
- modul.const_defined?(constant, false)
20
- end,
21
- new_method: :const_defined?
22
- end
23
-
24
- if Tins::StringVersion.compare(RUBY_VERSION, :<, '2.0')
25
- def deep_const_get(path, start_module = Object)
26
- path.to_s.split('::').inject(start_module) do |p, c|
27
- case
28
- when c.empty?
29
- if start_module == Object
30
- Object
31
- else
32
- raise ArgumentError, "top level constants cannot be reached from"\
33
- " start module #{start_module.inspect}"
34
- end
35
- when const_defined_in?(p, c)
36
- p.const_get(c)
37
- else
38
- begin
39
- p.const_missing(c)
40
- rescue NameError => e
41
- raise ArgumentError, "can't get const #{path}: #{e}"
42
- end
43
- end
44
- end
45
- end
46
- else
47
- require 'tins/deprecate'
48
- extend Tins::Deprecate
49
-
50
- deprecate method:
51
- def deep_const_get(path, start_module = Object)
52
- start_module.const_get(path)
53
- rescue NameError => e
54
- raise ArgumentError, "can't get const #{path}: #{e}"
55
- end,
56
- new_method: :const_get
57
- end
58
- end
59
-
60
- def deep_const_get(path, start_module = Object)
61
- ::Tins::DeepConstGet.deep_const_get(path, start_module)
62
- end
63
- end
64
- end
@@ -1,51 +0,0 @@
1
- class TimedCache
2
- class Value < Struct.new(:value, :timestamp)
3
- def self.json_create(hash)
4
- new(*hash.values_at('value', 'timestamp'))
5
- end
6
-
7
- def as_json(*)
8
- super | { JSON.create_id => self.class.name }
9
- end
10
- end
11
-
12
- def initialize(name, ttl: 60, jitter: 1..5, &block)
13
- @name = name
14
- @ttl = ttl
15
- @jitter = jitter
16
- block or raise ArgumentError, 'block is required'
17
- @block = block
18
- @redis = Redis.new
19
- end
20
-
21
- def namespaced(key)
22
- "timed_cache:#{key}"
23
- end
24
-
25
- def value
26
- now = Time.now
27
- if stored = stored_value
28
- if (now - @ttl).to_i >= stored.timestamp
29
- Thread.new {
30
- sleep @jitter
31
- if stored_value.timestamp <= stored.timestamp
32
- @redis.set namespaced(@name), new_value(now).to_json
33
- end
34
- }
35
- end
36
- stored.value
37
- else
38
- nv = new_value(now)
39
- @redis.set namespaced(@name), nv.to_json
40
- nv.value
41
- end
42
- end
43
-
44
- def new_value(now)
45
- Value.new(@block.(), now.to_i)
46
- end
47
-
48
- def stored_value
49
- @redis.get(namespaced(@name)).full? { |s| ::JSON.parse(s, create_additions: true) rescue nil }
50
- end
51
- end
data/lib/tins/uniq_by.rb DELETED
@@ -1,23 +0,0 @@
1
- require 'tins/string_version'
2
-
3
- module Tins
4
- module UniqBy
5
- if Tins::StringVersion.compare(RUBY_VERSION, :<=, "1.8")
6
- def uniq_by(&block)
7
- block ||= lambda { |x| x }
8
- inject({}) { |h, e| h[ block.call(e) ] ||= e; h }.values
9
- end
10
- else
11
- require 'tins/deprecate'
12
- extend Tins::Deprecate
13
-
14
- deprecate method:
15
- def uniq_by(&block)
16
- uniq(&block)
17
- end,
18
- new_method: :uniq
19
- end
20
- end
21
- end
22
-
23
- require 'tins/alias'
@@ -1,7 +0,0 @@
1
- require 'tins/count_by'
2
-
3
- module Tins
4
- module ::Enumerable
5
- include CountBy
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- require 'tins/deep_const_get'
2
-
3
- module Tins
4
- class ::Object
5
- include DeepConstGet
6
- end
7
- end
@@ -1,25 +0,0 @@
1
- require 'tins/string_version'
2
- require 'tins/uniq_by'
3
-
4
- module Tins
5
- module ::Enumerable
6
- include UniqBy
7
- end
8
-
9
- class ::Array
10
- if Tins::StringVersion.compare(RUBY_VERSION, :<=, "1.8")
11
- include UniqBy
12
-
13
- def uniq_by!(&b)
14
- replace uniq_by(&b)
15
- end
16
- else
17
- require 'tins/deprecate'
18
- extend Tins::Deprecate
19
-
20
- deprecate method:
21
- alias_method(:uniq_by!, :uniq!),
22
- new_method: :uniq!
23
- end
24
- end
25
- end
@@ -1,17 +0,0 @@
1
- require 'test_helper'
2
- require 'tins/xt'
3
-
4
- module Tins
5
- class CountByTest < Test::Unit::TestCase
6
-
7
- def test_count_by
8
- assert_equal 0, [].count_by { |x| x % 2 == 0 }
9
- assert_equal 0, [ 1 ].count_by { |x| x % 2 == 0 }
10
- assert_equal 1, [ 1 ].count_by { |x| x % 2 == 1 }
11
- assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 0 }
12
- assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 1 }
13
- assert_equal 2, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 0 }
14
- assert_equal 3, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 1 }
15
- end
16
- end
17
- end
@@ -1,37 +0,0 @@
1
- require 'test_helper'
2
- require 'tins/xt/deep_const_get'
3
-
4
- module Tins
5
- class DeepConstGetTest < Test::Unit::TestCase
6
- module A
7
- module B
8
- end
9
- end
10
-
11
- module C
12
- module NotB
13
- end
14
-
15
- def self.const_missing(c)
16
- NotB
17
- end
18
- end
19
-
20
- def test_deep_const_get_with_start_module
21
- assert_raise(ArgumentError) { deep_const_get '::B', A }
22
- assert_equal A::B, deep_const_get('B', A)
23
- end
24
-
25
- def test_deep_const_get_without_start_module
26
- assert_equal Tins::DeepConstGetTest::A::B, deep_const_get('::Tins::DeepConstGetTest::A::B')
27
- assert_equal Tins::DeepConstGetTest::A::B, deep_const_get('Tins::DeepConstGetTest::A::B')
28
- assert_equal Array, deep_const_get('::Array')
29
- assert_equal Array, deep_const_get('Array')
30
- end
31
-
32
- def test_deep_const_get_with_const_missing
33
- assert_raise(ArgumentError) { deep_const_get '::Tins::DeepConstGetTest::A::NIXDA' }
34
- assert_equal Tins::DeepConstGetTest::C::NotB, deep_const_get('::Tins::DeepConstGetTest::C::B')
35
- end
36
- end
37
- end
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
- require 'tins/xt'
3
-
4
- module Tins
5
- class UniqByTest < Test::Unit::TestCase
6
-
7
- unless defined?(Point)
8
- class Point < Struct.new :x, :y
9
- end
10
- end
11
-
12
- def test_uniq_by
13
- assert_equal [ 1, 2, 3 ], [ 1, 2, 2, 3 ].uniq_by.sort
14
- a = [ 1, 2, 2, 3 ]; a.uniq_by!
15
- assert_equal [ 1, 2, 3 ], a.sort
16
- p1 = Point.new 1, 2
17
- p2 = Point.new 2, 2
18
- p3 = Point.new 2, 2
19
- p4 = Point.new 3, 3
20
- a = [ p1, p2, p3, p4 ]
21
- a_uniq = a.uniq_by { |p| p.y }
22
- assert_equal 2, a_uniq.size
23
- assert a_uniq.include?(p4)
24
- assert [ p1, p2, p3 ].any? { |p| a_uniq.include? p }
25
- a.uniq_by! { |p| p.y }
26
- assert_equal 2, a.size
27
- assert a.include?(p4)
28
- assert [ p1, p2, p3 ].any? { |p| a.include? p }
29
- end
30
- end
31
- end
File without changes