enumeration 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,19 @@
1
- pkg/*
2
- .bundle
3
1
  *.gem
4
- *.log
2
+ *.log
3
+ *.rbc
4
+ .rbx/
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rake', '~>0.9.2'
5
+ gem 'rake', "~> 10.4.0"
6
+ gem 'pry', "~> 0.9.0"
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011-Present Kelly Redding and Collin Redding
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # Enumeration
2
+
3
+ Add enumerated value attributes to your ruby classes.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ require 'enumeration'
9
+
10
+ class Thing
11
+ include Enumeration
12
+
13
+ # list enumeration
14
+ enum :word, %w{aye bee see}
15
+
16
+ # map enumeration
17
+ enum :stuff, {
18
+ :a => "aye",
19
+ :b => "bee",
20
+ :c => "see"
21
+ }
22
+ end
23
+
24
+ # get the enum sets
25
+ Thing.word_set # => ['aye', 'bee', 'see']
26
+ Thing.stuff_set # => [:a, :b, :c]
27
+
28
+ # lookup mapped enum values
29
+ Thing.stuff(:a) # => "aye"
30
+
31
+
32
+ t = Thing.new
33
+
34
+ # write list enum values
35
+ t.word # => nil
36
+ t.word = "aye"
37
+ t.word # => "aye"
38
+ t.word_key # => "aye" (a list's 'keys' are it's values, vice-versa)
39
+ t.word = "dee"
40
+ t.word # => nil (won't write non enum values)
41
+ t.word_key # => nil
42
+
43
+ # write mapped enum value
44
+ t.stuff # => nil
45
+ t.stuff = :b # (write using key)
46
+ t.stuff # => "bee"
47
+ t.stuff_key # => :b
48
+ t.stuff = "see" # (write using value)
49
+ t.stuff # => "see"
50
+ t.stuff_key # => :c
51
+ t.stuff = :d
52
+ t.stuff # => nil (won't write non enum keys)
53
+ t.stuff_key # => nil
54
+ t.stuff = "dee"
55
+ t.stuff # => nil (won't write non enum values)
56
+ t.stuff_key # => nil
57
+ ```
58
+
59
+ ## Installation
60
+
61
+ Add this line to your application's Gemfile:
62
+
63
+ gem 'enumeration'
64
+
65
+ And then execute:
66
+
67
+ $ bundle
68
+
69
+ Or install it yourself as:
70
+
71
+ $ gem install enumeration
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,7 +1 @@
1
- require 'assert/rake_tasks'
2
- include Assert::RakeTasks
3
-
4
- require 'bundler'
5
- Bundler::GemHelper.install_tasks
6
-
7
- task :default => :build
1
+ require "bundler/gem_tasks"
@@ -1,22 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require "enumeration/version"
4
5
 
5
- Gem::Specification.new do |s|
6
- s.name = "enumeration"
7
- s.version = Enumeration::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Kelly D. Redding"]
10
- s.email = ["kelly@kelredd.com"]
11
- s.homepage = "http://github.com/kelredd/enumeration"
12
- s.summary = %q{add enumerated value attributes to your ruby classes}
13
- s.description = %q{add enumerated value attributes to your ruby classes}
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "enumeration"
8
+ gem.version = Enumeration::VERSION
9
+ gem.authors = ["Kelly Redding", "Collin Redding"]
10
+ gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
11
+ gem.description = %q{Add enumerated value attributes to your ruby classes.}
12
+ gem.summary = %q{Add enumerated value attributes to your ruby classes.}
13
+ gem.homepage = "http://github.com/redding/enumeration"
14
+ gem.license = 'MIT'
14
15
 
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency("assert", ["~> 2.13"])
19
22
 
20
- s.add_development_dependency("bundler", ["~> 1.0"])
21
- s.add_development_dependency("assert", ["~> 0.7"])
22
23
  end
@@ -1,4 +1,4 @@
1
- module Enumeration; end
1
+ require 'enumeration/version'
2
2
  require 'enumeration/collection'
3
3
 
4
4
  module Enumeration
@@ -1,55 +1,58 @@
1
- module Enumeration; end
2
- module Enumeration::AssertMacros
1
+ module Enumeration
3
2
 
4
- # a set of Assert macros to help write enum definition and
5
- # regression tests in Assert (https://github.com/teaminsight/assert)
3
+ module AssertMacros
6
4
 
7
- def self.included(receiver)
8
- receiver.class_eval do
9
- extend MacroMethods
10
- end
11
- end
5
+ # a set of Assert macros to help write enum definition and
6
+ # regression tests in Assert (https://github.com/teaminsight/assert)
12
7
 
13
- module MacroMethods
14
-
15
- def have_enum(name, *args)
16
- values = [*args].flatten
17
- type = nil
18
- if values.first.kind_of?(::Hash)
19
- values = values.first
20
- type = 'map'
21
- elsif !values.empty?
22
- type = 'list'
8
+ def self.included(receiver)
9
+ receiver.class_eval do
10
+ extend MacroMethods
23
11
  end
12
+ end
24
13
 
25
- called_from = caller.first
26
- macro_name = "have the"
27
- macro_name += " #{type}" if type
28
- macro_name += " enum '#{name}'"
29
- macro_name += " with #{values.inspect} values" if !values.empty?
14
+ module MacroMethods
30
15
 
31
- Assert::Macro.new(macro_name) do
32
- should have_accessor name, [called_from]
16
+ def have_enum(name, *args)
17
+ values = [*args].flatten
18
+ type = nil
19
+ if values.first.kind_of?(::Hash)
20
+ values = values.first
21
+ type = 'map'
22
+ elsif !values.empty?
23
+ type = 'list'
24
+ end
33
25
 
34
- should have_class_method "#{name}_collection", [called_from]
26
+ called_from = caller.first
27
+ macro_name = "have the"
28
+ macro_name += " #{type}" if type
29
+ macro_name += " enum '#{name}'"
30
+ macro_name += " with #{values.inspect} values" if !values.empty?
35
31
 
36
- if type == 'map'
37
- should have_class_method name, [called_from]
38
- end
32
+ Assert::Macro.new(macro_name) do
33
+ should have_accessor name, [called_from]
39
34
 
40
- if !values.empty?
41
- should "know its '#{name}' enum values", called_from do
42
- assert_equal values, subject.class.send("#{name}_collection")
43
- end
35
+ should have_class_method "#{name}_collection", [called_from]
44
36
 
45
37
  if type == 'map'
46
- should "map the '#{name}' enum values at the class level", called_from do
47
- values.each {|k,v| assert_equal v, subject.class.send(name, k)}
38
+ should have_class_method name, [called_from]
39
+ end
40
+
41
+ if !values.empty?
42
+ should "know its '#{name}' enum values", called_from do
43
+ assert_equal values, subject.class.send("#{name}_collection")
44
+ end
45
+
46
+ if type == 'map'
47
+ should "map the '#{name}' enum values at the class level", called_from do
48
+ values.each {|k,v| assert_equal v, subject.class.send(name, k)}
49
+ end
48
50
  end
49
51
  end
50
- end
51
52
 
53
+ end
52
54
  end
55
+
53
56
  end
54
57
 
55
58
  end
@@ -1,49 +1,52 @@
1
- module Enumeration; end
2
- class Enumeration::Collection
1
+ module Enumeration
3
2
 
4
- attr_reader :data
3
+ class Collection
5
4
 
6
- def initialize(map_or_list)
7
- unless map_or_list.kind_of?(::Hash) || map_or_list.kind_of?(::Array)
8
- raise ArgumentError, "please specify the enum collection as a Hash or Array"
5
+ attr_reader :data
6
+
7
+ def initialize(map_or_list)
8
+ unless map_or_list.kind_of?(::Hash) || map_or_list.kind_of?(::Array)
9
+ raise ArgumentError, "please specify the enum collection as a Hash or Array"
10
+ end
11
+ @data = map_or_list
9
12
  end
10
- @data = map_or_list
11
- end
12
13
 
13
- # lookup collection value by a key
14
- def [](key)
15
- if self.map? && @data.has_key?(key)
16
- @data[key]
17
- elsif (self.map? && @data.has_value?(key)) ||
18
- (self.list? && @data.include?(key))
19
- key
20
- else
21
- nil
14
+ # lookup collection value by a key
15
+ def [](key)
16
+ if self.map? && @data.has_key?(key)
17
+ @data[key]
18
+ elsif (self.map? && @data.has_value?(key)) ||
19
+ (self.list? && @data.include?(key))
20
+ key
21
+ else
22
+ nil
23
+ end
22
24
  end
23
- end
24
25
 
25
- # lookup collection key by a value
26
- def key(value)
27
- if self.map? && @data.has_value?(value)
28
- @data.invert[value]
29
- elsif (self.map? && @data.has_key?(value)) ||
30
- (self.list? && @data.include?(value))
31
- value
32
- else
33
- nil
26
+ # lookup collection key by a value
27
+ def key(value)
28
+ if self.map? && @data.has_value?(value)
29
+ @data.invert[value]
30
+ elsif (self.map? && @data.has_key?(value)) ||
31
+ (self.list? && @data.include?(value))
32
+ value
33
+ else
34
+ nil
35
+ end
34
36
  end
35
- end
36
37
 
37
- def list?
38
- @data.kind_of?(::Array)
39
- end
38
+ def list?
39
+ @data.kind_of?(::Array)
40
+ end
40
41
 
41
- def map?
42
- @data.kind_of?(::Hash)
43
- end
42
+ def map?
43
+ @data.kind_of?(::Hash)
44
+ end
45
+
46
+ def set
47
+ self.map? ? @data.keys : @data
48
+ end
44
49
 
45
- def set
46
- self.map? ? @data.keys : @data
47
50
  end
48
51
 
49
52
  end
@@ -1,3 +1,3 @@
1
1
  module Enumeration
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -1,7 +1,10 @@
1
- # this file is automatically required in when you require 'assert'
2
- # put test helpers here
1
+ # this file is automatically required when you run `assert`
2
+ # put any test helpers here
3
3
 
4
- # add root dir to the load path
4
+ # add the root dir to the load path
5
5
  $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
6
6
 
7
- require 'test/thing'
7
+ # require pry for debugging (`binding.pry`)
8
+ require 'pry'
9
+
10
+ require 'test/support/factory'
@@ -0,0 +1,6 @@
1
+ require 'assert/factory'
2
+
3
+ module Factory
4
+ extend Assert::Factory
5
+
6
+ end
@@ -1,25 +1,27 @@
1
1
  require 'assert'
2
-
3
- require 'enumeration'
4
2
  require 'enumeration/assert_macros'
5
3
 
6
4
  module Enumeration::AssertMacros
7
5
 
8
- class BaseTests < Assert::Context
9
- desc "Enumeration::AssertMacros"
6
+ class UnitTests < Assert::Context
10
7
  include Enumeration::AssertMacros
11
8
 
12
- before do
13
- Thing.send :include, Enumeration
14
- Thing.send(:enum, :list, %w{aye bee see})
15
- Thing.send(:enum, :map, {
16
- :a => "aye",
17
- :b => "bee",
18
- :c => "see"
19
- })
20
- @a_thing = Thing.new
9
+ desc "Enumeration::AssertMacros"
10
+ setup do
11
+ @enum_class = Class.new do
12
+ include Enumeration
13
+
14
+ enum :list, %w{aye bee see}
15
+
16
+ enum :map, {
17
+ :a => "aye",
18
+ :b => "bee",
19
+ :c => "see"
20
+ }
21
+ end
22
+ @enum = @enum_class.new
21
23
  end
22
- subject { @a_thing }
24
+ subject{ @enum }
23
25
 
24
26
  should have_enum :list
25
27
  should have_enum :list, ['aye', 'bee', 'see']
@@ -0,0 +1,100 @@
1
+ require "assert"
2
+ require "enumeration/collection"
3
+
4
+ class Enumeration::Collection
5
+
6
+ class UnitTests < Assert::Context
7
+ desc "Enumeration::Collection"
8
+ setup do
9
+ @collection = Enumeration::Collection.new([])
10
+ end
11
+ subject{ @collection }
12
+
13
+ should have_readers :data
14
+ should have_imeths :[], :key, :list?, :map?, :set
15
+
16
+ should "only be created from Arrays or Hashes" do
17
+ assert_raises ArgumentError do
18
+ Enumeration::Collection.new(Factory.string)
19
+ end
20
+ assert_nothing_raised do
21
+ Enumeration::Collection.new([])
22
+ Enumeration::Collection.new({})
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ class ListCollectionTests < UnitTests
29
+ desc "for a list"
30
+ setup do
31
+ @list = ['one', 'two', 'three']
32
+ @collection = Enumeration::Collection.new(@list)
33
+ end
34
+
35
+ should "be a list" do
36
+ assert_true subject.list?
37
+ assert_false subject.map?
38
+ end
39
+
40
+ should "know its data" do
41
+ assert_equal @list, subject.data
42
+ end
43
+
44
+ should "know its set" do
45
+ assert_equal @list, subject.set
46
+ end
47
+
48
+ should "lookup value by key" do
49
+ assert_equal 'two', subject['two']
50
+ end
51
+
52
+ should "lookup key by value" do
53
+ assert_equal 'three', subject.key('three')
54
+ end
55
+
56
+ end
57
+
58
+ class MapCollectionTests < UnitTests
59
+ desc "for a map"
60
+ setup do
61
+ @map = {
62
+ :one => 1,
63
+ :two => 2,
64
+ :three => 3
65
+ }
66
+ @collection = Enumeration::Collection.new(@map)
67
+ end
68
+
69
+ should "be a map" do
70
+ assert_true subject.map?
71
+ assert_false subject.list?
72
+ end
73
+
74
+ should "know its data" do
75
+ assert_equal(@map, subject.data)
76
+ end
77
+
78
+ should "know it's set" do
79
+ @map.keys.each{ |k| assert subject.set.include?(k) }
80
+ end
81
+
82
+ should "lookup value by key" do
83
+ assert_equal 2, subject[:two]
84
+ end
85
+
86
+ should "lookup value by value" do
87
+ assert_equal 2, subject[2]
88
+ end
89
+
90
+ should "lookup key by value" do
91
+ assert_equal :two, subject.key(2)
92
+ end
93
+
94
+ should "lookup key by key" do
95
+ assert_equal :two, subject.key(:two)
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,117 @@
1
+ require "assert"
2
+ require 'enumeration'
3
+
4
+ module Enumeration
5
+
6
+ class UnitTests < Assert::Context
7
+ desc "Enumeration"
8
+ setup do
9
+ @enum_class = Class.new{ include Enumeration }
10
+ @enum = @enum_class.new
11
+ end
12
+ subject{ @enum }
13
+
14
+ should have_class_method :enum
15
+
16
+ end
17
+
18
+ class ListEnumTests < UnitTests
19
+ desc "for a list"
20
+ setup do
21
+ @enum_class.send(:enum, :word, %w{aye bee see})
22
+ end
23
+
24
+ should have_cmeths :word_set, :word_collection
25
+ should have_accessor :word
26
+
27
+ should "not have a class level lookup method" do
28
+ assert_raises NoMethodError do
29
+ @enum_class.word
30
+ end
31
+ end
32
+
33
+ should "provide class level access to the enum list" do
34
+ words = @enum_class.word_set
35
+ assert_kind_of ::Array, words
36
+ assert_equal 3, words.size
37
+ assert_equal ['aye', 'bee', 'see'], words
38
+ assert_equal words, @enum_class.word_collection
39
+ end
40
+
41
+ should "write a value and read the value" do
42
+ subject.word = "see"
43
+ assert_equal "see", subject.word
44
+ assert_equal "see", subject.word_key
45
+ end
46
+
47
+ should "write nil for values that aren't in the enum" do
48
+ subject.word = Factory.string
49
+ assert_equal nil, subject.word
50
+ assert_equal nil, subject.word_key
51
+ end
52
+
53
+ end
54
+
55
+ class MapEnumTests < UnitTests
56
+ desc "for a map"
57
+ setup do
58
+ @enum_class.send(:enum, :stuff, {
59
+ :a => "aye",
60
+ :b => "bee",
61
+ :c => "see"
62
+ })
63
+ end
64
+
65
+ should have_cmeths :stuff, :stuff_set, :stuff_collection
66
+ should have_accessor :stuff
67
+
68
+ should "provide class level lookup of the enum" do
69
+ assert_equal "aye", @enum_class.stuff(:a)
70
+ end
71
+
72
+ should "provide class level access to the enum set" do
73
+ stuffs = @enum_class.stuff_set
74
+ assert_kind_of ::Array, stuffs
75
+ assert_equal 3, stuffs.size
76
+ [:a, :b, :c].each{ |s| assert @enum_class.stuff_set.include?(s) }
77
+
78
+ exp = {
79
+ :a => 'aye',
80
+ :b => 'bee',
81
+ :c => 'see'
82
+ }
83
+ assert_equal exp, @enum_class.stuff_collection
84
+ end
85
+
86
+ should "write a key and read the value and key" do
87
+ subject.stuff = :b
88
+ assert_equal "bee", subject.stuff
89
+ assert_equal :b, subject.stuff_key
90
+ end
91
+
92
+ should "write a value and read the value" do
93
+ subject.stuff = "see"
94
+ assert_equal "see", subject.stuff
95
+ assert_equal :c, subject.stuff_key
96
+ end
97
+
98
+ should "not read keys like you would values" do
99
+ subject.stuff = :c
100
+ assert_not_equal :c, subject.stuff
101
+ end
102
+
103
+ should "write nil for keys that aren't in the enum" do
104
+ subject.stuff = Factory.string.to_sym
105
+ assert_equal nil, subject.stuff
106
+ assert_equal nil, subject.stuff_key
107
+ end
108
+
109
+ should "write nil for values that aren't in the enum" do
110
+ subject.stuff = Factory.string
111
+ assert_equal nil, subject.stuff
112
+ assert_equal nil, subject.stuff_key
113
+ end
114
+
115
+ end
116
+
117
+ end
metadata CHANGED
@@ -1,55 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumeration
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 1
10
- version: 1.3.1
9
+ - 2
10
+ version: 1.3.2
11
11
  platform: ruby
12
12
  authors:
13
- - Kelly D. Redding
13
+ - Kelly Redding
14
+ - Collin Redding
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2012-01-10 00:00:00 Z
19
+ date: 2015-02-28 00:00:00 Z
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- type: :development
22
- prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
26
25
  - - ~>
27
26
  - !ruby/object:Gem::Version
28
- hash: 15
27
+ hash: 25
29
28
  segments:
30
- - 1
31
- - 0
32
- version: "1.0"
33
- version_requirements: *id001
34
- name: bundler
35
- - !ruby/object:Gem::Dependency
29
+ - 2
30
+ - 13
31
+ version: "2.13"
36
32
  type: :development
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 5
44
- segments:
45
- - 0
46
- - 7
47
- version: "0.7"
48
- version_requirements: *id002
49
33
  name: assert
50
- description: add enumerated value attributes to your ruby classes
34
+ version_requirements: *id001
35
+ prerelease: false
36
+ description: Add enumerated value attributes to your ruby classes.
51
37
  email:
52
- - kelly@kelredd.com
38
+ - kelly@kellyredding.com
39
+ - collin.redding@me.com
53
40
  executables: []
54
41
 
55
42
  extensions: []
@@ -59,25 +46,22 @@ extra_rdoc_files: []
59
46
  files:
60
47
  - .gitignore
61
48
  - Gemfile
62
- - Gemfile.lock
63
- - README.rdoc
49
+ - LICENSE.txt
50
+ - README.md
64
51
  - Rakefile
65
52
  - enumeration.gemspec
66
53
  - lib/enumeration.rb
67
54
  - lib/enumeration/assert_macros.rb
68
55
  - lib/enumeration/collection.rb
69
56
  - lib/enumeration/version.rb
70
- - test/api_test.rb
71
- - test/assert_macros_test.rb
72
- - test/collection_test.rb
73
57
  - test/helper.rb
74
- - test/irb.rb
75
- - test/list_enum_test.rb
76
- - test/map_enum_test.rb
77
- - test/thing.rb
78
- homepage: http://github.com/kelredd/enumeration
79
- licenses: []
80
-
58
+ - test/support/factory.rb
59
+ - test/unit/assert_macros_tests.rb
60
+ - test/unit/collection_tests.rb
61
+ - test/unit/enumeration_tests.rb
62
+ homepage: http://github.com/redding/enumeration
63
+ licenses:
64
+ - MIT
81
65
  post_install_message:
82
66
  rdoc_options: []
83
67
 
@@ -104,16 +88,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
88
  requirements: []
105
89
 
106
90
  rubyforge_project:
107
- rubygems_version: 1.8.11
91
+ rubygems_version: 1.8.29
108
92
  signing_key:
109
93
  specification_version: 3
110
- summary: add enumerated value attributes to your ruby classes
94
+ summary: Add enumerated value attributes to your ruby classes.
111
95
  test_files:
112
- - test/api_test.rb
113
- - test/assert_macros_test.rb
114
- - test/collection_test.rb
115
96
  - test/helper.rb
116
- - test/irb.rb
117
- - test/list_enum_test.rb
118
- - test/map_enum_test.rb
119
- - test/thing.rb
97
+ - test/support/factory.rb
98
+ - test/unit/assert_macros_tests.rb
99
+ - test/unit/collection_tests.rb
100
+ - test/unit/enumeration_tests.rb
@@ -1,25 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- enumeration (1.3.1)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- ansi (1.4.1)
10
- assert (0.7.3)
11
- assert-view (~> 0.5)
12
- assert-view (0.5.0)
13
- ansi (~> 1.3)
14
- undies (~> 2.0)
15
- rake (0.9.2)
16
- undies (2.0.0)
17
-
18
- PLATFORMS
19
- ruby
20
-
21
- DEPENDENCIES
22
- assert (~> 0.7)
23
- bundler (~> 1.0)
24
- enumeration!
25
- rake (~> 0.9.2)
@@ -1,86 +0,0 @@
1
- = Enumeration
2
-
3
- == Description
4
-
5
- add enumerated value attributes to your ruby classes
6
-
7
- == Installation
8
-
9
- gem install enumeration
10
-
11
- == Basic Example and Usage
12
-
13
- require 'enumeration'
14
-
15
- class Thing
16
- include Enumeration
17
-
18
- # list enumeration
19
- enum :word, %w{aye bee see}
20
-
21
- # map enumeration
22
- enum :stuff, {
23
- :a => "aye",
24
- :b => "bee",
25
- :c => "see"
26
- }
27
- end
28
-
29
- # get the enum sets
30
- Thing.word_set # => ['aye', 'bee', 'see']
31
- Thing.stuff_set # => [:a, :b, :c]
32
-
33
- # lookup mapped enum values
34
- Thing.stuff(:a) # => "aye"
35
-
36
-
37
- t = Thing.new
38
-
39
- # write list enum values
40
- t.word # => nil
41
- t.word = "aye"
42
- t.word # => "aye"
43
- t.word_key # => "aye" (a list's 'keys' are it's values, vice-versa)
44
- t.word = "dee"
45
- t.word # => nil (won't write non enum values)
46
- t.word_key # => nil
47
-
48
- # write mapped enum value
49
- t.stuff # => nil
50
- t.stuff = :b # (write using key)
51
- t.stuff # => "bee"
52
- t.stuff_key # => :b
53
- t.stuff = "see" # (write using value)
54
- t.stuff # => "see"
55
- t.stuff_key # => :c
56
- t.stuff = :d
57
- t.stuff # => nil (won't write non enum keys)
58
- t.stuff_key # => nil
59
- t.stuff = "dee"
60
- t.stuff # => nil (won't write non enum values)
61
- t.stuff_key # => nil
62
-
63
- == License
64
-
65
- Copyright (c) 2011 Kelly D. Redding
66
-
67
- Permission is hereby granted, free of charge, to any person
68
- obtaining a copy of this software and associated documentation
69
- files (the "Software"), to deal in the Software without
70
- restriction, including without limitation the rights to use,
71
- copy, modify, merge, publish, distribute, sublicense, and/or sell
72
- copies of the Software, and to permit persons to whom the
73
- Software is furnished to do so, subject to the following
74
- conditions:
75
-
76
- The above copyright notice and this permission notice shall be
77
- included in all copies or substantial portions of the Software.
78
-
79
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
80
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
81
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
82
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
83
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
84
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
85
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
86
- OTHER DEALINGS IN THE SOFTWARE.
@@ -1,15 +0,0 @@
1
- require "assert"
2
-
3
- require 'enumeration'
4
-
5
- class APITest < Assert::Context
6
- desc "Enumeration mixin"
7
-
8
- subject { Thing.new }
9
- before do
10
- Thing.send :include, Enumeration
11
- end
12
-
13
- should have_class_method :enum
14
-
15
- end
@@ -1,84 +0,0 @@
1
- require "assert"
2
-
3
- require "enumeration/collection"
4
-
5
- class CollectionAPITest < Assert::Context
6
- desc "Enumeration collection"
7
- subject { Enumeration::Collection.new([]) }
8
-
9
- should have_reader :data
10
- should have_instance_methods :set, :map?, :list?, :[]
11
-
12
- should "only be created from Arrays or Hashes" do
13
- assert_raises ArgumentError do
14
- Enumeration::Collection.new('stuff')
15
- end
16
- assert_nothing_raised do
17
- Enumeration::Collection.new([])
18
- Enumeration::Collection.new({})
19
- end
20
- end
21
-
22
- end
23
-
24
- class ListCollectionTest < Assert::Context
25
- desc "List collection"
26
- subject { Enumeration::Collection.new(['one', 'two', 'three']) }
27
-
28
- should "be a list" do
29
- assert_equal true, subject.list?
30
- assert_equal false, subject.map?
31
- end
32
-
33
- should "know it's data" do
34
- assert_equal ['one', 'two', 'three'], subject.data
35
- end
36
-
37
- should "know it's set" do
38
- assert_equal ['one', 'two', 'three'], subject.set
39
- end
40
-
41
- should "lookup value by key" do
42
- assert_equal 'two', subject['two']
43
- end
44
-
45
- should "lookup key by value" do
46
- assert_equal 'three', subject.key('three')
47
- end
48
-
49
- end
50
-
51
- class MapCollectionTest < Assert::Context
52
- desc "Map collection"
53
- subject { Enumeration::Collection.new({ :one => 1, :two => 2, :three => 3}) }
54
-
55
- should "be a map" do
56
- assert_equal true, subject.map?
57
- assert_equal false, subject.list?
58
- end
59
-
60
- should "know it's data" do
61
- assert_equal({:one=>1,:two=>2,:three=>3}, subject.data)
62
- end
63
-
64
- should "know it's set" do
65
- [:one, :two, :three].each{|n| assert subject.set.include?(n)}
66
- end
67
-
68
- should "lookup value by key" do
69
- assert_equal 2, subject[:two]
70
- end
71
-
72
- should "lookup value by value" do
73
- assert_equal 2, subject[2]
74
- end
75
-
76
- should "lookup key by value" do
77
- assert_equal :two, subject.key(2)
78
- end
79
-
80
- should "lookup key by key" do
81
- assert_equal :two, subject.key(:two)
82
- end
83
-
84
- end
@@ -1,10 +0,0 @@
1
- require 'assert/setup'
2
-
3
- # this file is required in when the 'irb' rake test is run.
4
- # b/c 'assert' is required above, the test helper will be
5
- # required in.
6
-
7
- # put any IRB setup code here
8
-
9
- require 'enumeration'
10
-
@@ -1,51 +0,0 @@
1
- require "assert"
2
-
3
- require 'enumeration'
4
-
5
- class ListEnumTest < Assert::Context
6
- desc "instance"
7
-
8
- subject { @a_thing }
9
- before do
10
- Thing.send :include, Enumeration
11
- Thing.send(:enum, :word, %w{aye bee see})
12
- @a_thing = Thing.new
13
- end
14
-
15
- should have_class_methods :word_set, :word_collection
16
- should have_accessor :word
17
-
18
- should "not have a class level lookup method" do
19
- assert_raises NoMethodError do
20
- Thing.word
21
- end
22
- end
23
-
24
- should "provide class level access to the enum set" do
25
- words = Thing.word_set
26
- assert words
27
- assert_kind_of ::Array, words
28
- assert !words.empty?
29
- assert_equal 3, words.size
30
- assert_equal ['aye', 'bee', 'see'], Thing.word_set
31
- assert_equal Thing.word_set, Thing.word_collection
32
- end
33
-
34
- should "write a value and read the value" do
35
- subject.word = "see"
36
- assert_equal "see", subject.word
37
- end
38
-
39
- should "write a value and read the key" do
40
- subject.word = "see"
41
- assert_equal "see", subject.word_key
42
- end
43
-
44
- should "write nil for values that aren't in the enum" do
45
- subject.word = "bady-bad"
46
- assert_equal nil, subject.word
47
- assert_equal nil, subject.word_key
48
- end
49
-
50
- end
51
-
@@ -1,65 +0,0 @@
1
- require "assert"
2
-
3
- require 'enumeration'
4
-
5
- class MapEnumTest < Assert::Context
6
- desc "instance"
7
-
8
- subject { @a_thing }
9
- before do
10
- Thing.send :include, Enumeration
11
- Thing.send(:enum, :stuff, {
12
- :a => "aye",
13
- :b => "bee",
14
- :c => "see"
15
- })
16
- @a_thing = Thing.new
17
- end
18
-
19
- should have_class_methods :stuff, :stuff_set, :stuff_collection
20
- should have_accessor :stuff
21
-
22
- should "provide class level access to the enum set" do
23
- stuffs = Thing.stuff_set
24
- assert stuffs
25
- assert_kind_of ::Array, stuffs
26
- assert !stuffs.empty?
27
- assert_equal 3, stuffs.size
28
- [:a, :b, :c].each{|t| assert Thing.stuff_set.include?(t)}
29
- assert_equal({:a=>'aye',:b=>'bee',:c=>'see'}, Thing.stuff_collection)
30
- end
31
-
32
- should "provide class level lookup of the enum" do
33
- assert_equal "aye", Thing.stuff(:a)
34
- end
35
-
36
- should "write a key and read the value and key" do
37
- subject.stuff = :b
38
- assert_equal "bee", subject.stuff
39
- assert_equal :b, subject.stuff_key
40
- end
41
-
42
- should "write a value and read the value" do
43
- subject.stuff = "see"
44
- assert_equal "see", subject.stuff
45
- assert_equal :c, subject.stuff_key
46
- end
47
-
48
- should "not read keys like you would values" do
49
- subject.stuff = :c
50
- assert_not_equal :c, subject.stuff
51
- end
52
-
53
- should "write nil for keys that aren't in the enum" do
54
- subject.stuff = :bad
55
- assert_equal nil, subject.stuff
56
- assert_equal nil, subject.stuff_key
57
- end
58
-
59
- should "write nil for values that aren't in the enum" do
60
- subject.stuff = "bady-bad"
61
- assert_equal nil, subject.stuff
62
- assert_equal nil, subject.stuff_key
63
- end
64
-
65
- end
@@ -1,3 +0,0 @@
1
- class Thing
2
- attr_accessor :one, :two, :three
3
- end