mini_enum 0.0.1 → 1.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.
- data/.gitignore +1 -17
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile.lock +26 -0
- data/README.rdoc +1 -0
- data/Rakefile +5 -0
- data/lib/mini_enum.rb +47 -1
- data/lib/mini_enum/version.rb +1 -1
- data/mini_enum.gemspec +2 -1
- data/spec/mini_enum/mini_enum_spec.rb +42 -0
- data/spec/spec_helper.rb +8 -0
- metadata +27 -4
- data/README.md +0 -29
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mini_enum (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rake (10.0.3)
|
11
|
+
rspec (2.12.0)
|
12
|
+
rspec-core (~> 2.12.0)
|
13
|
+
rspec-expectations (~> 2.12.0)
|
14
|
+
rspec-mocks (~> 2.12.0)
|
15
|
+
rspec-core (2.12.2)
|
16
|
+
rspec-expectations (2.12.1)
|
17
|
+
diff-lcs (~> 1.1.3)
|
18
|
+
rspec-mocks (2.12.2)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
mini_enum!
|
25
|
+
rake
|
26
|
+
rspec
|
data/README.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
= Mini Enum {https://travis-ci.org/wallacyyy/mini_enum.png?branch=master} [http://travis-ci.org/wallacyyy/mini_enum]
|
data/Rakefile
CHANGED
data/lib/mini_enum.rb
CHANGED
@@ -1,5 +1,51 @@
|
|
1
1
|
require "mini_enum/version"
|
2
2
|
|
3
3
|
module MiniEnum
|
4
|
-
|
4
|
+
|
5
|
+
def initialize(key, value)
|
6
|
+
@key = key
|
7
|
+
@value = value
|
8
|
+
end
|
9
|
+
|
10
|
+
def key
|
11
|
+
@key
|
12
|
+
end
|
13
|
+
|
14
|
+
def value
|
15
|
+
@value
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(base)
|
19
|
+
base.extend(ClassMethods)
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
def define(key, value)
|
24
|
+
@hash ||= {}
|
25
|
+
@hash[key] = self.new(key, value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def const_missing(key)
|
29
|
+
@hash[key].value
|
30
|
+
end
|
31
|
+
|
32
|
+
def each
|
33
|
+
@hash.each do |key, value|
|
34
|
+
yield key, value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def all
|
39
|
+
@hash.values
|
40
|
+
end
|
41
|
+
|
42
|
+
def all_to_hash
|
43
|
+
hash = {}
|
44
|
+
each do |key, value|
|
45
|
+
hash[key] = value.value
|
46
|
+
end
|
47
|
+
hash
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
5
51
|
end
|
data/lib/mini_enum/version.rb
CHANGED
data/mini_enum.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["leonardowrc@gmail.com"]
|
7
7
|
gem.description = %q{A simple enum implementation for ruby}
|
8
8
|
gem.summary = %q{Enum for ruby}
|
9
|
-
gem.homepage = "
|
9
|
+
gem.homepage = "https://github.com/wallacyyy/mini_enum"
|
10
10
|
gem.files = `git ls-files`.split($\)
|
11
11
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
@@ -15,5 +15,6 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.version = MiniEnum::VERSION
|
16
16
|
|
17
17
|
gem.add_development_dependency "rspec"
|
18
|
+
gem.add_development_dependency "rake"
|
18
19
|
|
19
20
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MiniEnum do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
class Enum
|
7
|
+
include MiniEnum
|
8
|
+
end
|
9
|
+
|
10
|
+
@hash = Hash.new
|
11
|
+
@hash[:KEY] = "value"
|
12
|
+
@hash[:ANOTHER_KEY] = "another_value"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "initialize a enum with a key/value pair" do
|
16
|
+
Enum.define @hash.keys.first, @hash[:KEY]
|
17
|
+
Enum::KEY.should == "value"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "convert all enum values to hash" do
|
21
|
+
Enum.define @hash.keys.first, @hash[:KEY]
|
22
|
+
Enum.all_to_hash.should be_a_kind_of(Hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "iterate through enum pairs" do
|
26
|
+
@hash.each_pair do |key,value|
|
27
|
+
Enum.define key, value
|
28
|
+
end
|
29
|
+
|
30
|
+
Enum.each do |key|
|
31
|
+
@hash.keys.include?key.should be_true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "list all the defined enum values" do
|
36
|
+
@hash.each_pair do |key,value|
|
37
|
+
Enum.define key, value
|
38
|
+
end
|
39
|
+
Enum.all_to_hash.should include(:KEY => "value", :ANOTHER_KEY => "another_value")
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1.0'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: A simple enum implementation for ruby
|
31
47
|
email:
|
32
48
|
- leonardowrc@gmail.com
|
@@ -35,14 +51,19 @@ extensions: []
|
|
35
51
|
extra_rdoc_files: []
|
36
52
|
files:
|
37
53
|
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- .travis.yml
|
38
56
|
- Gemfile
|
57
|
+
- Gemfile.lock
|
39
58
|
- LICENSE
|
40
|
-
- README.
|
59
|
+
- README.rdoc
|
41
60
|
- Rakefile
|
42
61
|
- lib/mini_enum.rb
|
43
62
|
- lib/mini_enum/version.rb
|
44
63
|
- mini_enum.gemspec
|
45
|
-
|
64
|
+
- spec/mini_enum/mini_enum_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/wallacyyy/mini_enum
|
46
67
|
licenses: []
|
47
68
|
post_install_message:
|
48
69
|
rdoc_options: []
|
@@ -66,4 +87,6 @@ rubygems_version: 1.8.24
|
|
66
87
|
signing_key:
|
67
88
|
specification_version: 3
|
68
89
|
summary: Enum for ruby
|
69
|
-
test_files:
|
90
|
+
test_files:
|
91
|
+
- spec/mini_enum/mini_enum_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
data/README.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# MiniEnum
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'mini_enum'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install mini_enum
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|