persistent-dmnd 1.0.0 → 2.0.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.
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1 || ">= 0.a"
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../gems.rb", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||= begin
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version || "#{Gem::Requirement.default}.a"
67
+ end
68
+ end
69
+
70
+ def load_bundler!
71
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
72
+
73
+ # must dup string for RG < 1.8 compatibility
74
+ activate_bundler(bundler_version.dup)
75
+ end
76
+
77
+ def activate_bundler(bundler_version)
78
+ if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
+ bundler_version = "< 2"
80
+ end
81
+ gem_error = activation_error_handling do
82
+ gem "bundler", bundler_version
83
+ end
84
+ return if gem_error.nil?
85
+ require_error = activation_error_handling do
86
+ require "bundler/version"
87
+ end
88
+ return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
+ warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
+ exit 42
91
+ end
92
+
93
+ def activation_error_handling
94
+ yield
95
+ nil
96
+ rescue StandardError, LoadError => e
97
+ e
98
+ end
99
+ end
100
+
101
+ m.load_bundler!
102
+
103
+ if m.invoked_as_script?
104
+ load Gem.bin_path("bundler", "bundle")
105
+ end
data/bin/pry CHANGED
@@ -8,13 +8,21 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- bundle_binstub = File.expand_path("../bundle", __FILE__)
12
- load(bundle_binstub) if File.file?(bundle_binstub)
13
-
14
11
  require "pathname"
15
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../gems.rb",
16
13
  Pathname.new(__FILE__).realpath)
17
14
 
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
18
26
  require "rubygems"
19
27
  require "bundler/setup"
20
28
 
data/bin/rspec CHANGED
@@ -8,13 +8,21 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- bundle_binstub = File.expand_path("../bundle", __FILE__)
12
- load(bundle_binstub) if File.file?(bundle_binstub)
13
-
14
11
  require "pathname"
15
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../gems.rb",
16
13
  Pathname.new(__FILE__).realpath)
17
14
 
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
18
26
  require "rubygems"
19
27
  require "bundler/setup"
20
28
 
data/gems.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # typed: false
3
+
1
4
  source 'https://rubygems.org'
2
5
 
3
6
  gemspec
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # typed: strong
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
5
  # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # typed: true
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
5
  # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
@@ -61,6 +62,7 @@ module Persistent💎
61
62
  def a💎
62
63
  Persistent💎::Array
63
64
  end
65
+
64
66
  alias_method :aDmnd, :a💎
65
67
 
66
68
  # Create a new persistent hash
@@ -73,6 +75,7 @@ module Persistent💎
73
75
  def h💎
74
76
  Persistent💎::Hash
75
77
  end
78
+
76
79
  alias_method :hDmnd, :h💎
77
80
 
78
81
  # Create a new persistent set
@@ -85,6 +88,7 @@ module Persistent💎
85
88
  def s💎
86
89
  Persistent💎::Set
87
90
  end
91
+
88
92
  alias_method :sDmnd, :s💎
89
93
 
90
94
  # Pretty syntax to making something persistent
@@ -104,6 +108,7 @@ module Persistent💎
104
108
  def 💎ify
105
109
  Persistent💎::Dmndifier
106
110
  end
111
+
107
112
  alias_method :dmndify, :💎ify
108
113
  end
109
114
 
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # typed: false
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
5
  # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
@@ -62,6 +63,7 @@ module Persistent💎
62
63
  ConcurrentRubySupport::ensure_concurrent_ruby_loaded
63
64
  Concurrent::Array.new(self)
64
65
  end
66
+
65
67
  alias :to_concurrent :to_concurrent_array
66
68
 
67
69
  # Return Concurrent::Tuple with contents of Persistent💎::Array
@@ -85,16 +87,19 @@ module Persistent💎
85
87
  def to_a💎
86
88
  self
87
89
  end
90
+
88
91
  alias_method :to_aDmnd, :to_a💎
89
92
 
90
93
  def to_h💎
91
94
  h💎[self]
92
95
  end
96
+
93
97
  alias_method :to_hDmnd, :to_h💎
94
98
 
95
99
  def to_s💎
96
100
  s💎[*self]
97
101
  end
102
+
98
103
  alias_method :to_sDmnd, :to_s💎
99
104
  end
100
105
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # typed: true
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
5
  # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
@@ -65,7 +66,7 @@ module Persistent💎
65
66
 
66
67
  def raise_no_concurrent_ruby
67
68
  raise(NotImplementedError,
68
- 'concurrent-ruby gem is not available, please install it in order to use #to_concurrent and #to_concurrent_* methods')
69
+ 'concurrent-ruby gem is not available, please install it in order to use #to_concurrent and #to_concurrent_* methods')
69
70
  end
70
71
 
71
72
  # The following methods are only for internal and test usage. Please do not use them :)
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # typed: true
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
5
  # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
@@ -40,7 +41,7 @@ module Persistent💎
40
41
  DEFAULT_OPTIONS = {
41
42
  on_unknown: proc { |arg|
42
43
  raise ArgumentError, "Could not 💎ify an object of class #{arg.class}. Maybe you need to implement :to_💎?"
43
- }
44
+ },
44
45
  }.freeze
45
46
 
46
47
  private_constant :DEFAULT_OPTIONS
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # typed: ignore
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
5
  # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # typed: false
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
5
  # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
@@ -57,6 +58,7 @@ module Persistent💎
57
58
  ConcurrentRubySupport::ensure_concurrent_ruby_loaded
58
59
  Concurrent::Hash[self]
59
60
  end
61
+
60
62
  alias :to_concurrent :to_concurrent_hash
61
63
 
62
64
  # Return Concurrent::Map with contents of Persistent💎::Hash
@@ -105,21 +107,25 @@ module Persistent💎
105
107
  enum_for(:each💎)
106
108
  end
107
109
  end
110
+
108
111
  alias_method :eachDmnd, :each💎
109
112
 
110
113
  def to_a💎
111
114
  a💎[*each💎]
112
115
  end
116
+
113
117
  alias_method :to_aDmnd, :to_a💎
114
118
 
115
119
  def to_h💎
116
120
  self
117
121
  end
122
+
118
123
  alias_method :to_hDmnd, :to_h💎
119
124
 
120
125
  def to_s💎
121
126
  s💎[*each💎]
122
127
  end
128
+
123
129
  alias_method :to_sDmnd, :to_s💎
124
130
  end
125
131
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # typed: true
2
3
 
3
4
  # Persistent-💎: Ruby gem for easily creating immutable data structures
4
5
  # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
@@ -0,0 +1,155 @@
1
+ # encoding: UTF-8
2
+ # typed: false
3
+
4
+ # Persistent-💎: Ruby gem for easily creating immutable data structures
5
+ # Copyright (c) 2017-2018 Ivo Anjo <ivo.anjo@ist.utl.pt>
6
+ #
7
+ # This file is part of Persistent-💎, and parts were inspired by Ruby's set.rb
8
+ # https://github.com/ruby/ruby/blob/v2_6_0_preview2/lib/set.rb
9
+ # Copyright (c) 2002-2016 Akinori MUSHA <knu@iDaemons.org>
10
+ # All rights reserved. You can redistribute and/or modify it under the same terms as Ruby. See
11
+ # https://github.com/ruby/ruby/blob/v2_6_0_preview2/COPYING for more details.
12
+
13
+ # frozen_string_literal: true
14
+
15
+ require 'set'
16
+
17
+ module Persistent💎
18
+ # Workaround for https://github.com/jruby/jruby/issues/5227
19
+ # We monkey patch the Ruby Set methods affected to restore their interoperable behavior
20
+ #
21
+ module JRuby92SetWorkaround
22
+ def self.workaround_needed?
23
+ workaround_checker = Object.new
24
+ workaround_checker.instance_eval do
25
+ def is_a?(klass)
26
+ super || klass == Set
27
+ end
28
+
29
+ def size
30
+ 0
31
+ end
32
+
33
+ def all?
34
+ false
35
+ end
36
+ end
37
+
38
+ begin
39
+ Set.new.superset?(workaround_checker)
40
+ false
41
+ rescue ArgumentError => e
42
+ e.message == "value must be a set"
43
+ end
44
+ end
45
+
46
+ if RUBY_PLATFORM == 'java' && JRUBY_VERSION.start_with?('9.2.') && workaround_needed?
47
+ class ::Set
48
+ # Save existing Set methods
49
+
50
+ alias persistent_dmnd_workaround_original_equal ==
51
+ alias persistent_dmnd_workaround_original_superset? superset?
52
+ alias persistent_dmnd_workaround_original_proper_superset? proper_superset?
53
+ alias persistent_dmnd_workaround_original_subset? subset?
54
+ alias persistent_dmnd_workaround_original_proper_subset? proper_subset?
55
+ alias persistent_dmnd_workaround_original_intersect? intersect?
56
+ alias persistent_dmnd_workaround_original_disjoint? disjoint?
57
+ alias persistent_dmnd_workaround_original_flatten_merge flatten_merge
58
+ alias persistent_dmnd_workaround_original_flatten flatten
59
+ alias persistent_dmnd_workaround_original_flatten! flatten!
60
+
61
+ # Redefine all set methods that use instanceof RubySet to restore previous behavior
62
+
63
+ def ==(other)
64
+ persistent_dmnd_workaround_original_equal(other) ||
65
+ (other.is_a?(::Set) && size == other.size && other.all? { |o| include?(o) })
66
+ end
67
+
68
+ def superset?(set)
69
+ persistent_dmnd_workaround_original_superset?(set)
70
+ rescue ArgumentError => e
71
+ raise unless e.message == "value must be a set" && set.is_a?(::Set)
72
+ size >= set.size && set.all? { |o| include?(o) }
73
+ end
74
+
75
+ def proper_superset?(set)
76
+ persistent_dmnd_workaround_original_proper_superset?(set)
77
+ rescue ArgumentError => e
78
+ raise unless e.message == "value must be a set" && set.is_a?(::Set)
79
+ size > set.size && set.all? { |o| include?(o) }
80
+ end
81
+
82
+ def subset?(set)
83
+ persistent_dmnd_workaround_original_subset?(set)
84
+ rescue ArgumentError => e
85
+ raise unless e.message == "value must be a set" && set.is_a?(::Set)
86
+ size <= set.size && all? { |o| set.include?(o) }
87
+ end
88
+
89
+ def proper_subset?(set)
90
+ persistent_dmnd_workaround_original_proper_subset?(set)
91
+ rescue ArgumentError => e
92
+ raise unless e.message == "value must be a set" && set.is_a?(::Set)
93
+ size < set.size && all? { |o| set.include?(o) }
94
+ end
95
+
96
+ def intersect?(set)
97
+ persistent_dmnd_workaround_original_intersect?(set)
98
+ rescue ArgumentError => e
99
+ raise unless e.message == "value must be a set" && set.is_a?(::Set)
100
+ if size < set.size
101
+ any? { |o| set.include?(o) }
102
+ else
103
+ set.any? { |o| include?(o) }
104
+ end
105
+ end
106
+
107
+ def disjoint?(set)
108
+ persistent_dmnd_workaround_original_disjoint?(set)
109
+ rescue ArgumentError => e
110
+ raise unless e.message == "value must be a set" && set.is_a?(::Set)
111
+ !(
112
+ if size < set.size
113
+ any? { |o| set.include?(o) }
114
+ else
115
+ set.any? { |o| include?(o) }
116
+ end
117
+ )
118
+ end
119
+
120
+ def flatten_merge(set, seen = ::Set.new)
121
+ set.each do |o|
122
+ if o.is_a?(::Set)
123
+ if seen.include?(o_id = o.object_id)
124
+ raise ArgumentError, "tried to flatten recursive Set"
125
+ end
126
+
127
+ seen.add(o_id)
128
+ flatten_merge(o, seen)
129
+ seen.delete(o_id)
130
+ else
131
+ add(o)
132
+ end
133
+ end
134
+
135
+ self
136
+ end
137
+
138
+ def flatten
139
+ self.class.new.flatten_merge(self)
140
+ end
141
+
142
+ def flatten!
143
+ replace(flatten()) if any? { |o| o.is_a?(::Set) }
144
+ end
145
+
146
+ # Reset aliases to point to redefined methods (otherwise they would keep on pointing to the old variants)
147
+
148
+ alias >= superset?
149
+ alias > proper_superset?
150
+ alias <= subset?
151
+ alias < proper_subset?
152
+ end
153
+ end
154
+ end
155
+ end