persistent-dmnd 1.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,92 @@
1
+ # encoding: UTF-8
2
+
3
+ # Persistent-💎: Ruby gem for easily creating immutable data structures
4
+ # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ #
6
+ # This file is part of Persistent-💎.
7
+ #
8
+ # MIT License
9
+ #
10
+ # Copyright (c) 2017 Ivo Anjo
11
+ #
12
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ # of this software and associated documentation files (the "Software"), to deal
14
+ # in the Software without restriction, including without limitation the rights
15
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ # copies of the Software, and to permit persons to whom the Software is
17
+ # furnished to do so, subject to the following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included in all
20
+ # copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ # SOFTWARE.
29
+
30
+ # frozen_string_literal: true
31
+
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
+
37
+ require 'hamster'
38
+ require 'set'
39
+
40
+ module Persistent💎
41
+ class Set < Hamster::Set
42
+ include SelfConversion
43
+ include IsPersistent
44
+ include JRubyWorkaround
45
+ include Persistent💎
46
+
47
+ def self.from_set(set)
48
+ self[*set.to_a]
49
+ end
50
+
51
+ def ==(other)
52
+ super || other.respond_to?(:to_set) && set_eq?(other.to_set)
53
+ end
54
+
55
+ def is_a?(klass)
56
+ super ||
57
+ # hack to allow Set to be comparable with us
58
+ # and yes a Persistent💎::Set is a Set: go away, stop type-checking and start duck typing!
59
+ klass == ::Set
60
+ end
61
+
62
+ def to_set
63
+ ::Set.new(self)
64
+ end
65
+
66
+ # Default behavior from Kernel#<=>
67
+ def <=>(other)
68
+ self == other ? 0 : nil
69
+ end
70
+
71
+ def to_a💎
72
+ a💎[*self]
73
+ end
74
+ alias_method :to_aDmnd, :to_a💎
75
+
76
+ def to_h💎
77
+ h💎[self]
78
+ end
79
+ alias_method :to_hDmnd, :to_h💎
80
+
81
+ def to_s💎
82
+ self
83
+ end
84
+ alias_method :to_sDmnd, :to_s💎
85
+
86
+ private
87
+
88
+ def set_eq?(other)
89
+ self.size == other.size && other.all? { |item| include?(item) }
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+
3
+ # Persistent-💎: Ruby gem for easily creating immutable data structures
4
+ # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ #
6
+ # This file is part of Persistent-💎.
7
+ #
8
+ # MIT License
9
+ #
10
+ # Copyright (c) 2017 Ivo Anjo
11
+ #
12
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ # of this software and associated documentation files (the "Software"), to deal
14
+ # in the Software without restriction, including without limitation the rights
15
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ # copies of the Software, and to permit persons to whom the Software is
17
+ # furnished to do so, subject to the following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included in all
20
+ # copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ # SOFTWARE.
29
+
30
+ # frozen_string_literal: true
31
+
32
+ module Persistent💎
33
+ VERSION = '1.0.0'
34
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: UTF-8
2
+
3
+ # Persistent-💎: Ruby gem for easily creating immutable data structures
4
+ # Copyright (c) 2017 Ivo Anjo <ivo.anjo@ist.utl.pt>
5
+ #
6
+ # This file is part of Persistent-💎.
7
+ #
8
+ # MIT License
9
+ #
10
+ # Copyright (c) 2017 Ivo Anjo
11
+ #
12
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ # of this software and associated documentation files (the "Software"), to deal
14
+ # in the Software without restriction, including without limitation the rights
15
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ # copies of the Software, and to permit persons to whom the Software is
17
+ # furnished to do so, subject to the following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included in all
20
+ # copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ # SOFTWARE.
29
+
30
+ # frozen_string_literal: true
31
+
32
+ lib = File.expand_path('../lib', __FILE__)
33
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
34
+ require 'persistent_dmnd/version'
35
+
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'
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://github.com/ivoanjo/persistent-dmnd/'
45
+ spec.license = 'MIT'
46
+
47
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
48
+ f.match(%r{^(test|spec|features)/})
49
+ end
50
+ spec.require_paths = ['lib']
51
+
52
+ spec.required_ruby_version = '>= 1.9.3'
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'
58
+ spec.add_development_dependency 'pry'
59
+ spec.add_development_dependency 'pry-byebug' unless RUBY_PLATFORM == 'java' || RUBY_VERSION.start_with?('1.9.')
60
+ spec.add_development_dependency 'pry-debugger-jruby' if RUBY_PLATFORM == 'java' && !JRUBY_VERSION.start_with?('1.7.')
61
+
62
+ spec.add_dependency 'hamster', '~> 3.0'
63
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: persistent-dmnd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ivo Anjo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: concurrent-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hamster
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: A tiny ruby gem that gives you a beautiful short-hand syntax for creating
112
+ immutable arrays, hashes and sets
113
+ email: ivo.anjo@ist.utl.pt
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".ruby-version"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.adoc
123
+ - Gemfile
124
+ - LICENSE
125
+ - README.adoc
126
+ - Rakefile
127
+ - UPSTREAM_TODO.adoc
128
+ - bin/pry
129
+ - bin/rspec
130
+ - gems.rb
131
+ - lib/persistent-dmnd.rb
132
+ - "lib/persistent-\U0001F48E.rb"
133
+ - lib/persistent_dmnd/array.rb
134
+ - lib/persistent_dmnd/concurrent_ruby_support.rb
135
+ - lib/persistent_dmnd/dmndifier.rb
136
+ - lib/persistent_dmnd/everywhere.rb
137
+ - lib/persistent_dmnd/hash.rb
138
+ - lib/persistent_dmnd/is_persistent.rb
139
+ - lib/persistent_dmnd/jruby_workaround.rb
140
+ - lib/persistent_dmnd/ruby_1_9_and_2_0_support.rb
141
+ - lib/persistent_dmnd/self_conversion.rb
142
+ - lib/persistent_dmnd/set.rb
143
+ - lib/persistent_dmnd/version.rb
144
+ - persistent-dmnd.gemspec
145
+ homepage: https://github.com/ivoanjo/persistent-dmnd/
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: 1.9.3
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.7.3
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: "Persistent-\U0001F48E: Because Immutable Data Is Forever"
169
+ test_files: []