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 CHANGED
@@ -7,9 +7,9 @@ group :development do
7
7
  end
8
8
 
9
9
  group :test do
10
- gem 'rspec', '~> 2.0'
11
- gem 'rspec-rails', '~> 2.0'
12
- gem 'formtastic', '~> 1.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.1)
6
- actionpack (= 3.0.1)
7
- mail (~> 2.2.5)
8
- actionpack (3.0.1)
9
- activemodel (= 3.0.1)
10
- activesupport (= 3.0.1)
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.1)
13
+ i18n (~> 0.4)
14
14
  rack (~> 1.2.1)
15
- rack-mount (~> 0.6.12)
16
- rack-test (~> 0.5.4)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.7)
17
17
  tzinfo (~> 0.3.23)
18
- activemodel (3.0.1)
19
- activesupport (= 3.0.1)
18
+ activemodel (3.0.5)
19
+ activesupport (= 3.0.5)
20
20
  builder (~> 2.1.2)
21
- i18n (~> 0.4.1)
22
- activerecord (3.0.1)
23
- activemodel (= 3.0.1)
24
- activesupport (= 3.0.1)
25
- arel (~> 1.0.0)
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.1)
28
- activemodel (= 3.0.1)
29
- activesupport (= 3.0.1)
30
- activesupport (3.0.1)
31
- arel (1.0.1)
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.1.0)
39
- actionpack (>= 2.3.0)
40
- activesupport (>= 2.3.0)
41
- i18n (>= 0.4.0)
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.4.1)
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.7)
50
+ mail (2.2.15)
52
51
  activesupport (>= 2.3.6)
53
- mime-types
54
- treetop (>= 1.4.5)
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.1)
58
- rack-mount (0.6.13)
57
+ rack (1.2.2)
58
+ rack-mount (0.6.14)
59
59
  rack (>= 1.0.0)
60
- rack-test (0.5.6)
60
+ rack-test (0.5.7)
61
61
  rack (>= 1.0)
62
- rails (3.0.1)
63
- actionmailer (= 3.0.1)
64
- actionpack (= 3.0.1)
65
- activerecord (= 3.0.1)
66
- activeresource (= 3.0.1)
67
- activesupport (= 3.0.1)
68
- bundler (~> 1.0.0)
69
- railties (= 3.0.1)
70
- railties (3.0.1)
71
- actionpack (= 3.0.1)
72
- activesupport (= 3.0.1)
73
- rake (>= 0.8.4)
74
- thor (~> 0.14.0)
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.0.0)
77
- rspec-core (= 2.0.0)
78
- rspec-expectations (= 2.0.0)
79
- rspec-mocks (= 2.0.0)
80
- rspec-core (2.0.0)
81
- rspec-expectations (2.0.0)
82
- diff-lcs (>= 1.1.2)
83
- rspec-mocks (2.0.0)
84
- rspec-core (= 2.0.0)
85
- rspec-expectations (= 2.0.0)
86
- rspec-rails (2.0.1)
87
- rspec (~> 2.0.0)
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.3)
97
- treetop (1.4.8)
97
+ thor (0.14.6)
98
+ treetop (1.4.9)
98
99
  polyglot (>= 0.3.1)
99
- tzinfo (0.3.23)
100
+ tzinfo (0.3.25)
100
101
 
101
102
  PLATFORMS
102
103
  ruby
103
104
 
104
105
  DEPENDENCIES
105
- formtastic (~> 1.1)
106
+ formtastic (~> 1.2)
106
107
  jeweler (= 1.4.0)
107
108
  rails (~> 3.0)
108
- rspec (~> 2.0)
109
- rspec-rails (~> 2.0)
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 :priority, :alarm_priority
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.7.1
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.7.1"
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-02-06}
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.5.0}
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 :priority, :alarm_priority
19
+ # classy_enum_attr :alarm_priority, :enum => :priority
20
20
  # end
21
- def classy_enum_attr(enum, attribute=nil)
21
+ def classy_enum_attr(*args)
22
+ options = args.extract_options!
22
23
 
23
- attribute ||= enum
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.send(method)
4
+ enum_class = object.class.instance_variable_get(:@classy_enums)[method]
5
5
 
6
- if enum_class.nil?
7
- enum_class = (options[:enum_class] || method).to_s.classify.constantize rescue Error.invalid_classy_enum_object(method)
8
- options[:collection] = enum_class.select_options
9
- else
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, :enum_class => :breed))
59
+ concat(builder.input(:other_breed, :as => :enum_select))
60
60
  end
61
61
  end
62
62
 
data/spec/spec_helper.rb CHANGED
@@ -32,7 +32,7 @@ class Dog < ActiveRecord::Base
32
32
  end
33
33
 
34
34
  class OtherDog < ActiveRecord::Base
35
- classy_enum_attr :breed, :other_breed
35
+ classy_enum_attr :other_breed, :enum => :breed
36
36
  end
37
37
 
38
38
  module FormtasticSpecHelper
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: 1
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 1
10
- version: 0.7.1
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-02-06 00:00:00 -05:00
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.5.0
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