jeffp-enumerated_attribute 0.2.0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -0
- data/Rakefile +2 -2
- data/lib/enumerated_attribute/rails_helpers.rb +16 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -33,6 +33,7 @@ encapsulation, quicker implementation and cleaner code.
|
|
33
33
|
Features include:
|
34
34
|
* ActiveRecord integration
|
35
35
|
* ActionView form helpers
|
36
|
+
* Scaffold generator integration
|
36
37
|
* Configurable enumeration labels
|
37
38
|
* Auto-defined attribute methods
|
38
39
|
* Dynamically-generated predicate methods
|
@@ -84,6 +85,10 @@ Expose the enumeration in your forms with +enum_select+
|
|
84
85
|
<%= submit_tag 'save' %>
|
85
86
|
<% end %>
|
86
87
|
|
88
|
+
or generate a scaffold with one of your favorite scaffold generators. Currently
|
89
|
+
support scaffold generators include: scaffold, nifty_scaffold, rspec_scaffold, and wizardly_scaffold.
|
90
|
+
See the section 'Generating Scaffolds' below.
|
91
|
+
|
87
92
|
The select options text can be customized. See 'Customizing Labels' in the Integration section.
|
88
93
|
|
89
94
|
== Ruby Example
|
@@ -466,6 +471,22 @@ example with the +form_tag+ and a @user object.
|
|
466
471
|
<%= submit_tag 'Register' %>
|
467
472
|
<% end %>
|
468
473
|
|
474
|
+
==== Generating Scaffolds
|
475
|
+
|
476
|
+
You can generate views with enumerations using your favorite scaffold generator. Currently
|
477
|
+
supported generators include: scaffold, nifty_scaffold, rspec_scaffold and wizardly_scaffold.
|
478
|
+
For most scaffolds there are two steps. First, generate the scaffold views and
|
479
|
+
migrations using the 'enum' type for enumerations
|
480
|
+
|
481
|
+
./script/generate scaffold contractor name:string gender:enum age:integer status:enum
|
482
|
+
|
483
|
+
Second, do not forget to add the +enum_attr+ macro to the generated model and migrate the database
|
484
|
+
|
485
|
+
class Contractor < ActiveRecord::Base
|
486
|
+
enum_attr :gender, %w(male female)
|
487
|
+
enum_attr :status, %w(available unavailable)
|
488
|
+
end
|
489
|
+
|
469
490
|
|
470
491
|
=== Implementation Notes
|
471
492
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'enumerated_attribute'
|
8
|
-
s.version = '0.2.
|
8
|
+
s.version = '0.2.1'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.description = 'Enumerated model attributes and view helpers'
|
11
11
|
s.summary = 'Add enumerated attributes to your models and expose them in drop-down lists in your views'
|
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = Dir['spec/*_spec.rb']
|
19
19
|
|
20
20
|
s.author = 'Jeff Patmon'
|
21
|
-
s.email = 'jpatmon@
|
21
|
+
s.email = 'jpatmon@gmail.com'
|
22
22
|
s.homepage = 'http://github.com/jeffp/enumerated_attribute/tree/master'
|
23
23
|
end
|
24
24
|
|
@@ -19,6 +19,22 @@ if defined?(ActiveRecord)
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
#ARGV is used by generators -- if it contains one of these generator commands - add enumeration support
|
23
|
+
unless ((ARGV || []) & ["scaffold", "rspec_scaffold", "nifty_scaffold"]).empty?
|
24
|
+
require 'rails_generator'
|
25
|
+
module Rails
|
26
|
+
module Generator
|
27
|
+
class GeneratedAttribute
|
28
|
+
def field_type_with_enumerated_attribute
|
29
|
+
return (@field_type = :enum_select) if type == :enum
|
30
|
+
field_type_without_enumerated_attribute
|
31
|
+
end
|
32
|
+
alias_method_chain :field_type, :enumerated_attribute
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
22
38
|
if defined?(ActionView::Base)
|
23
39
|
module ActionView
|
24
40
|
module Helpers
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeffp-enumerated_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Patmon
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Enumerated model attributes and view helpers
|
17
|
-
email: jpatmon@
|
17
|
+
email: jpatmon@gmail.com
|
18
18
|
executables: []
|
19
19
|
|
20
20
|
extensions: []
|