classy_enum 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -3
- data/Gemfile.lock +65 -64
- data/README.textile +4 -2
- data/VERSION +1 -1
- data/classy_enum.gemspec +3 -3
- data/lib/classy_enum/attributes.rb +9 -3
- data/lib/classy_enum/semantic_form_builder.rb +5 -9
- data/spec/classy_enum_semantic_form_builder_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +6 -6
data/Gemfile
CHANGED
@@ -7,9 +7,9 @@ group :development do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
group :test do
|
10
|
-
gem 'rspec', '~> 2.
|
11
|
-
gem 'rspec-rails', '~> 2.
|
12
|
-
gem 'formtastic', '~> 1.
|
10
|
+
gem 'rspec', '~> 2.5'
|
11
|
+
gem 'rspec-rails', '~> 2.5'
|
12
|
+
gem 'formtastic', '~> 1.2'
|
13
13
|
gem 'sqlite3-ruby', :require => 'sqlite3'
|
14
14
|
gem 'ruby-debug'
|
15
15
|
end
|
data/Gemfile.lock
CHANGED
@@ -2,89 +2,90 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
abstract (1.0.0)
|
5
|
-
actionmailer (3.0.
|
6
|
-
actionpack (= 3.0.
|
7
|
-
mail (~> 2.2.
|
8
|
-
actionpack (3.0.
|
9
|
-
activemodel (= 3.0.
|
10
|
-
activesupport (= 3.0.
|
5
|
+
actionmailer (3.0.5)
|
6
|
+
actionpack (= 3.0.5)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.5)
|
9
|
+
activemodel (= 3.0.5)
|
10
|
+
activesupport (= 3.0.5)
|
11
11
|
builder (~> 2.1.2)
|
12
12
|
erubis (~> 2.6.6)
|
13
|
-
i18n (~> 0.4
|
13
|
+
i18n (~> 0.4)
|
14
14
|
rack (~> 1.2.1)
|
15
|
-
rack-mount (~> 0.6.
|
16
|
-
rack-test (~> 0.5.
|
15
|
+
rack-mount (~> 0.6.13)
|
16
|
+
rack-test (~> 0.5.7)
|
17
17
|
tzinfo (~> 0.3.23)
|
18
|
-
activemodel (3.0.
|
19
|
-
activesupport (= 3.0.
|
18
|
+
activemodel (3.0.5)
|
19
|
+
activesupport (= 3.0.5)
|
20
20
|
builder (~> 2.1.2)
|
21
|
-
i18n (~> 0.4
|
22
|
-
activerecord (3.0.
|
23
|
-
activemodel (= 3.0.
|
24
|
-
activesupport (= 3.0.
|
25
|
-
arel (~>
|
21
|
+
i18n (~> 0.4)
|
22
|
+
activerecord (3.0.5)
|
23
|
+
activemodel (= 3.0.5)
|
24
|
+
activesupport (= 3.0.5)
|
25
|
+
arel (~> 2.0.2)
|
26
26
|
tzinfo (~> 0.3.23)
|
27
|
-
activeresource (3.0.
|
28
|
-
activemodel (= 3.0.
|
29
|
-
activesupport (= 3.0.
|
30
|
-
activesupport (3.0.
|
31
|
-
arel (
|
32
|
-
activesupport (~> 3.0.0)
|
27
|
+
activeresource (3.0.5)
|
28
|
+
activemodel (= 3.0.5)
|
29
|
+
activesupport (= 3.0.5)
|
30
|
+
activesupport (3.0.5)
|
31
|
+
arel (2.0.9)
|
33
32
|
builder (2.1.2)
|
34
33
|
columnize (0.3.2)
|
35
34
|
diff-lcs (1.1.2)
|
36
35
|
erubis (2.6.6)
|
37
36
|
abstract (>= 1.0.0)
|
38
|
-
formtastic (1.
|
39
|
-
actionpack (>= 2.3.
|
40
|
-
activesupport (>= 2.3.
|
41
|
-
i18n (
|
37
|
+
formtastic (1.2.3)
|
38
|
+
actionpack (>= 2.3.7)
|
39
|
+
activesupport (>= 2.3.7)
|
40
|
+
i18n (~> 0.4)
|
42
41
|
gemcutter (0.6.1)
|
43
42
|
git (1.2.5)
|
44
|
-
i18n (0.
|
43
|
+
i18n (0.5.0)
|
45
44
|
jeweler (1.4.0)
|
46
45
|
gemcutter (>= 0.1.0)
|
47
46
|
git (>= 1.2.5)
|
48
47
|
rubyforge (>= 2.0.0)
|
49
48
|
json_pure (1.5.1)
|
50
49
|
linecache (0.43)
|
51
|
-
mail (2.2.
|
50
|
+
mail (2.2.15)
|
52
51
|
activesupport (>= 2.3.6)
|
53
|
-
|
54
|
-
|
52
|
+
i18n (>= 0.4.0)
|
53
|
+
mime-types (~> 1.16)
|
54
|
+
treetop (~> 1.4.8)
|
55
55
|
mime-types (1.16)
|
56
56
|
polyglot (0.3.1)
|
57
|
-
rack (1.2.
|
58
|
-
rack-mount (0.6.
|
57
|
+
rack (1.2.2)
|
58
|
+
rack-mount (0.6.14)
|
59
59
|
rack (>= 1.0.0)
|
60
|
-
rack-test (0.5.
|
60
|
+
rack-test (0.5.7)
|
61
61
|
rack (>= 1.0)
|
62
|
-
rails (3.0.
|
63
|
-
actionmailer (= 3.0.
|
64
|
-
actionpack (= 3.0.
|
65
|
-
activerecord (= 3.0.
|
66
|
-
activeresource (= 3.0.
|
67
|
-
activesupport (= 3.0.
|
68
|
-
bundler (~> 1.0
|
69
|
-
railties (= 3.0.
|
70
|
-
railties (3.0.
|
71
|
-
actionpack (= 3.0.
|
72
|
-
activesupport (= 3.0.
|
73
|
-
rake (>= 0.8.
|
74
|
-
thor (~> 0.14.
|
62
|
+
rails (3.0.5)
|
63
|
+
actionmailer (= 3.0.5)
|
64
|
+
actionpack (= 3.0.5)
|
65
|
+
activerecord (= 3.0.5)
|
66
|
+
activeresource (= 3.0.5)
|
67
|
+
activesupport (= 3.0.5)
|
68
|
+
bundler (~> 1.0)
|
69
|
+
railties (= 3.0.5)
|
70
|
+
railties (3.0.5)
|
71
|
+
actionpack (= 3.0.5)
|
72
|
+
activesupport (= 3.0.5)
|
73
|
+
rake (>= 0.8.7)
|
74
|
+
thor (~> 0.14.4)
|
75
75
|
rake (0.8.7)
|
76
|
-
rspec (2.
|
77
|
-
rspec-core (
|
78
|
-
rspec-expectations (
|
79
|
-
rspec-mocks (
|
80
|
-
rspec-core (2.
|
81
|
-
rspec-expectations (2.
|
82
|
-
diff-lcs (
|
83
|
-
rspec-mocks (2.
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
76
|
+
rspec (2.5.0)
|
77
|
+
rspec-core (~> 2.5.0)
|
78
|
+
rspec-expectations (~> 2.5.0)
|
79
|
+
rspec-mocks (~> 2.5.0)
|
80
|
+
rspec-core (2.5.1)
|
81
|
+
rspec-expectations (2.5.0)
|
82
|
+
diff-lcs (~> 1.1.2)
|
83
|
+
rspec-mocks (2.5.0)
|
84
|
+
rspec-rails (2.5.0)
|
85
|
+
actionpack (~> 3.0)
|
86
|
+
activesupport (~> 3.0)
|
87
|
+
railties (~> 3.0)
|
88
|
+
rspec (~> 2.5.0)
|
88
89
|
ruby-debug (0.10.4)
|
89
90
|
columnize (>= 0.1)
|
90
91
|
ruby-debug-base (~> 0.10.4.0)
|
@@ -93,19 +94,19 @@ GEM
|
|
93
94
|
rubyforge (2.0.4)
|
94
95
|
json_pure (>= 1.1.7)
|
95
96
|
sqlite3-ruby (1.3.1)
|
96
|
-
thor (0.14.
|
97
|
-
treetop (1.4.
|
97
|
+
thor (0.14.6)
|
98
|
+
treetop (1.4.9)
|
98
99
|
polyglot (>= 0.3.1)
|
99
|
-
tzinfo (0.3.
|
100
|
+
tzinfo (0.3.25)
|
100
101
|
|
101
102
|
PLATFORMS
|
102
103
|
ruby
|
103
104
|
|
104
105
|
DEPENDENCIES
|
105
|
-
formtastic (~> 1.
|
106
|
+
formtastic (~> 1.2)
|
106
107
|
jeweler (= 1.4.0)
|
107
108
|
rails (~> 3.0)
|
108
|
-
rspec (~> 2.
|
109
|
-
rspec-rails (~> 2.
|
109
|
+
rspec (~> 2.5)
|
110
|
+
rspec-rails (~> 2.5)
|
110
111
|
ruby-debug
|
111
112
|
sqlite3-ruby
|
data/README.textile
CHANGED
@@ -4,7 +4,7 @@ ClassyEnum is a Ruby on Rails gem that adds class-based enumerator functionality
|
|
4
4
|
|
5
5
|
h2. Requirements
|
6
6
|
|
7
|
-
*Rails:* Any version of Rails 2.3.x or Rails 3.x. (Older versions of Rails may work, but have not been tested)
|
7
|
+
*Rails:* Any version of Rails 2.3.x or Rails 3.0.x. (Older versions of Rails may work, but have not been tested)
|
8
8
|
|
9
9
|
*Ruby:* Ruby 1.8.7 and 1.9.2.
|
10
10
|
|
@@ -12,6 +12,8 @@ h2. Installation
|
|
12
12
|
|
13
13
|
The gem is hosted at "rubygems.org":https://rubygems.org/gems/classy_enum and can be installed with: @gem install classy_enum@
|
14
14
|
|
15
|
+
You will also need to add @app/enums@ as an autoloadable path. This configuration will depend on which version of rails you are using.
|
16
|
+
|
15
17
|
h2. Example Usage
|
16
18
|
|
17
19
|
The most common use for ClassyEnum is to replace database lookup tables where the content and behavior is mostly static and has multiple "types". In this example, I have an ActiveRecord model called @Alarm@ with an attribute called @priority@. Priority is stored as a string (VARCHAR) type in the database and is converted to an enum value when requested.
|
@@ -121,7 +123,7 @@ What if your enum class name is not the same as your model's attribute name? No
|
|
121
123
|
|
122
124
|
<pre>
|
123
125
|
class Alarm < ActiveRecord::Base
|
124
|
-
classy_enum_attr :
|
126
|
+
classy_enum_attr :alarm_priority, :enum => :priority
|
125
127
|
end
|
126
128
|
|
127
129
|
@alarm = Alarm.create(:alarm_priority => :medium)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/classy_enum.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{classy_enum}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.8.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Peter Brown"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-24}
|
13
13
|
s.description = %q{A utility that adds class based enum functionality to ActiveRecord attributes}
|
14
14
|
s.email = %q{github@lette.us}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
|
|
45
45
|
s.homepage = %q{http://github.com/beerlington/classy_enum}
|
46
46
|
s.rdoc_options = ["--charset=UTF-8"]
|
47
47
|
s.require_paths = ["lib"]
|
48
|
-
s.rubygems_version = %q{1.
|
48
|
+
s.rubygems_version = %q{1.6.2}
|
49
49
|
s.summary = %q{A class based enumerator utility for Ruby on Rails}
|
50
50
|
s.test_files = [
|
51
51
|
"spec/classy_enum_attributes_spec.rb",
|
@@ -16,16 +16,22 @@ module ClassyEnum
|
|
16
16
|
#
|
17
17
|
# # Associate an enum Priority with Alarm model's alarm_priority attribute
|
18
18
|
# class Alarm < ActiveRecord::Base
|
19
|
-
# classy_enum_attr :
|
19
|
+
# classy_enum_attr :alarm_priority, :enum => :priority
|
20
20
|
# end
|
21
|
-
def classy_enum_attr(
|
21
|
+
def classy_enum_attr(*args)
|
22
|
+
options = args.extract_options!
|
22
23
|
|
23
|
-
attribute
|
24
|
+
attribute = args[0]
|
25
|
+
enum = options[:enum] || attribute
|
24
26
|
|
25
27
|
klass = enum.to_s.camelize.constantize
|
26
28
|
|
27
29
|
self.instance_eval do
|
28
30
|
|
31
|
+
# Store the enum class so it can be retrieved by Formtastic input builder
|
32
|
+
@classy_enums ||= {}
|
33
|
+
@classy_enums[attribute] = klass
|
34
|
+
|
29
35
|
# Add ActiveRecord validation to ensure it won't be saved unless it's an option
|
30
36
|
validates_inclusion_of attribute, :in => klass.all, :message => "must be one of #{klass.valid_options}"
|
31
37
|
|
@@ -1,16 +1,12 @@
|
|
1
1
|
module ClassyEnum
|
2
2
|
class SemanticFormBuilder < Formtastic::SemanticFormBuilder # :nodoc: all
|
3
3
|
def enum_select_input(method, options)
|
4
|
-
enum_class = object.
|
4
|
+
enum_class = object.class.instance_variable_get(:@classy_enums)[method]
|
5
5
|
|
6
|
-
if enum_class.nil?
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Error.invalid_classy_enum_object(method) unless enum_class.is_a? ClassyEnum::Base
|
11
|
-
options[:collection] = enum_class.class.superclass.select_options
|
12
|
-
options[:selected] = enum_class.to_s
|
13
|
-
end
|
6
|
+
raise Error.invalid_classy_enum_object(method) if enum_class.nil?
|
7
|
+
|
8
|
+
options[:collection] = enum_class.select_options
|
9
|
+
options[:selected] = object.send(method).to_s
|
14
10
|
|
15
11
|
options[:include_blank] = false
|
16
12
|
|
@@ -56,7 +56,7 @@ describe 'using enum_select input' do
|
|
56
56
|
context "with an object with a different attribute name which requires the enum_class" do
|
57
57
|
before(:each) do
|
58
58
|
@output = semantic_form_for(OtherDog.new, :url => "/") do |builder|
|
59
|
-
concat(builder.input(:other_breed, :as => :enum_select
|
59
|
+
concat(builder.input(:other_breed, :as => :enum_select))
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classy_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Brown
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-24 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
requirements: []
|
157
157
|
|
158
158
|
rubyforge_project:
|
159
|
-
rubygems_version: 1.
|
159
|
+
rubygems_version: 1.6.2
|
160
160
|
signing_key:
|
161
161
|
specification_version: 3
|
162
162
|
summary: A class based enumerator utility for Ruby on Rails
|