ruby-enum 0.4.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adefdfa7f7f41de28559b75eddd3a48d2fa624db
4
- data.tar.gz: fff0f432422d79528e170105fd2650095980b90f
3
+ metadata.gz: 9c0c38cc0b3edc3052b171b5dc3aacdee8a3e2f0
4
+ data.tar.gz: e561a122f1dcdc6b5657d1d004d37d37a00e8108
5
5
  SHA512:
6
- metadata.gz: eb221f6f89abf7b6e39239dbbcc1b99dbec7bf4f8913d02143fe9494c44503ffeea604fb746170bd619e62bb1195c9ba42fa5ce668af916d86818aa64901f365
7
- data.tar.gz: ef9203ba82087347bfa97310ed4b6414abbd052cf9af40babd991078c1e523b074f400df8786ab63ed3e5390839e944be41a0274dbe44fc9a64012d8c80db4dd
6
+ metadata.gz: 474384b04e35b3ab7e0fb5145cb07c545c12f8dd37df44c1c0c75d465439df575f4aeeb82e0ca2cc71b55dea25af610c08b2b57fcb8760abb5b9cfc40e9ca6ab
7
+ data.tar.gz: e98254d96a8f3f1af22f1ee3c34ca5d2de116724a2cae4f4ab8ba337a05cd2bf78397a6ae3bbf0a2771f3b76a915865b1cbf8ccdd3b8cfe97ffe84bbae7abe92
@@ -1,10 +1,14 @@
1
+ ### 0.5.0 (11/20/2015)
2
+
3
+ * [#8](https://github.com/dblock/ruby-enum/pull/8): Added `Ruby::Enum#key`, `Ruby::Enum#value`, `Ruby::Enum#key?`, and `Ruby::Enum#value?` - [@dmolesUC3](https://github.com/dmolesUC3).
4
+
1
5
  ### 0.4.0 (6/29/2014)
2
6
 
3
- * Mixed in `Enumerable` - [@kgann](https://github.com/kgann).
7
+ * [#5](https://github.com/dblock/ruby-enum/pull/5): Mixed in `Enumerable` - [@kgann](https://github.com/kgann).
4
8
 
5
9
  ### 0.3.0 (5/19/2014)
6
10
 
7
- * Added `Ruby::Enum#map` - [@ArnaudRinquin](https://github.com/ArnaudRinquin).
11
+ * [#4](https://github.com/dblock/ruby-enum/pull/4): Added `Ruby::Enum#map` - [@ArnaudRinquin](https://github.com/ArnaudRinquin).
8
12
 
9
13
  ### 0.2.1 (5/15/2013)
10
14
 
@@ -0,0 +1,125 @@
1
+ # Contributing to Ruby-Enum
2
+
3
+ This project is work of [many contributors](https://github.com/dblock/ruby-enum/graphs/contributors).
4
+
5
+ You're encouraged to submit [pull requests](https://github.com/dblock/ruby-enum/pulls), [propose features and discuss issues](https://github.com/dblock/ruby-enum/issues).
6
+
7
+ In the examples below, substitute your Github username for `contributor` in URLs.
8
+
9
+ ### Fork the Project
10
+
11
+ Fork the [project on Github](https://github.com/dblock/ruby-enum) and check out your copy.
12
+
13
+ ```
14
+ git clone https://github.com/contributor/ruby-enum.git
15
+ cd ruby-enum
16
+ git remote add upstream https://github.com/dblock/ruby-enum.git
17
+ ```
18
+
19
+ ### Bundle Install and Test
20
+
21
+ Ensure that you can build the project and run tests.
22
+
23
+ ```
24
+ bundle install
25
+ bundle exec rake
26
+ ```
27
+
28
+ ## Contribute Code
29
+
30
+ ### Create a Topic Branch
31
+
32
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
33
+
34
+ ```
35
+ git checkout master
36
+ git pull upstream master
37
+ git checkout -b my-feature-branch
38
+ ```
39
+
40
+ ### Write Tests
41
+
42
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add tests to [spec](spec).
43
+
44
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
45
+
46
+ ### Write Code
47
+
48
+ Implement your feature or bug fix.
49
+
50
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ingored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.
51
+
52
+ Make sure that `bundle exec rake` completes without errors.
53
+
54
+ ### Write Documentation
55
+
56
+ Document any external behavior in the [README](README.md).
57
+
58
+ ### Update Changelog
59
+
60
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Don't remove *Your contribution here*.
61
+
62
+ Make it look like every other line, including a link to the issue being fixed, your name and link to your Github account.
63
+
64
+ ### Commit Changes
65
+
66
+ Make sure git knows your name and email address:
67
+
68
+ ```
69
+ git config --global user.name "Your Name"
70
+ git config --global user.email "contributor@example.com"
71
+ ```
72
+
73
+ Writing good commit logs is important. A commit log should describe what changed and why.
74
+
75
+ ```
76
+ git add ...
77
+ git commit
78
+ ```
79
+
80
+ ### Push
81
+
82
+ ```
83
+ git push origin my-feature-branch
84
+ ```
85
+
86
+ ### Make a Pull Request
87
+
88
+ Go to https://github.com/contributor/ruby-enum and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
89
+
90
+ ### Update CHANGELOG Again
91
+
92
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
93
+
94
+ ```
95
+ * [#123](https://github.com/dblock/ruby-enum/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
96
+ ```
97
+
98
+ Amend your previous commit and force push the changes.
99
+
100
+ ```
101
+ git commit --amend
102
+ git push origin my-feature-branch -f
103
+ ```
104
+
105
+ ### Rebase
106
+
107
+ If you've been working on a change for a while, rebase with upstream/master.
108
+
109
+ ```
110
+ git fetch upstream
111
+ git rebase upstream/master
112
+ git push origin my-feature-branch -f
113
+ ```
114
+
115
+ ### Check on Your Pull Request
116
+
117
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
118
+
119
+ ### Be Patient
120
+
121
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
122
+
123
+ ## Thank You
124
+
125
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rspec"
6
- gem "rake"
7
- gem "rubocop", "0.21.0"
5
+ gem 'rspec', '~> 3.4.0'
6
+ gem 'rake'
7
+ gem 'rubocop', '0.35.1'
@@ -1,44 +1,53 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-enum (0.4.0)
4
+ ruby-enum (0.5.0)
5
5
  i18n
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- ast (2.0.0)
10
+ ast (2.1.0)
11
+ astrolabe (1.3.1)
12
+ parser (~> 2.2)
11
13
  diff-lcs (1.2.5)
12
- i18n (0.6.9)
13
- json (1.8.1)
14
- parser (2.1.9)
14
+ i18n (0.7.0)
15
+ parser (2.2.3.0)
15
16
  ast (>= 1.1, < 3.0)
16
- slop (~> 3.4, >= 3.4.5)
17
- powerpack (0.0.9)
17
+ powerpack (0.1.1)
18
18
  rainbow (2.0.0)
19
19
  rake (10.3.1)
20
- rspec (2.14.1)
21
- rspec-core (~> 2.14.0)
22
- rspec-expectations (~> 2.14.0)
23
- rspec-mocks (~> 2.14.0)
24
- rspec-core (2.14.8)
25
- rspec-expectations (2.14.5)
26
- diff-lcs (>= 1.1.3, < 2.0)
27
- rspec-mocks (2.14.6)
28
- rubocop (0.21.0)
29
- json (>= 1.7.7, < 2)
30
- parser (~> 2.1.9)
31
- powerpack (~> 0.0.6)
20
+ rspec (3.4.0)
21
+ rspec-core (~> 3.4.0)
22
+ rspec-expectations (~> 3.4.0)
23
+ rspec-mocks (~> 3.4.0)
24
+ rspec-core (3.4.1)
25
+ rspec-support (~> 3.4.0)
26
+ rspec-expectations (3.4.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-mocks (3.4.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-support (3.4.0)
33
+ rubocop (0.35.1)
34
+ astrolabe (~> 1.3)
35
+ parser (>= 2.2.3.0, < 3.0)
36
+ powerpack (~> 0.1)
32
37
  rainbow (>= 1.99.1, < 3.0)
33
- ruby-progressbar (~> 1.4)
34
- ruby-progressbar (1.5.1)
35
- slop (3.5.0)
38
+ ruby-progressbar (~> 1.7)
39
+ tins (<= 1.6.0)
40
+ ruby-progressbar (1.7.5)
41
+ tins (1.6.0)
36
42
 
37
43
  PLATFORMS
38
44
  ruby
39
45
 
40
46
  DEPENDENCIES
41
47
  rake
42
- rspec
43
- rubocop (= 0.21.0)
48
+ rspec (~> 3.4.0)
49
+ rubocop (= 0.35.1)
44
50
  ruby-enum!
51
+
52
+ BUNDLED WITH
53
+ 1.10.6
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2014 Daniel Doubrovkine.
3
+ Copyright (c) 2013-2015 Daniel Doubrovkine.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  Ruby::Enum
2
2
  ==========
3
3
 
4
- [![Build Status](https://travis-ci.org/dblock/ruby-enum.png)](https://travis-ci.org/dblock/ruby-enum)
4
+ [![Gem Version](http://img.shields.io/gem/v/ruby-enum.svg)](http://badge.fury.io/rb/ruby-enum)
5
+ [![Build Status](http://img.shields.io/travis/dblock/ruby-enum.svg)](https://travis-ci.org/dblock/ruby-enum)
6
+ [![Dependency Status](https://gemnasium.com/dblock/ruby-enum.svg)](https://gemnasium.com/dblock/ruby-enum)
7
+ [![Code Climate](https://codeclimate.com/github/dblock/ruby-enum.svg)](https://codeclimate.com/github/dblock/ruby-enum)
5
8
 
6
9
  Enum-like behavior for Ruby, heavily inspired by [this](http://www.rubyfleebie.com/enumerations-and-ruby) and improved upon [another blog post](http://code.dblock.org/how-to-define-enums-in-ruby).
7
10
 
@@ -73,17 +76,61 @@ end
73
76
  # => [ [:GREEN, #<Colors:...>], [:RED, #<Colors:...>] ]
74
77
  ```
75
78
 
76
- ## Contributing
79
+ ### Several hash-like methods are supported.
80
+
81
+ #### Retrieving keys and values
82
+
83
+ ``` ruby
84
+ Colors.keys
85
+ # => [:RED, :GREEN]
86
+
87
+ Colors.values
88
+ # => ["red", "green"]
89
+ ```
77
90
 
78
- You're encouraged to contribute to this gem.
91
+ #### Mapping keys to values
92
+
93
+ ``` ruby
94
+ Colors.key?(:RED)
95
+ # => true
96
+
97
+ Colors.value(:RED)
98
+ # => "red"
99
+
100
+ Colors.key?(:BLUE)
101
+ # => false
102
+
103
+ Colors.value(:BLUE)
104
+ # => nil
105
+ ```
79
106
 
80
- * Fork this project.
81
- * Make changes, write tests.
82
- * Updated [CHANGELOG](CHANGELOG.md).
83
- * Make a pull request, bonus points for topic branches.
107
+ #### Mapping values to keys
108
+
109
+ ``` ruby
110
+ Colors.value?('green')
111
+ # => true
112
+
113
+ Colors.key('green')
114
+ # => :GREEN
115
+
116
+ Colors.value?('yellow')
117
+ # => false
118
+
119
+ Colors.key('yellow')
120
+ # => nil
121
+ ```
122
+
123
+ ## Contributing
124
+
125
+ You're encouraged to contribute to this gem. See [CONTRIBUTING](CONTRIBUTING.md) for details.
84
126
 
85
127
  ## Copyright and License
86
128
 
87
- Copyright (c) 2013-2014, Daniel Doubrovkine and [Contributors](CHANGELOG.md).
129
+ Copyright (c) 2013-2015, Daniel Doubrovkine and [Contributors](CHANGELOG.md).
88
130
 
89
131
  This project is licensed under the [MIT License](LICENSE.md).
132
+
133
+ ## Related Projects
134
+
135
+ * [typesafe_enum](https://github.com/dmolesUC3/typesafe_enum): Typesafe enums, inspired by Java.
136
+ * [renum](https://github.com/duelinmarkers/renum): A readable, but terse enum.
@@ -0,0 +1,67 @@
1
+ # Releasing Ruby-Enum
2
+
3
+ There're no hard rules about when to release ruby-enum. Release bug fixes frequenty, features not so frequently and breaking API changes rarely.
4
+
5
+ ### Release
6
+
7
+ Run tests, check that all tests succeed locally.
8
+
9
+ ```
10
+ bundle install
11
+ rake
12
+ ```
13
+
14
+ Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/ruby-enum) for all supported platforms.
15
+
16
+ Increment the version, modify [lib/ruby-enum/version.rb](lib/ruby-enum/version.rb).
17
+
18
+ * Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.2.1` to `0.2.2`).
19
+ * Increment the second number if the release contains major features or breaking API changes (eg. change `0.2.1` to `0.3.0`).
20
+
21
+ Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
22
+
23
+ ```
24
+ ### 0.2.2 (7/10/2015)
25
+ ```
26
+
27
+ Remove the line with "Your contribution here.", since there will be no more contributions to this release.
28
+
29
+ Commit your changes.
30
+
31
+ ```
32
+ git add README.md CHANGELOG.md lib/ruby-enum/version.rb
33
+ git commit -m "Preparing for release, 0.2.2."
34
+ git push origin master
35
+ ```
36
+
37
+ Release.
38
+
39
+ ```
40
+ $ rake release
41
+
42
+ ruby-enum 0.2.2 built to pkg/ruby-enum-0.2.2.gem.
43
+ Tagged v0.2.2.
44
+ Pushed git commits and tags.
45
+ Pushed ruby-enum 0.2.2 to rubygems.org.
46
+ ```
47
+
48
+ ### Prepare for the Next Version
49
+
50
+ Add the next release to [CHANGELOG.md](CHANGELOG.md).
51
+
52
+ ```
53
+ Next Release
54
+ ============
55
+
56
+ * Your contribution here.
57
+ ```
58
+
59
+ Increment the third version number in [lib/ruby-enum/version.rb](lib/ruby-enum/version.rb).
60
+
61
+ Comit your changes.
62
+
63
+ ```
64
+ git add CHANGELOG.md lib/ruby-enum/version.rb
65
+ git commit -m "Preparing for next development iteration, 0.2.3."
66
+ git push origin master
67
+ ```
data/Rakefile CHANGED
@@ -11,6 +11,6 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
11
11
  end
12
12
 
13
13
  require 'rubocop/rake_task'
14
- Rubocop::RakeTask.new(:rubocop)
14
+ RuboCop::RakeTask.new(:rubocop)
15
15
 
16
16
  task default: [:rubocop, :spec]
@@ -20,14 +20,17 @@ module Ruby
20
20
  # [value] Enumerator value.
21
21
  def define(key, value)
22
22
  @_enum_hash ||= {}
23
- @_enum_hash[key] = new(key, value)
23
+ @_enums_by_value ||= {}
24
+ new_instance = new(key, value)
25
+ @_enum_hash[key] = new_instance
26
+ @_enums_by_value[value] = new_instance
24
27
  end
25
28
 
26
29
  def const_missing(key)
27
30
  if @_enum_hash[key]
28
31
  @_enum_hash[key].value
29
32
  else
30
- fail Ruby::Enum::Errors::UninitializedConstantError.new(name: name, key: key)
33
+ fail Ruby::Enum::Errors::UninitializedConstantError, name: name, key: key
31
34
  end
32
35
  end
33
36
 
@@ -37,20 +40,63 @@ module Ruby
37
40
  @_enum_hash.each(&block)
38
41
  end
39
42
 
40
- # Attempt to parse an enumerated value.
43
+ # Attempt to parse an enum key and return the
44
+ # corresponding value.
41
45
  #
42
46
  # === Parameters
43
- # [s] The string to parse.
47
+ # [k] The key string to parse.
44
48
  #
45
- # Returns an enumerated value or nil.
46
- def parse(s)
47
- s = s.to_s.upcase
49
+ # Returns the corresponding value or nil.
50
+ def parse(k)
51
+ k = k.to_s.upcase
48
52
  each do |key, enum|
49
- return enum.value if key.to_s.upcase == s
53
+ return enum.value if key.to_s.upcase == k
50
54
  end
51
55
  nil
52
56
  end
53
57
 
58
+ # Whether the specified key exists in this enum.
59
+ #
60
+ # === Parameters
61
+ # [k] The string key to check.
62
+ #
63
+ # Returns true if the key exists, false otherwise.
64
+ def key?(k)
65
+ @_enum_hash.key?(k)
66
+ end
67
+
68
+ # Gets the string value for the specified key.
69
+ #
70
+ # === Parameters
71
+ # [k] The key symbol to get the value for.
72
+ #
73
+ # Returns the corresponding enum instance or nil.
74
+ def value(k)
75
+ enum = @_enum_hash[k]
76
+ enum.value if enum
77
+ end
78
+
79
+ # Whether the specified value exists in this enum.
80
+ #
81
+ # === Parameters
82
+ # [k] The string value to check.
83
+ #
84
+ # Returns true if the value exists, false otherwise.
85
+ def value?(v)
86
+ @_enums_by_value.key?(v)
87
+ end
88
+
89
+ # Gets the key symbol for the specified value.
90
+ #
91
+ # === Parameters
92
+ # [v] The string value to parse.
93
+ #
94
+ # Returns the corresponding key symbol or nil.
95
+ def key(v)
96
+ enum = @_enums_by_value[v]
97
+ enum.key if enum
98
+ end
99
+
54
100
  # Returns all enum keys.
55
101
  def keys
56
102
  @_enum_hash.values.map(&:key)
@@ -21,54 +21,54 @@ module Ruby
21
21
  @resolution = create_resolution(key, attributes)
22
22
 
23
23
  "\nProblem:\n #{@problem}"\
24
- "\nSummary:\n #{@summary}" + "\nResolution:\n #{@resolution}"
24
+ "\nSummary:\n #{@summary}" + "\nResolution:\n #{@resolution}"
25
25
  end
26
26
 
27
27
  private
28
28
 
29
29
  BASE_KEY = 'ruby.enum.errors.messages' #:nodoc:
30
30
 
31
- # Given the key of the specific error and the options hash, translate the
32
- # message.
33
- #
34
- # === Parameters
35
- # [key] The key of the error in the locales.
36
- # [options] The objects to pass to create the message.
37
- #
38
- # Returns a localized error message string.
31
+ # Given the key of the specific error and the options hash, translate the
32
+ # message.
33
+ #
34
+ # === Parameters
35
+ # [key] The key of the error in the locales.
36
+ # [options] The objects to pass to create the message.
37
+ #
38
+ # Returns a localized error message string.
39
39
  def translate(key, options)
40
40
  ::I18n.translate("#{BASE_KEY}.#{key}", { locale: :en }.merge(options)).strip
41
41
  end
42
42
 
43
- # Create the problem.
44
- #
45
- # === Parameters
46
- # [key] The error key.
47
- # [attributes] The attributes to interpolate.
48
- #
49
- # Returns the problem.
43
+ # Create the problem.
44
+ #
45
+ # === Parameters
46
+ # [key] The error key.
47
+ # [attributes] The attributes to interpolate.
48
+ #
49
+ # Returns the problem.
50
50
  def create_problem(key, attributes)
51
51
  translate("#{key}.message", attributes)
52
52
  end
53
53
 
54
- # Create the summary.
55
- #
56
- # === Parameters
57
- # [key] The error key.
58
- # [attributes] The attributes to interpolate.
59
- #
60
- # Returns the summary.
54
+ # Create the summary.
55
+ #
56
+ # === Parameters
57
+ # [key] The error key.
58
+ # [attributes] The attributes to interpolate.
59
+ #
60
+ # Returns the summary.
61
61
  def create_summary(key, attributes)
62
62
  translate("#{key}.summary", attributes)
63
63
  end
64
64
 
65
- # Create the resolution.
66
- #
67
- # === Parameters
68
- # [key] The error key.
69
- # [attributes] The attributes to interpolate.
70
- #
71
- # Returns the resolution.
65
+ # Create the resolution.
66
+ #
67
+ # === Parameters
68
+ # [key] The error key.
69
+ # [attributes] The attributes to interpolate.
70
+ #
71
+ # Returns the resolution.
72
72
  def create_resolution(key, attributes)
73
73
  translate("#{key}.resolution", attributes)
74
74
  end
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module Enum
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
Binary file
@@ -9,11 +9,11 @@ end
9
9
 
10
10
  describe Ruby::Enum do
11
11
  it 'returns an enum value' do
12
- Colors::RED.should eq 'red'
13
- Colors::GREEN.should eq 'green'
12
+ expect(Colors::RED).to eq 'red'
13
+ expect(Colors::GREEN).to eq 'green'
14
14
  end
15
15
  it 'raises UninitializedConstantError on an invalid constant' do
16
- expect { Colors::ANYTHING }.to raise_error Ruby::Enum::Errors::UninitializedConstantError
16
+ expect { Colors::ANYTHING }.to raise_error Ruby::Enum::Errors::UninitializedConstantError, /The constant Colors::ANYTHING has not been defined./
17
17
  end
18
18
  context '#each' do
19
19
  it 'iterates over constants' do
@@ -25,9 +25,9 @@ describe Ruby::Enum do
25
25
  enum_keys << enum.key
26
26
  enum_values << enum.value
27
27
  end
28
- keys.should eq [:RED, :GREEN]
29
- enum_keys.should eq [:RED, :GREEN]
30
- enum_values.should eq %w(red green)
28
+ expect(keys).to eq [:RED, :GREEN]
29
+ expect(enum_keys).to eq [:RED, :GREEN]
30
+ expect(enum_values).to eq %w(red green)
31
31
  end
32
32
  end
33
33
  context '#map' do
@@ -35,38 +35,78 @@ describe Ruby::Enum do
35
35
  key_key_values = Colors.map do |key, enum|
36
36
  [key, enum.key, enum.value]
37
37
  end
38
- key_key_values.count.should eq 2
39
- key_key_values[0].should eq [:RED, :RED, 'red']
40
- key_key_values[1].should eq [:GREEN, :GREEN, 'green']
38
+ expect(key_key_values.count).to eq 2
39
+ expect(key_key_values[0]).to eq [:RED, :RED, 'red']
40
+ expect(key_key_values[1]).to eq [:GREEN, :GREEN, 'green']
41
41
  end
42
42
  end
43
43
  context '#parse' do
44
44
  it 'parses exact value' do
45
- Colors.parse('red').should == Colors::RED
45
+ expect(Colors.parse('red')).to eq(Colors::RED)
46
46
  end
47
47
  it 'is case-insensitive' do
48
- Colors.parse('ReD').should == Colors::RED
48
+ expect(Colors.parse('ReD')).to eq(Colors::RED)
49
49
  end
50
50
  it 'returns nil for a null value' do
51
- Colors.parse(nil).should be_nil
51
+ expect(Colors.parse(nil)).to be_nil
52
52
  end
53
53
  it 'returns nil for an invalid value' do
54
- Colors.parse('invalid').should be_nil
54
+ expect(Colors.parse('invalid')).to be_nil
55
+ end
56
+ end
57
+ context '#key?' do
58
+ it 'returns true for valid keys' do
59
+ Colors.keys.each do |key|
60
+ expect(Colors.key?(key)).to eq(true)
61
+ end
62
+ end
63
+ it 'returns false for invalid keys' do
64
+ expect(Colors.key?(:NOT_A_KEY)).to eq(false)
65
+ end
66
+ end
67
+ context '#value' do
68
+ it 'returns string values for keys' do
69
+ Colors.each do |key, enum|
70
+ expect(Colors.value(key)).to eq(enum.value)
71
+ end
72
+ end
73
+ it 'returns nil for an invalid key' do
74
+ expect(Colors.value(:NOT_A_KEY)).to be_nil
75
+ end
76
+ end
77
+ context '#value?' do
78
+ it 'returns true for valid values' do
79
+ Colors.values.each do |value|
80
+ expect(Colors.value?(value)).to eq(true)
81
+ end
82
+ end
83
+ it 'returns false for invalid values' do
84
+ expect(Colors.value?('I am not a value')).to eq(false)
85
+ end
86
+ end
87
+ context '#key' do
88
+ it 'returns enum instances for values' do
89
+ Colors.each do |_, enum|
90
+ expect(Colors.key(enum.value)).to eq(enum.key)
91
+ end
92
+ end
93
+ it 'returns nil for an invalid value' do
94
+ expect(Colors.key('invalid')).to be_nil
55
95
  end
56
96
  end
57
97
  context '#keys' do
58
98
  it 'returns keys' do
59
- Colors.keys.should == [:RED, :GREEN]
99
+ expect(Colors.keys).to eq([:RED, :GREEN])
60
100
  end
61
101
  end
62
102
  context '#values' do
63
103
  it 'returns values' do
64
- Colors.values.should == %w(red green)
104
+ expect(Colors.values).to eq(%w(red green))
65
105
  end
66
106
  end
67
107
  context '#to_h' do
68
108
  it 'returns a hash of key:values' do
69
- Colors.to_h.should == { RED: 'red', GREEN: 'green' }
109
+ expect(Colors.to_h).to eq(RED: 'red', GREEN: 'green')
70
110
  end
71
111
  end
72
112
  end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe Ruby::Enum do
4
4
  it 'has a version' do
5
- Ruby::Enum::VERSION.should_not be_nil
5
+ expect(Ruby::Enum::VERSION).not_to be_nil
6
6
  end
7
7
  end
@@ -3,3 +3,5 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'rubygems'
4
4
  require 'rspec'
5
5
  require 'ruby-enum'
6
+
7
+ RSpec.configure(&:raise_errors_for_deprecations!)
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-29 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description:
@@ -31,19 +31,22 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - CHANGELOG.md
34
+ - CONTRIBUTING.md
34
35
  - Gemfile
35
36
  - Gemfile.lock
37
+ - LICENSE.md
38
+ - README.md
39
+ - RELEASING.md
40
+ - Rakefile
36
41
  - lib/config/locales/en.yml
42
+ - lib/ruby-enum.rb
37
43
  - lib/ruby-enum/enum.rb
38
44
  - lib/ruby-enum/errors/base.rb
39
45
  - lib/ruby-enum/errors/uninitialized_constant_error.rb
40
46
  - lib/ruby-enum/version.rb
41
- - lib/ruby-enum.rb
42
47
  - lib/ruby_enum.rb
43
- - LICENSE.md
44
48
  - pkg/ruby-enum-0.3.0.gem
45
- - Rakefile
46
- - README.md
49
+ - pkg/ruby-enum-0.4.0.gem
47
50
  - ruby-enum.gemspec
48
51
  - spec/ruby-enum/enum_spec.rb
49
52
  - spec/ruby-enum/version_spec.rb
@@ -58,17 +61,17 @@ require_paths:
58
61
  - lib
59
62
  required_ruby_version: !ruby/object:Gem::Requirement
60
63
  requirements:
61
- - - '>='
64
+ - - ">="
62
65
  - !ruby/object:Gem::Version
63
66
  version: '0'
64
67
  required_rubygems_version: !ruby/object:Gem::Requirement
65
68
  requirements:
66
- - - '>='
69
+ - - ">="
67
70
  - !ruby/object:Gem::Version
68
71
  version: 1.3.6
69
72
  requirements: []
70
73
  rubyforge_project:
71
- rubygems_version: 2.0.14
74
+ rubygems_version: 2.4.8
72
75
  signing_key:
73
76
  specification_version: 4
74
77
  summary: Enum-like behavior for Ruby.