persistent-dmnd 1.0.4 → 2.0.3

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.
@@ -1,7 +1,8 @@
1
1
  # encoding: UTF-8
2
+ # typed: false
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
- # Copyright (c) 2017-2018 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ # Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
5
6
  #
6
7
  # This file is part of Persistent-💎, and parts were inspired by Ruby's set.rb
7
8
  # https://github.com/ruby/ruby/blob/v2_6_0_preview2/lib/set.rb
@@ -11,7 +12,7 @@
11
12
 
12
13
  # frozen_string_literal: true
13
14
 
14
- require 'set'
15
+ require "set"
15
16
 
16
17
  module Persistent💎
17
18
  # Workaround for https://github.com/jruby/jruby/issues/5227
@@ -42,7 +43,7 @@ module Persistent💎
42
43
  end
43
44
  end
44
45
 
45
- if RUBY_PLATFORM == 'java' && JRUBY_VERSION.start_with?('9.2.') && workaround_needed?
46
+ if RUBY_PLATFORM == "java" && (JRUBY_VERSION.start_with?("9.2.") || JRUBY_VERSION.start_with?("9.3.")) && workaround_needed?
46
47
  class ::Set
47
48
  # Save existing Set methods
48
49
 
@@ -107,13 +108,11 @@ module Persistent💎
107
108
  persistent_dmnd_workaround_original_disjoint?(set)
108
109
  rescue ArgumentError => e
109
110
  raise unless e.message == "value must be a set" && set.is_a?(::Set)
110
- !(
111
- if size < set.size
112
- any? { |o| set.include?(o) }
113
- else
114
- set.any? { |o| include?(o) }
115
- end
116
- )
111
+ !(if size < set.size
112
+ any? { |o| set.include?(o) }
113
+ else
114
+ set.any? { |o| include?(o) }
115
+ end)
117
116
  end
118
117
 
119
118
  def flatten_merge(set, seen = ::Set.new)
@@ -1,13 +1,14 @@
1
1
  # encoding: UTF-8
2
+ # typed: false
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
- # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ # Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
5
6
  #
6
7
  # This file is part of Persistent-💎.
7
8
  #
8
9
  # MIT License
9
10
  #
10
- # Copyright (c) 2017 Ivo Anjo
11
+ # Copyright (c) 2017-2021 Ivo Anjo
11
12
  #
12
13
  # Permission is hereby granted, free of charge, to any person obtaining a copy
13
14
  # of this software and associated documentation files (the "Software"), to deal
@@ -31,11 +32,11 @@
31
32
 
32
33
  module Persistent💎
33
34
  module JRubyWorkaround
34
- if RUBY_PLATFORM == 'java' && JRUBY_VERSION < "9.2.0.0" # Only supposed to do something on legacy JRuby versions
35
+ if RUBY_PLATFORM == "java" && JRUBY_VERSION < "9.2.0.0" # Only supposed to do something on legacy JRuby versions
35
36
  BROKEN_ENCODING = "\x00"
36
37
  private_constant :BROKEN_ENCODING
37
38
 
38
- BROKEN_ENCODING_JRUBY_1_7 = [239, 146, 142].pack('c*').force_encoding('UTF-8')
39
+ BROKEN_ENCODING_JRUBY_1_7 = [239, 146, 142].pack("c*").force_encoding("UTF-8")
39
40
  private_constant :BROKEN_ENCODING_JRUBY_1_7
40
41
 
41
42
  def self.included(klass)
@@ -80,25 +81,25 @@ module Persistent💎
80
81
  def maybe_fix_broken_encoding(name, target = nil)
81
82
  name_string = name.to_s
82
83
 
83
- if JRUBY_VERSION.start_with?('1.7.')
84
+ if JRUBY_VERSION.start_with?("1.7.")
84
85
  unless name_string.match(/\?.+/) ||
85
- ['a?', 'h?', 's?', 'each?'].include?(name_string) ||
86
- ['_?', '_a?', '_h?', '_s?'].any? { |suffix| name_string.end_with?(suffix) }
86
+ ["a?", "h?", "s?", "each?"].include?(name_string) ||
87
+ ["_?", "_a?", "_h?", "_s?"].any? { |suffix| name_string.end_with?(suffix) }
87
88
  return
88
89
  end
89
90
  else
90
91
  return unless name_string.end_with?(BROKEN_ENCODING)
91
92
  end
92
93
 
93
- fixed_name = name_string.sub('?', '💎').delete(BROKEN_ENCODING).to_sym
94
- fixed_name_jruby_1_7 = name_string.sub('?', BROKEN_ENCODING_JRUBY_1_7).to_sym
94
+ fixed_name = name_string.sub("?", "💎").delete(BROKEN_ENCODING).to_sym
95
+ fixed_name_jruby_1_7 = name_string.sub("?", BROKEN_ENCODING_JRUBY_1_7).to_sym
95
96
 
96
97
  if target
97
98
  target.instance_eval { alias_method(fixed_name, name) }
98
- target.instance_eval { alias_method(fixed_name_jruby_1_7, name) } if JRUBY_VERSION.start_with?('1.7.')
99
+ target.instance_eval { alias_method(fixed_name_jruby_1_7, name) } if JRUBY_VERSION.start_with?("1.7.")
99
100
  else
100
101
  alias_method(fixed_name, name)
101
- alias_method(fixed_name_jruby_1_7, name) if JRUBY_VERSION.start_with?('1.7.')
102
+ alias_method(fixed_name_jruby_1_7, name) if JRUBY_VERSION.start_with?("1.7.")
102
103
  end
103
104
  end
104
105
  end
@@ -1,13 +1,14 @@
1
1
  # encoding: UTF-8
2
+ # typed: true
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
- # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ # Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
5
6
  #
6
7
  # This file is part of Persistent-💎.
7
8
  #
8
9
  # MIT License
9
10
  #
10
- # Copyright (c) 2017 Ivo Anjo
11
+ # Copyright (c) 2017-2021 Ivo Anjo
11
12
  #
12
13
  # Permission is hereby granted, free of charge, to any person obtaining a copy
13
14
  # of this software and associated documentation files (the "Software"), to deal
@@ -32,7 +33,7 @@
32
33
  module Persistent💎
33
34
  module Ruby19And20Support
34
35
  # Enumerable#to_h was only introduced in Ruby 2.1 so we have to do it by hand on 2.0/1.9
35
- if RUBY_VERSION.start_with?('2.0.') || RUBY_VERSION.start_with?('1.9.')
36
+ if RUBY_VERSION.start_with?("2.0.") || RUBY_VERSION.start_with?("1.9.")
36
37
  def self.enumerable_to_h(enumerable)
37
38
  enumerable.each_with_object({}) do |(key, value), result|
38
39
  result[key] = value
@@ -1,13 +1,14 @@
1
1
  # encoding: UTF-8
2
+ # typed: true
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
- # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ # Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
5
6
  #
6
7
  # This file is part of Persistent-💎.
7
8
  #
8
9
  # MIT License
9
10
  #
10
- # Copyright (c) 2017 Ivo Anjo
11
+ # Copyright (c) 2017-2021 Ivo Anjo
11
12
  #
12
13
  # Permission is hereby granted, free of charge, to any person obtaining a copy
13
14
  # of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +30,7 @@
29
30
 
30
31
  # frozen_string_literal: true
31
32
 
32
- require 'persistent_dmnd/jruby_workaround'
33
+ require "persistent_dmnd/jruby_workaround"
33
34
 
34
35
  module Persistent💎
35
36
  # Implements trivial conversion to persistent data structures for our own classes
@@ -1,13 +1,14 @@
1
1
  # encoding: UTF-8
2
+ # typed: true
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
- # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ # Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
5
6
  #
6
7
  # This file is part of Persistent-💎.
7
8
  #
8
9
  # MIT License
9
10
  #
10
- # Copyright (c) 2017 Ivo Anjo
11
+ # Copyright (c) 2017-2021 Ivo Anjo
11
12
  #
12
13
  # Permission is hereby granted, free of charge, to any person obtaining a copy
13
14
  # of this software and associated documentation files (the "Software"), to deal
@@ -29,14 +30,14 @@
29
30
 
30
31
  # frozen_string_literal: true
31
32
 
32
- require 'persistent_dmnd/self_conversion'
33
- require 'persistent_dmnd/is_persistent'
34
- require 'persistent_dmnd/concurrent_ruby_support'
35
- require 'persistent_dmnd/jruby_workaround'
36
- require 'persistent_dmnd/jruby_9_2_set_workaround'
33
+ require "persistent_dmnd/self_conversion"
34
+ require "persistent_dmnd/is_persistent"
35
+ require "persistent_dmnd/concurrent_ruby_support"
36
+ require "persistent_dmnd/jruby_workaround"
37
+ require "persistent_dmnd/jruby_9_2_set_workaround"
37
38
 
38
- require 'hamster'
39
- require 'set'
39
+ require "hamster"
40
+ require "set"
40
41
 
41
42
  module Persistent💎
42
43
  class Set < Hamster::Set
@@ -64,9 +65,17 @@ module Persistent💎
64
65
  ::Set.new(self)
65
66
  end
66
67
 
67
- # Default behavior from Kernel#<=>
68
+ # Note: Behavior changed from Ruby < 3 (returned 0/nil) to match Ruby 3.0 Set#<=> (returns 0/nil/-1/+1);
69
+ # see also https://rubyreferences.github.io/rubychanges/3.0.html#standard-library for details
68
70
  def <=>(other)
69
- self == other ? 0 : nil
71
+ case size <=> other.size
72
+ when (-1)
73
+ (-1) if self < other
74
+ when (+1)
75
+ (+1) if self > other
76
+ else
77
+ 0 if self == other
78
+ end
70
79
  end
71
80
 
72
81
  def to_a💎
@@ -1,13 +1,14 @@
1
1
  # encoding: UTF-8
2
+ # typed: strong
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
- # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ # Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
5
6
  #
6
7
  # This file is part of Persistent-💎.
7
8
  #
8
9
  # MIT License
9
10
  #
10
- # Copyright (c) 2017 Ivo Anjo
11
+ # Copyright (c) 2017-2021 Ivo Anjo
11
12
  #
12
13
  # Permission is hereby granted, free of charge, to any person obtaining a copy
13
14
  # of this software and associated documentation files (the "Software"), to deal
@@ -30,5 +31,5 @@
30
31
  # frozen_string_literal: true
31
32
 
32
33
  module Persistent💎
33
- VERSION = '1.0.4'
34
+ VERSION = "2.0.3"
34
35
  end
@@ -1,13 +1,13 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
- # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
4
+ # Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
5
5
  #
6
6
  # This file is part of Persistent-💎.
7
7
  #
8
8
  # MIT License
9
9
  #
10
- # Copyright (c) 2017 Ivo Anjo
10
+ # Copyright (c) 2017-2021 Ivo Anjo
11
11
  #
12
12
  # Permission is hereby granted, free of charge, to any person obtaining a copy
13
13
  # of this software and associated documentation files (the "Software"), to deal
@@ -29,37 +29,40 @@
29
29
 
30
30
  # frozen_string_literal: true
31
31
 
32
- lib = File.expand_path('../lib', __FILE__)
32
+ lib = File.expand_path("../lib", __FILE__)
33
33
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
34
- require 'persistent_dmnd/version'
34
+ require "persistent_dmnd/version"
35
35
 
36
36
  Gem::Specification.new do |spec|
37
- spec.name = 'persistent-dmnd'
38
- spec.version = Persistent💎::VERSION
39
- spec.authors = 'Ivo Anjo'
40
- spec.email = 'ivo.anjo@ist.utl.pt'
37
+ spec.name = "persistent-dmnd"
38
+ spec.version = Persistent💎::VERSION
39
+ spec.authors = "Ivo Anjo"
40
+ spec.email = "ivo@ivoanjo.me"
41
41
 
42
- spec.summary = 'Persistent-💎: Because Immutable Data Is Forever'
43
- spec.description = 'A tiny ruby gem that gives you a beautiful short-hand syntax for creating immutable arrays, hashes and sets'
44
- spec.homepage = 'https://gitlab.com/ivoanjo/persistent-dmnd/'
45
- spec.license = 'MIT'
42
+ spec.summary = "Persistent-💎: Because Immutable Data Is Forever"
43
+ spec.description = "A tiny ruby gem that gives you a beautiful short-hand syntax for creating immutable arrays, hashes and sets"
44
+ spec.homepage = "https://gitlab.com/ivoanjo/persistent-dmnd/"
45
+ spec.license = "MIT"
46
46
 
47
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
47
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
48
48
  f.match(%r{^(test|spec|features)/})
49
49
  end
50
- spec.require_paths = ['lib']
50
+ spec.require_paths = ["lib"]
51
51
 
52
- spec.required_ruby_version = '>= 1.9.3'
52
+ spec.required_ruby_version = ">= 1.9.3"
53
53
 
54
- spec.add_development_dependency 'bundler', '~> 1.16'
55
- spec.add_development_dependency 'rake', '~> 12.2'
56
- spec.add_development_dependency 'rspec', '~> 3.7'
57
- spec.add_development_dependency 'concurrent-ruby', '~> 1.0' unless RUBY_ENGINE == 'truffleruby'
58
- spec.add_development_dependency 'concurrent-ruby', '~> 1.1' if RUBY_ENGINE == 'truffleruby'
59
- spec.add_development_dependency 'rufo', '~> 0.2'
60
- spec.add_development_dependency 'pry'
61
- spec.add_development_dependency 'pry-byebug' if RUBY_ENGINE == 'ruby' && !RUBY_VERSION.start_with?('1.9.')
62
- spec.add_development_dependency 'pry-debugger-jruby' if RUBY_ENGINE == 'jruby' && !JRUBY_VERSION.start_with?('1.7.')
54
+ spec.add_development_dependency "bundler", "~> 1.16" if RUBY_VERSION < "2.6"
55
+ spec.add_development_dependency "rake", "~> 12.2" # Note: Rake 12.2 is the last that supports Ruby 1.9
56
+ spec.add_development_dependency "rspec", "~> 3.8"
57
+ spec.add_development_dependency "concurrent-ruby", "~> 1.1"
58
+ spec.add_development_dependency "rufo", "~> 0.13" if RUBY_VERSION >= "2.6.0"
59
+ spec.add_development_dependency "pry" if RUBY_VERSION >= "2.0.0"
60
+ spec.add_development_dependency "pry-byebug" if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.4"
61
+ spec.add_development_dependency "pry-debugger-jruby" if RUBY_ENGINE == "jruby" && !JRUBY_VERSION.start_with?("1.7.")
62
+ unless RUBY_ENGINE == "truffleruby"
63
+ spec.add_development_dependency "sorbet"
64
+ spec.add_development_dependency "spoom", "~> 1.1" if RUBY_VERSION >= "2.3.7"
65
+ end
63
66
 
64
- spec.add_dependency 'hamster', '~> 3.0'
67
+ spec.add_dependency "hamster", "~> 3.0"
65
68
  end
data/sorbet/config ADDED
@@ -0,0 +1,2 @@
1
+ --dir
2
+ .