typesafe_enum 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a03ce1356a736037c69f793aaffb12ffe001b4e8
4
- data.tar.gz: 3d748bba73a6df9a5f2bf929c379ef2a2ca904b4
3
+ metadata.gz: 1f9b1132621b9e769433ef61e8fd2512a66197c4
4
+ data.tar.gz: f5394bf7f1a1e88c56c727352f8d2dd113934855
5
5
  SHA512:
6
- metadata.gz: f8437ae0afc6f20a003ca259fedf412378ffdea8c9090b17cc9271326cb78a0c43dd8dda22a3df31c32d468b94ea8e7edbb3b586ca8c582c967ac7c447da1a03
7
- data.tar.gz: c55260cab261cc0273cfc61ca0eaaf686f57ecda9d18d8ea6c13e237e12ae97bd4909fc1ce54bd1545d2f4fb50c7e9c5d38cd04572e4d39172db3a71790dfc80
6
+ metadata.gz: ffd661decf927ce85719a8cac164e7105f674e4289d68d546102f500aeb8d3a70907a25fafee22960c07967104ec77b8ee4ac8310450ba2febeafdb75c31dfa0
7
+ data.tar.gz: 6f4770854fe78d823c0031f16338c081a4fbac9def1e519e4f7c579566c57ffbac0a13f4d597890b42fe97df614a52a3f6ff83b48fca5b505c96004bcf9833c0
data/.gitignore CHANGED
@@ -1,3 +1,7 @@
1
+ # IDEA
2
+
3
+ .idea
4
+
1
5
  # Ruby defaults
2
6
 
3
7
  /.bundle/
@@ -12,13 +12,13 @@ Style/Documentation:
12
12
  Enabled: false
13
13
 
14
14
  # Allow one line around class body (Style/EmptyLines will still disallow two or more)
15
- Style/EmptyLinesAroundClassBody:
15
+ Layout/EmptyLinesAroundClassBody:
16
16
  Enabled: false
17
17
 
18
18
  # Allow one line around module body (Style/EmptyLines will still disallow two or more)
19
- Style/EmptyLinesAroundModuleBody:
19
+ Layout/EmptyLinesAroundModuleBody:
20
20
  Enabled: false
21
21
 
22
22
  # Allow one line around block body (Style/EmptyLines will still disallow two or more)
23
- Style/EmptyLinesAroundBlockBody:
23
+ Layout/EmptyLinesAroundBlockBody:
24
24
  Enabled: false
@@ -1 +1 @@
1
- 2.2.3
1
+ 2.4.1
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.1.8 (22 December 2017)
2
+
3
+ - Update to Ruby 2.4.1
4
+ - Update to rspec 3.7
5
+ - Update to RuboCop 0.52
6
+ - Update to Yard 0.9.12
7
+
1
8
  ## 0.1.7 (28 April 2016)
2
9
 
3
10
  - The default `to_s` for `TypesafeEnum::Base` now includes the enum's class, key, value,
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # ------------------------------------------------------------
2
4
  # RSpec
3
5
 
@@ -8,7 +10,7 @@ namespace :spec do
8
10
 
9
11
  desc 'Run all unit tests'
10
12
  RSpec::Core::RakeTask.new(:unit) do |task|
11
- task.rspec_opts = %w(--color --format documentation --order default)
13
+ task.rspec_opts = %w[--color --format documentation --order default]
12
14
  task.pattern = 'unit/**/*_spec.rb'
13
15
  end
14
16
 
@@ -38,7 +40,7 @@ RuboCop::RakeTask.new
38
40
 
39
41
  desc 'List TODOs (from spec/todo.rb)'
40
42
  RSpec::Core::RakeTask.new(:todo) do |task|
41
- task.rspec_opts = %w(--color --format documentation --order default)
43
+ task.rspec_opts = %w[--color --format documentation --order default]
42
44
  task.pattern = 'todo.rb'
43
45
  end
44
46
 
@@ -46,4 +48,4 @@ end
46
48
  # Defaults
47
49
 
48
50
  desc 'Run unit tests, check test coverage, run acceptance tests, check code style'
49
- task default: [:coverage, :rubocop]
51
+ task default: %i[coverage rubocop]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TypesafeEnum
2
4
  Dir.glob(File.expand_path('../typesafe_enum/*.rb', __FILE__)).sort.each(&method(:require))
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A Ruby implementation of Joshua Bloch's
2
4
  # [typesafe enum pattern](http://www.oracle.com/technetwork/java/page1-139488.html#replaceenums)
3
5
  module TypesafeEnum
@@ -68,7 +70,7 @@ module TypesafeEnum
68
70
  # @param ord [Integer] the ordinal to look up
69
71
  # @return [self, nil] the corresponding enum instance, or nil
70
72
  def find_by_ord(ord)
71
- return nil if ord < 0 || ord > size
73
+ return nil if ord > size || ord.negative?
72
74
  as_array[ord]
73
75
  end
74
76
 
@@ -94,11 +96,11 @@ module TypesafeEnum
94
96
  key = instance.key
95
97
  value = instance.value
96
98
  if (found = find_by_key(key))
97
- fail NameError, "#{name}::#{key} already exists" unless value == found.value
98
- warn("ignoring redeclaration of #{name}::#{key} with value #{value} (source: #{caller[4]})")
99
+ raise NameError, "#{name}::#{key} already exists" unless value == found.value
100
+ warn("ignoring redeclaration of #{name}::#{key} with value #{value} (source: #{caller(5..5).first})")
99
101
  nil
100
102
  else
101
- fail NameError, "A #{name} instance with value '#{value}' already exists" if find_by_value(value)
103
+ raise NameError, "A #{name} instance with value '#{value}' already exists" if find_by_value(value)
102
104
  [key, value]
103
105
  end
104
106
  end
@@ -143,7 +145,7 @@ module TypesafeEnum
143
145
  result = 17
144
146
  result = 31 * result + self.class.hash
145
147
  result = 31 * result + ord
146
- result.is_a?(Fixnum) ? result : result.hash
148
+ result.is_a?(Integer) ? result : result.hash
147
149
  end
148
150
  end
149
151
 
@@ -154,7 +156,7 @@ module TypesafeEnum
154
156
  private
155
157
 
156
158
  def initialize(key, value = nil, &block)
157
- fail TypeError, "#{key} is not a symbol" unless key.is_a?(Symbol)
159
+ raise TypeError, "#{key} is not a symbol" unless key.is_a?(Symbol)
158
160
  @key = key
159
161
  @value = value || key.to_s.downcase
160
162
  @ord = self.class.size
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TypesafeEnum
2
4
  # The name of this gem
3
5
  NAME = 'typesafe_enum'
4
6
 
5
7
  # The version of this gem
6
- VERSION = '0.1.7'
8
+ VERSION = '0.1.8'
7
9
 
8
10
  # The copyright notice for this gem
9
- COPYRIGHT = 'Copyright (c) 2016 The Regents of the University of California'
11
+ COPYRIGHT = 'Copyright (c) 2017 The Regents of the University of California'
10
12
  end
@@ -1,5 +1,8 @@
1
1
  inherit_from: ../.rubocop.yml
2
2
 
3
+ Metrics/BlockLength:
4
+ Enabled: false
5
+
3
6
  Metrics/MethodLength:
4
7
  Enabled: false
5
8
 
@@ -8,3 +11,6 @@ Metrics/ModuleLength:
8
11
 
9
12
  Style/ClassAndModuleChildren:
10
13
  Enabled: false
14
+
15
+ Security/MarshalLoad:
16
+ Enabled: false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # ------------------------------------------------------------
2
4
  # SimpleCov setup
3
5
 
@@ -1,4 +1,6 @@
1
- # coding: utf-8
1
+
2
+ # frozen_string_literal: true
3
+
2
4
  require 'spec_helper'
3
5
 
4
6
  class Suit < TypesafeEnum::Base
@@ -152,7 +154,7 @@ module TypesafeEnum
152
154
  describe '::map' do
153
155
  it 'maps enum values' do
154
156
  all_keys = Suit.map(&:key)
155
- expect(all_keys).to eq([:CLUBS, :DIAMONDS, :HEARTS, :SPADES])
157
+ expect(all_keys).to eq(%i[CLUBS DIAMONDS HEARTS SPADES])
156
158
  end
157
159
  end
158
160
 
@@ -253,7 +255,7 @@ module TypesafeEnum
253
255
 
254
256
  it 'always returns a Fixnum' do
255
257
  Suit.each do |s1|
256
- expect(s1.hash).to be_a(Fixnum)
258
+ expect(s1.hash).to be_a(Integer)
257
259
  end
258
260
  end
259
261
  end
@@ -270,7 +272,7 @@ module TypesafeEnum
270
272
 
271
273
  describe '#value' do
272
274
  it 'returns the string value of the enum instance' do
273
- expected = %w(clubs diamonds hearts spades)
275
+ expected = %w[clubs diamonds hearts spades]
274
276
  Suit.each_with_index do |s, index|
275
277
  expect(s.value).to eq(expected[index])
276
278
  end
@@ -279,7 +281,7 @@ module TypesafeEnum
279
281
 
280
282
  describe '#key' do
281
283
  it 'returns the symbol key of the enum instance' do
282
- expected = [:CLUBS, :DIAMONDS, :HEARTS, :SPADES]
284
+ expected = %i[CLUBS DIAMONDS HEARTS SPADES]
283
285
  Suit.each_with_index do |s, index|
284
286
  expect(s.key).to eq(expected[index])
285
287
  end
@@ -301,7 +303,7 @@ module TypesafeEnum
301
303
  ec.each do |ev|
302
304
  result = ev.to_s
303
305
  [ec.to_s, ev.key, ev.ord, ev.value].each do |info|
304
- expect(result).to include("#{info}")
306
+ expect(result).to include(info.to_s)
305
307
  end
306
308
  end
307
309
  end
@@ -311,7 +313,7 @@ module TypesafeEnum
311
313
 
312
314
  describe '::find_by_key' do
313
315
  it 'maps symbol keys to enum instances' do
314
- keys = [:CLUBS, :DIAMONDS, :HEARTS, :SPADES]
316
+ keys = %i[CLUBS DIAMONDS HEARTS SPADES]
315
317
  expected = Suit.to_a
316
318
  keys.each_with_index do |k, index|
317
319
  expect(Suit.find_by_key(k)).to be(expected[index])
@@ -325,7 +327,7 @@ module TypesafeEnum
325
327
 
326
328
  describe '::find_by_value' do
327
329
  it 'maps values to enum instances' do
328
- values = %w(clubs diamonds hearts spades)
330
+ values = %w[clubs diamonds hearts spades]
329
331
  expected = Suit.to_a
330
332
  values.each_with_index do |n, index|
331
333
  expect(Suit.find_by_value(n)).to be(expected[index])
@@ -351,7 +353,7 @@ module TypesafeEnum
351
353
 
352
354
  describe '::find_by_value_str' do
353
355
  it 'maps string values to enum instances' do
354
- values = %w(clubs diamonds hearts spades)
356
+ values = %w[clubs diamonds hearts spades]
355
357
  expected = Suit.to_a
356
358
  values.each_with_index do |n, index|
357
359
  expect(Suit.find_by_value_str(n)).to be(expected[index])
@@ -407,11 +409,11 @@ module TypesafeEnum
407
409
  when Suit::SPADES
408
410
  '♠'
409
411
  else
410
- fail "unknown suit: #{self}"
412
+ raise "unknown suit: #{self}"
411
413
  end
412
414
  end
413
415
 
414
- expect(Suit.map { |s| pip(s) }).to eq(%w(♣ ♦ ♥ ♠))
416
+ expect(Suit.map { |s| pip(s) }).to eq(%w[♣ ♦ ♥ ♠])
415
417
  end
416
418
 
417
419
  it 'supports "inner class" methods' do
@@ -1,4 +1,6 @@
1
- # coding: utf-8
1
+
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
 
@@ -26,9 +28,9 @@ Gem::Specification.new do |spec|
26
28
 
27
29
  spec.add_development_dependency 'bundler', '~> 1.7'
28
30
  spec.add_development_dependency 'rake', '~> 10.4'
29
- spec.add_development_dependency 'rspec', '~> 3.2'
31
+ spec.add_development_dependency 'rspec', '~> 3.7'
32
+ spec.add_development_dependency 'rubocop', '~> 0.52'
30
33
  spec.add_development_dependency 'simplecov', '~> 0.9.2'
31
34
  spec.add_development_dependency 'simplecov-console', '~> 0.2.0'
32
- spec.add_development_dependency 'rubocop', '~> 0.32.1'
33
- spec.add_development_dependency 'yard', '~> 0.8'
35
+ spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.12'
34
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typesafe_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-28 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,70 +44,76 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.2'
47
+ version: '3.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.2'
54
+ version: '3.7'
55
55
  - !ruby/object:Gem::Dependency
56
- name: simplecov
56
+ name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.9.2
61
+ version: '0.52'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.9.2
68
+ version: '0.52'
69
69
  - !ruby/object:Gem::Dependency
70
- name: simplecov-console
70
+ name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.0
75
+ version: 0.9.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.0
82
+ version: 0.9.2
83
83
  - !ruby/object:Gem::Dependency
84
- name: rubocop
84
+ name: simplecov-console
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.32.1
89
+ version: 0.2.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.32.1
96
+ version: 0.2.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: yard
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.8'
103
+ version: '0.9'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 0.9.12
104
107
  type: :development
105
108
  prerelease: false
106
109
  version_requirements: !ruby/object:Gem::Requirement
107
110
  requirements:
108
111
  - - "~>"
109
112
  - !ruby/object:Gem::Version
110
- version: '0.8'
113
+ version: '0.9'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 0.9.12
111
117
  description: A gem that implements the typesafe enum pattern in Ruby
112
118
  email:
113
119
  - david.moles@ucop.edu
@@ -132,7 +138,7 @@ files:
132
138
  - spec/spec_helper.rb
133
139
  - spec/unit/typesafe_enum/base_spec.rb
134
140
  - typesafe_enum.gemspec
135
- homepage: http://github.com/dmolesUC3/typesafe_enum
141
+ homepage: http://github.com/typesafe_enum
136
142
  licenses:
137
143
  - MIT
138
144
  metadata: {}
@@ -152,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
158
  version: '0'
153
159
  requirements: []
154
160
  rubyforge_project:
155
- rubygems_version: 2.4.5.1
161
+ rubygems_version: 2.6.12
156
162
  signing_key:
157
163
  specification_version: 4
158
164
  summary: Typesafe enum pattern for Ruby
@@ -160,4 +166,3 @@ test_files:
160
166
  - spec/.rubocop.yml
161
167
  - spec/spec_helper.rb
162
168
  - spec/unit/typesafe_enum/base_spec.rb
163
- has_rdoc: