enumlogic 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +4 -4
- data/enumlogic.gemspec +1 -1
- data/lib/enumlogic.rb +5 -2
- data/spec/enumlogic_spec.rb +2 -2
- metadata +17 -5
- checksums.yaml +0 -15
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 2.0.0 release 2013-05-13
|
2
|
+
|
3
|
+
* Reversed the namespace order: enum :car, ['truck', 'suv'] will now be car_truck? instead of truck_car?
|
4
|
+
* Namespacing is now enabled by default, turn it off with enum :car, ['truck', 'suv'], :namespace => false
|
5
|
+
|
1
6
|
== 1.0.1 relased 2009-09-01
|
2
7
|
|
3
8
|
* Allow nils
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
enumlogic (
|
4
|
+
enumlogic (2.0.0)
|
5
5
|
activesupport (>= 2.3.0)
|
6
6
|
|
7
7
|
GEM
|
8
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
activemodel (3.2.13)
|
11
11
|
activesupport (= 3.2.13)
|
@@ -21,8 +21,8 @@ GEM
|
|
21
21
|
arel (3.0.2)
|
22
22
|
builder (3.0.4)
|
23
23
|
i18n (0.6.1)
|
24
|
-
multi_json (1.7.
|
25
|
-
rake (10.0.
|
24
|
+
multi_json (1.7.3)
|
25
|
+
rake (10.0.4)
|
26
26
|
rspec (1.3.2)
|
27
27
|
sqlite3 (1.3.7)
|
28
28
|
tzinfo (0.3.37)
|
data/enumlogic.gemspec
CHANGED
data/lib/enumlogic.rb
CHANGED
@@ -6,6 +6,7 @@ module Enumlogic
|
|
6
6
|
#
|
7
7
|
# class Computer < ActiveRecord::Base
|
8
8
|
# enum :kind, ["apple", "dell", "hp"]
|
9
|
+
# # or....
|
9
10
|
# enum :kind, {"apple" => "Apple", "dell" => "Dell", "hp" => "HP"}
|
10
11
|
# end
|
11
12
|
#
|
@@ -16,11 +17,13 @@ module Enumlogic
|
|
16
17
|
# Computer.new(:kind => "unknown").valid? # false, automatically validates inclusion of the enum field
|
17
18
|
#
|
18
19
|
# c = Computer.new(:kind => "apple")
|
19
|
-
# c.
|
20
|
+
# c.kind_apple? # true, or c.apple? if :namespace => false
|
20
21
|
# c.kind_key # :apple
|
21
22
|
# c.kind_text # "apple" or "Apple" if you gave a hash with a user friendly text value
|
22
23
|
# c.enum?(:kind) # true
|
23
24
|
def enum(field, values, options = {})
|
25
|
+
namespace = options.key?(:namespace) ? options[:namespace] : true
|
26
|
+
|
24
27
|
values_hash = if values.is_a?(Array)
|
25
28
|
hash = {}
|
26
29
|
values.each { |value| hash[value] = value }
|
@@ -52,7 +55,7 @@ module Enumlogic
|
|
52
55
|
|
53
56
|
values_array.each do |value|
|
54
57
|
method_name = value.underscore.gsub(/[-\s]/, '_')
|
55
|
-
method_name = "#{
|
58
|
+
method_name = "#{field}_#{method_name}" if namespace
|
56
59
|
define_method("#{method_name}?") do
|
57
60
|
self.send(field) == value
|
58
61
|
end
|
data/spec/enumlogic_spec.rb
CHANGED
@@ -57,7 +57,7 @@ describe "Enumlogic" do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should create boolean methods" do
|
60
|
-
Computer.enum :kind, ["apple", "dell", "hp", "HelloThere"]
|
60
|
+
Computer.enum :kind, ["apple", "dell", "hp", "HelloThere"], :namespace => false
|
61
61
|
c = Computer.new(:kind => "apple")
|
62
62
|
c.should be_apple
|
63
63
|
c = Computer.new(:kind => "HelloThere")
|
@@ -67,7 +67,7 @@ describe "Enumlogic" do
|
|
67
67
|
it "should namespace boolean methods" do
|
68
68
|
Computer.enum :kind, ["apple", "dell", "hp"], :namespace => true
|
69
69
|
c = Computer.new(:kind => "apple")
|
70
|
-
c.should
|
70
|
+
c.should be_kind_apple
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should validate inclusion" do
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Ben Johnson
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,6 +30,7 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: activerecord
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,7 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rake
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,6 +62,7 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: rspec
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ~>
|
60
68
|
- !ruby/object:Gem::Version
|
@@ -62,6 +70,7 @@ dependencies:
|
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ~>
|
67
76
|
- !ruby/object:Gem::Version
|
@@ -69,6 +78,7 @@ dependencies:
|
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: sqlite3
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
83
|
- - ! '>='
|
74
84
|
- !ruby/object:Gem::Version
|
@@ -76,6 +86,7 @@ dependencies:
|
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
91
|
- - ! '>='
|
81
92
|
- !ruby/object:Gem::Version
|
@@ -100,26 +111,27 @@ files:
|
|
100
111
|
- spec/spec_helper.rb
|
101
112
|
homepage: http://github.com/binarylogic/enumlogic
|
102
113
|
licenses: []
|
103
|
-
metadata: {}
|
104
114
|
post_install_message:
|
105
115
|
rdoc_options: []
|
106
116
|
require_paths:
|
107
117
|
- lib
|
108
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
109
120
|
requirements:
|
110
121
|
- - ! '>='
|
111
122
|
- !ruby/object:Gem::Version
|
112
123
|
version: '0'
|
113
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
114
126
|
requirements:
|
115
127
|
- - ! '>='
|
116
128
|
- !ruby/object:Gem::Version
|
117
129
|
version: '0'
|
118
130
|
requirements: []
|
119
131
|
rubyforge_project:
|
120
|
-
rubygems_version:
|
132
|
+
rubygems_version: 1.8.25
|
121
133
|
signing_key:
|
122
|
-
specification_version:
|
134
|
+
specification_version: 3
|
123
135
|
summary: Adds enumerations to your models
|
124
136
|
test_files:
|
125
137
|
- spec/enumlogic_spec.rb
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
YWUxNDcwYzJkNmVjYmI0YWZkYjg2NDhjZGE1ZTU5MGZjZjU5OTA5MQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MjViMmM3MDFmOTgyZDc0ZmViNjE4YWJiNzk4ZjNiMDAwMzM0MDRjZA==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ZGQ3MTIyYTQxMTQxODkxNGUyNGM5YWEwODNkZWVlMWRmMDMyOWM0OTk5OTJk
|
10
|
-
YWFiZDFjMmMyNTY0OTAwMjk4Y2I5MTFiOGI1MjczMmQyZWIwNDkxMTkxZjMw
|
11
|
-
YThjNWNhZDI5ZWMyOGY4YTM4OTZmOTQ3NDliYTUyYzYzOTMxODE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YTZlNWY1Y2E2NWEwZGM1MTg4NTg4ZWIxNzhkMTU0MGUwZWUxMGRiNDI5MmU2
|
14
|
-
MTIwZjRiZjc5YjI2YTZiNDc5NzBjYTAyNWFlZWM5MjFmYjIzOWJlODEwODAy
|
15
|
-
YjZjYjEyYTZmMWYyOGJjNGQ3ZTY4NDAxNzNlMWY4N2M3ZDUzMGQ=
|