typesafe_enum 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +72 -7
- data/.ruby-version +1 -1
- data/CHANGES.md +6 -0
- data/README.md +4 -4
- data/lib/typesafe_enum.rb +1 -1
- data/lib/typesafe_enum/base.rb +4 -0
- data/lib/typesafe_enum/module_info.rb +2 -2
- data/spec/.rubocop.yml +5 -5
- data/spec/unit/typesafe_enum/base_spec.rb +6 -2
- data/typesafe_enum.gemspec +4 -8
- metadata +8 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 993bd214447b49bb0ad4d3586e4486f45b5a4e728d6240c1cf72909c62f37577
|
4
|
+
data.tar.gz: f8110980c436802a9737425ecca99641d837f56458cdc6c2afb4ec7789685c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1ecbac3bef591d12993ecb0d0252d625720e9ce7259e7bd673eb754c4d6db98b489aeb581be92a3c21f506a8bcf362f8d52e237e65e2882e5eed3894ad82393
|
7
|
+
data.tar.gz: 829ad9e7e94d28d3682aca8d0295ac5bfb4eb75982a6f1399e49538689f223ee0df673613756b05f8d49b53002aa9510bf66debf14c3b90f19d5feb4d11e0945
|
data/.rubocop.yml
CHANGED
@@ -3,22 +3,87 @@ Style/ClassAndModuleChildren:
|
|
3
3
|
Exclude:
|
4
4
|
- 'example.rb'
|
5
5
|
|
6
|
-
#
|
6
|
+
# Allow one line around block body (Layout/EmptyLines will still disallow two or more)
|
7
|
+
Layout/EmptyLinesAroundBlockBody:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# Allow one line around class body (Layout/EmptyLines will still disallow two or more)
|
11
|
+
Layout/EmptyLinesAroundClassBody:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
# Allow one line around module body (Layout/EmptyLines will still disallow two or more)
|
15
|
+
Layout/EmptyLinesAroundModuleBody:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
# Make indents consistent regardless of the lengths of variables and method names and whatnot
|
19
|
+
Layout/MultilineMethodCallIndentation:
|
20
|
+
EnforcedStyle: indented
|
21
|
+
|
22
|
+
# Produces monsters
|
23
|
+
Layout/MultilineOperationIndentation:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
# Reasonable line-length check; it's too easy for the cure to be worse than the disease
|
7
27
|
Metrics/LineLength:
|
28
|
+
Max: 150
|
29
|
+
|
30
|
+
# Just because something looks like an accessor doesn't mean it is one
|
31
|
+
Naming/PredicateName:
|
32
|
+
Exclude:
|
33
|
+
- 'app/controllers/application_controller.rb'
|
34
|
+
|
35
|
+
# Confusing and weird
|
36
|
+
Naming/VariableNumber:
|
37
|
+
Enabled: False
|
38
|
+
|
39
|
+
# We meant to do that
|
40
|
+
Naming/MemoizedInstanceVariableName:
|
41
|
+
Enabled: False
|
42
|
+
|
43
|
+
# It works in context, trust us
|
44
|
+
Naming/UncommunicativeMethodParamName:
|
45
|
+
Enabled: False
|
46
|
+
|
47
|
+
# Do what's readable in the context you're in
|
48
|
+
Style/AccessModifierDeclarations:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
# 👎 to cultural imperialism
|
52
|
+
Style/AsciiComments:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
# Sometimes we want to distinguish hash parameters from keyword arguments
|
56
|
+
Style/BracesAroundHashParameters:
|
57
|
+
Enabled: False
|
58
|
+
|
59
|
+
# Seriously?
|
60
|
+
Style/CommentedKeyword:
|
8
61
|
Enabled: False
|
9
62
|
|
10
63
|
# Disable problematic module documentation check (see https://github.com/bbatsov/rubocop/issues/947)
|
11
64
|
Style/Documentation:
|
12
65
|
Enabled: false
|
13
66
|
|
14
|
-
#
|
15
|
-
|
67
|
+
# Adding more line noise to format strings will not improve them
|
68
|
+
Style/FormatStringToken:
|
16
69
|
Enabled: false
|
17
70
|
|
18
|
-
#
|
19
|
-
|
71
|
+
# Putting '# frozen_string_literal: true' everywhere does not make the world a better place
|
72
|
+
Style/FrozenStringLiteralComment:
|
20
73
|
Enabled: false
|
21
74
|
|
22
|
-
#
|
23
|
-
|
75
|
+
# `foo.positive?` is cute, but it's not actually more readable than `foo > 0`
|
76
|
+
Style/NumericPredicate:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
# The semantics of `foo&.bar` are a lot less interchangeable with `foo && foo.bar` than RuboCop thinks
|
80
|
+
Style/SafeNavigation:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
# Requiring the lambda() method just makes wordy calls wordier
|
84
|
+
Style/Lambda:
|
85
|
+
EnforcedStyle: literal
|
86
|
+
|
87
|
+
# Unclear why it's a good idea to give parameters semantically meaningless names
|
88
|
+
Style/SingleLineBlockParams:
|
24
89
|
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.1
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# TypesafeEnum
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/
|
4
|
-
[![Code Climate](https://codeclimate.com/github/
|
5
|
-
[![Inline docs](http://inch-ci.org/github/
|
6
|
-
[![Gem Version](https://img.shields.io/gem/v/typesafe_enum.svg)](https://github.com/
|
3
|
+
[![Build Status](https://travis-ci.org/dmolesUC/typesafe_enum.svg?branch=master)](https://travis-ci.org/dmolesUC/typesafe_enum)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/dmolesUC/typesafe_enum.svg)](https://codeclimate.com/github/dmolesUC/typesafe_enum)
|
5
|
+
[![Inline docs](http://inch-ci.org/github/dmolesUC/typesafe_enum.svg)](http://inch-ci.org/github/dmolesUC/typesafe_enum)
|
6
|
+
[![Gem Version](https://img.shields.io/gem/v/typesafe_enum.svg)](https://github.com/dmolesUC/typesafe_enum/releases)
|
7
7
|
|
8
8
|
A Ruby implementation of Joshua Bloch's
|
9
9
|
[typesafe enum pattern](http://www.oracle.com/technetwork/java/page1-139488.html#replaceenums),
|
data/lib/typesafe_enum.rb
CHANGED
data/lib/typesafe_enum/base.rb
CHANGED
@@ -71,6 +71,7 @@ module TypesafeEnum
|
|
71
71
|
# @return [self, nil] the corresponding enum instance, or nil
|
72
72
|
def find_by_ord(ord)
|
73
73
|
return nil if ord > size || ord.negative?
|
74
|
+
|
74
75
|
as_array[ord]
|
75
76
|
end
|
76
77
|
|
@@ -97,10 +98,12 @@ module TypesafeEnum
|
|
97
98
|
value = instance.value
|
98
99
|
if (found = find_by_key(key))
|
99
100
|
raise NameError, "#{name}::#{key} already exists" unless value == found.value
|
101
|
+
|
100
102
|
warn("ignoring redeclaration of #{name}::#{key} with value #{value} (source: #{caller(5..5).first})")
|
101
103
|
nil
|
102
104
|
else
|
103
105
|
raise NameError, "A #{name} instance with value '#{value}' already exists" if find_by_value(value)
|
106
|
+
|
104
107
|
[key, value]
|
105
108
|
end
|
106
109
|
end
|
@@ -157,6 +160,7 @@ module TypesafeEnum
|
|
157
160
|
|
158
161
|
def initialize(key, value = nil, &block)
|
159
162
|
raise TypeError, "#{key} is not a symbol" unless key.is_a?(Symbol)
|
163
|
+
|
160
164
|
@key = key
|
161
165
|
@value = value || key.to_s.downcase
|
162
166
|
@ord = self.class.size
|
@@ -5,8 +5,8 @@ module TypesafeEnum
|
|
5
5
|
NAME = 'typesafe_enum'
|
6
6
|
|
7
7
|
# The version of this gem
|
8
|
-
VERSION = '0.1.
|
8
|
+
VERSION = '0.1.9'
|
9
9
|
|
10
10
|
# The copyright notice for this gem
|
11
|
-
COPYRIGHT = 'Copyright (c)
|
11
|
+
COPYRIGHT = 'Copyright (c) 2019 The Regents of the University of California'
|
12
12
|
end
|
data/spec/.rubocop.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
inherit_from: ../.rubocop.yml
|
2
2
|
|
3
|
-
|
3
|
+
Style/ClassAndModuleChildren:
|
4
4
|
Enabled: false
|
5
5
|
|
6
|
-
Metrics/
|
6
|
+
Metrics/AbcSize:
|
7
7
|
Enabled: false
|
8
8
|
|
9
|
-
Metrics/
|
9
|
+
Metrics/BlockLength:
|
10
10
|
Enabled: false
|
11
11
|
|
12
|
-
|
12
|
+
Metrics/ModuleLength:
|
13
13
|
Enabled: false
|
14
14
|
|
15
|
-
|
15
|
+
Metrics/MethodLength:
|
16
16
|
Enabled: false
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'spec_helper'
|
@@ -94,7 +93,8 @@ module TypesafeEnum
|
|
94
93
|
class ::IdenticalInstances < Base
|
95
94
|
new :SPADES, 'spades'
|
96
95
|
end
|
97
|
-
|
96
|
+
expected_msg = /ignoring redeclaration of IdenticalInstances::SPADES with value spades/
|
97
|
+
expect(::IdenticalInstances).to receive(:warn).with(a_string_matching(expected_msg))
|
98
98
|
class ::IdenticalInstances < Base
|
99
99
|
new :SPADES, 'spades'
|
100
100
|
end
|
@@ -190,6 +190,7 @@ module TypesafeEnum
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
+
# rubocop:disable Security/MarshalLoad
|
193
194
|
it 'survives marshalling' do
|
194
195
|
Suit.each do |s1|
|
195
196
|
dump = Marshal.dump(s1)
|
@@ -198,6 +199,7 @@ module TypesafeEnum
|
|
198
199
|
expect(s2 == s1).to eq(true)
|
199
200
|
end
|
200
201
|
end
|
202
|
+
# rubocop:enable Security/MarshalLoad
|
201
203
|
end
|
202
204
|
|
203
205
|
describe '#!=' do
|
@@ -245,6 +247,7 @@ module TypesafeEnum
|
|
245
247
|
end
|
246
248
|
end
|
247
249
|
|
250
|
+
# rubocop:disable Security/MarshalLoad
|
248
251
|
it 'survives marshalling' do
|
249
252
|
Suit.each do |s1|
|
250
253
|
dump = Marshal.dump(s1)
|
@@ -252,6 +255,7 @@ module TypesafeEnum
|
|
252
255
|
expect(s2.hash).to eq(s1.hash)
|
253
256
|
end
|
254
257
|
end
|
258
|
+
# rubocop:enable Security/MarshalLoad
|
255
259
|
|
256
260
|
it 'always returns a Fixnum' do
|
257
261
|
Suit.each do |s1|
|
data/typesafe_enum.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
5
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
5
|
|
7
6
|
require 'uri'
|
@@ -16,9 +15,7 @@ Gem::Specification.new do |spec|
|
|
16
15
|
spec.description = 'A gem that implements the typesafe enum pattern in Ruby'
|
17
16
|
spec.license = 'MIT'
|
18
17
|
|
19
|
-
|
20
|
-
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.gsub(%r{git@([^:]+)(.com|.org)[^\/]+}, 'http://\1\2'))
|
21
|
-
spec.homepage = URI::HTTP.build(host: origin_uri.host, path: origin_uri.path.chomp('.git')).to_s
|
18
|
+
spec.homepage = 'https://github.com/dmolesUC/typesafe_enum'
|
22
19
|
|
23
20
|
spec.files = `git ls-files -z`.split("\x0")
|
24
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -26,10 +23,9 @@ Gem::Specification.new do |spec|
|
|
26
23
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
27
24
|
spec.require_paths = ['lib']
|
28
25
|
|
29
|
-
spec.add_development_dependency 'bundler', '~> 1.7'
|
30
26
|
spec.add_development_dependency 'rake', '~> 10.4'
|
31
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
32
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.74'
|
33
29
|
spec.add_development_dependency 'simplecov', '~> 0.9.2'
|
34
30
|
spec.add_development_dependency 'simplecov-console', '~> 0.2.0'
|
35
31
|
spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.12'
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typesafe_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
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.7'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.7'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,28 +30,28 @@ dependencies:
|
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
33
|
+
version: '3.8'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
40
|
+
version: '3.8'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rubocop
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
47
|
+
version: '0.74'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
54
|
+
version: '0.74'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: simplecov
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,7 +124,7 @@ files:
|
|
138
124
|
- spec/spec_helper.rb
|
139
125
|
- spec/unit/typesafe_enum/base_spec.rb
|
140
126
|
- typesafe_enum.gemspec
|
141
|
-
homepage:
|
127
|
+
homepage: https://github.com/dmolesUC/typesafe_enum
|
142
128
|
licenses:
|
143
129
|
- MIT
|
144
130
|
metadata: {}
|
@@ -157,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
143
|
- !ruby/object:Gem::Version
|
158
144
|
version: '0'
|
159
145
|
requirements: []
|
160
|
-
|
161
|
-
rubygems_version: 2.6.12
|
146
|
+
rubygems_version: 3.0.4
|
162
147
|
signing_key:
|
163
148
|
specification_version: 4
|
164
149
|
summary: Typesafe enum pattern for Ruby
|