classy_enum 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +93 -0
- data/README.textile +6 -6
- data/Rakefile +12 -12
- data/VERSION +1 -1
- data/classy_enum.gemspec +26 -14
- data/lib/classy_enum.rb +26 -25
- data/lib/classy_enum/attributes.rb +32 -0
- data/lib/classy_enum/semantic_form_builder.rb +26 -0
- data/lib/generators/classy_enum/classy_enum_generator.rb +14 -0
- data/lib/generators/classy_enum/templates/enum.erb +15 -0
- data/spec/{classy_enum_helper_spec.rb → classy_enum_semantic_form_builder.rb} +1 -1
- data/spec/spec_helper.rb +9 -15
- metadata +59 -21
- data/lib/classy_enum/classy_enum_attributes.rb +0 -30
- data/lib/classy_enum/classy_enum_helper.rb +0 -14
- data/spec/spec.opts +0 -1
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
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)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4.1)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.12)
|
16
|
+
rack-test (~> 0.5.4)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.1)
|
19
|
+
activesupport (= 3.0.1)
|
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)
|
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)
|
33
|
+
builder (2.1.2)
|
34
|
+
diff-lcs (1.1.2)
|
35
|
+
erubis (2.6.6)
|
36
|
+
abstract (>= 1.0.0)
|
37
|
+
formtastic (1.1.0)
|
38
|
+
actionpack (>= 2.3.0)
|
39
|
+
activesupport (>= 2.3.0)
|
40
|
+
i18n (>= 0.4.0)
|
41
|
+
i18n (0.4.1)
|
42
|
+
mail (2.2.7)
|
43
|
+
activesupport (>= 2.3.6)
|
44
|
+
mime-types
|
45
|
+
treetop (>= 1.4.5)
|
46
|
+
mime-types (1.16)
|
47
|
+
polyglot (0.3.1)
|
48
|
+
rack (1.2.1)
|
49
|
+
rack-mount (0.6.13)
|
50
|
+
rack (>= 1.0.0)
|
51
|
+
rack-test (0.5.6)
|
52
|
+
rack (>= 1.0)
|
53
|
+
rails (3.0.1)
|
54
|
+
actionmailer (= 3.0.1)
|
55
|
+
actionpack (= 3.0.1)
|
56
|
+
activerecord (= 3.0.1)
|
57
|
+
activeresource (= 3.0.1)
|
58
|
+
activesupport (= 3.0.1)
|
59
|
+
bundler (~> 1.0.0)
|
60
|
+
railties (= 3.0.1)
|
61
|
+
railties (3.0.1)
|
62
|
+
actionpack (= 3.0.1)
|
63
|
+
activesupport (= 3.0.1)
|
64
|
+
rake (>= 0.8.4)
|
65
|
+
thor (~> 0.14.0)
|
66
|
+
rake (0.8.7)
|
67
|
+
rspec (2.0.0)
|
68
|
+
rspec-core (= 2.0.0)
|
69
|
+
rspec-expectations (= 2.0.0)
|
70
|
+
rspec-mocks (= 2.0.0)
|
71
|
+
rspec-core (2.0.0)
|
72
|
+
rspec-expectations (2.0.0)
|
73
|
+
diff-lcs (>= 1.1.2)
|
74
|
+
rspec-mocks (2.0.0)
|
75
|
+
rspec-core (= 2.0.0)
|
76
|
+
rspec-expectations (= 2.0.0)
|
77
|
+
rspec-rails (2.0.1)
|
78
|
+
rspec (~> 2.0.0)
|
79
|
+
sqlite3-ruby (1.3.1)
|
80
|
+
thor (0.14.3)
|
81
|
+
treetop (1.4.8)
|
82
|
+
polyglot (>= 0.3.1)
|
83
|
+
tzinfo (0.3.23)
|
84
|
+
|
85
|
+
PLATFORMS
|
86
|
+
ruby
|
87
|
+
|
88
|
+
DEPENDENCIES
|
89
|
+
formtastic (~> 1.1)
|
90
|
+
rails (~> 3.0)
|
91
|
+
rspec (~> 2.0)
|
92
|
+
rspec-rails (~> 2.0)
|
93
|
+
sqlite3-ruby
|
data/README.textile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
h1. classy_enum
|
2
2
|
|
3
|
-
ClassyEnum adds class-based enumerator functionality to
|
3
|
+
ClassyEnum is a Ruby on Rails gem that adds class-based enumerator functionality to ActiveRecord attributes.
|
4
4
|
|
5
5
|
h2. Requirements
|
6
6
|
|
7
|
-
*Rails:*
|
7
|
+
*Rails:* Any version of Rails 2.3.x or Rails 3.x. (Older versions of Rails may work, but have not been tested)
|
8
8
|
|
9
|
-
*Ruby:*
|
9
|
+
*Ruby:* Ruby 1.8.7 and 1.9.2.
|
10
10
|
|
11
11
|
h2. Installation
|
12
12
|
|
@@ -15,7 +15,7 @@ The gem is hosted at "rubygems.org":https://rubygems.org/gems/classy_enum
|
|
15
15
|
It can be installed with:
|
16
16
|
|
17
17
|
<pre>
|
18
|
-
|
18
|
+
gem install classy_enum
|
19
19
|
</pre>
|
20
20
|
|
21
21
|
h2. Example Usage
|
@@ -110,14 +110,14 @@ h2. Formtastic Support
|
|
110
110
|
To add ClassyEnum support to Formtastic, add the following to your formtastic.rb initializer (config/initializers/formtastic.rb):
|
111
111
|
|
112
112
|
<pre>
|
113
|
-
Formtastic::SemanticFormHelper.builder =
|
113
|
+
Formtastic::SemanticFormHelper.builder = ClassyEnum::SemanticFormBuilder
|
114
114
|
</pre>
|
115
115
|
|
116
116
|
Then in your Formtastic view forms, use this syntax: @<%= f.input :priority, :as => :enum_select %>@
|
117
117
|
|
118
118
|
h2. Notes
|
119
119
|
|
120
|
-
An ActiveRecord validator @validates_inclusion_of :field, :in => ENUM.all@ is automatically added to your model when you use @classy_enum_attr@.
|
120
|
+
An ActiveRecord validator @validates_inclusion_of :field, :in => ENUM.all, :allow_nil => true@ is automatically added to your model when you use @classy_enum_attr@.
|
121
121
|
|
122
122
|
h2. Copyright
|
123
123
|
|
data/Rakefile
CHANGED
@@ -6,32 +6,32 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "classy_enum"
|
8
8
|
gem.summary = %Q{A class based enumerator utility for Ruby on Rails}
|
9
|
-
gem.description = %Q{A utility that adds class based enum
|
9
|
+
gem.description = %Q{A utility that adds class based enum functionality to ActiveRecord attributes}
|
10
10
|
gem.email = "github@lette.us"
|
11
11
|
gem.homepage = "http://github.com/beerlington/classy_enum"
|
12
12
|
gem.authors = ["Peter Brown"]
|
13
|
-
gem.add_development_dependency "rspec", "
|
14
|
-
gem.
|
13
|
+
gem.add_development_dependency "rspec", "~> 2.0"
|
14
|
+
gem.add_development_dependency 'rspec-rails', '~> 2.0'
|
15
|
+
gem.add_development_dependency 'formtastic', '~> 1.1'
|
16
|
+
gem.add_development_dependency 'sqlite3-ruby'
|
17
|
+
gem.add_dependency "activerecord", ">= 2.3"
|
15
18
|
end
|
16
19
|
Jeweler::GemcutterTasks.new
|
17
20
|
rescue LoadError
|
18
21
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
22
|
end
|
20
23
|
|
21
|
-
require '
|
22
|
-
|
23
|
-
|
24
|
-
spec.
|
24
|
+
require 'rspec/core'
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
27
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
|
-
spec.libs << 'lib' << 'spec'
|
30
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
29
31
|
spec.pattern = 'spec/**/*_spec.rb'
|
30
32
|
spec.rcov = true
|
31
33
|
end
|
32
34
|
|
33
|
-
task :spec => :check_dependencies
|
34
|
-
|
35
35
|
task :default => :spec
|
36
36
|
|
37
37
|
require 'rake/rdoctask'
|
@@ -39,7 +39,7 @@ Rake::RDocTask.new do |rdoc|
|
|
39
39
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
40
|
|
41
41
|
rdoc.rdoc_dir = 'rdoc'
|
42
|
-
rdoc.title = "
|
42
|
+
rdoc.title = "thegem #{version}"
|
43
43
|
rdoc.rdoc_files.include('README*')
|
44
44
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
45
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/classy_enum.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{classy_enum}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.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{2010-
|
13
|
-
s.description = %q{A utility that adds class based enum
|
12
|
+
s.date = %q{2010-11-04}
|
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 = [
|
16
16
|
"LICENSE",
|
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
22
24
|
"LICENSE",
|
23
25
|
"README.textile",
|
24
26
|
"Rakefile",
|
@@ -28,12 +30,13 @@ Gem::Specification.new do |s|
|
|
28
30
|
"generators/templates/enum.erb",
|
29
31
|
"init.rb",
|
30
32
|
"lib/classy_enum.rb",
|
31
|
-
"lib/classy_enum/
|
32
|
-
"lib/classy_enum/
|
33
|
+
"lib/classy_enum/attributes.rb",
|
34
|
+
"lib/classy_enum/semantic_form_builder.rb",
|
35
|
+
"lib/generators/classy_enum/classy_enum_generator.rb",
|
36
|
+
"lib/generators/classy_enum/templates/enum.erb",
|
33
37
|
"spec/classy_enum_attributes_spec.rb",
|
34
|
-
"spec/
|
38
|
+
"spec/classy_enum_semantic_form_builder.rb",
|
35
39
|
"spec/classy_enum_spec.rb",
|
36
|
-
"spec/spec.opts",
|
37
40
|
"spec/spec_helper.rb"
|
38
41
|
]
|
39
42
|
s.homepage = %q{http://github.com/beerlington/classy_enum}
|
@@ -43,7 +46,7 @@ Gem::Specification.new do |s|
|
|
43
46
|
s.summary = %q{A class based enumerator utility for Ruby on Rails}
|
44
47
|
s.test_files = [
|
45
48
|
"spec/classy_enum_attributes_spec.rb",
|
46
|
-
"spec/
|
49
|
+
"spec/classy_enum_semantic_form_builder.rb",
|
47
50
|
"spec/classy_enum_spec.rb",
|
48
51
|
"spec/spec_helper.rb"
|
49
52
|
]
|
@@ -53,15 +56,24 @@ Gem::Specification.new do |s|
|
|
53
56
|
s.specification_version = 3
|
54
57
|
|
55
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
-
s.add_development_dependency(%q<rspec>, ["
|
57
|
-
s.
|
59
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
60
|
+
s.add_development_dependency(%q<rspec-rails>, ["~> 2.0"])
|
61
|
+
s.add_development_dependency(%q<formtastic>, ["~> 1.1"])
|
62
|
+
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
63
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.3"])
|
58
64
|
else
|
59
|
-
s.add_dependency(%q<rspec>, ["
|
60
|
-
s.add_dependency(%q<
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
66
|
+
s.add_dependency(%q<rspec-rails>, ["~> 2.0"])
|
67
|
+
s.add_dependency(%q<formtastic>, ["~> 1.1"])
|
68
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
69
|
+
s.add_dependency(%q<activerecord>, [">= 2.3"])
|
61
70
|
end
|
62
71
|
else
|
63
|
-
s.add_dependency(%q<rspec>, ["
|
64
|
-
s.add_dependency(%q<
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
73
|
+
s.add_dependency(%q<rspec-rails>, ["~> 2.0"])
|
74
|
+
s.add_dependency(%q<formtastic>, ["~> 1.1"])
|
75
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
76
|
+
s.add_dependency(%q<activerecord>, [">= 2.3"])
|
65
77
|
end
|
66
78
|
end
|
67
79
|
|
data/lib/classy_enum.rb
CHANGED
@@ -1,25 +1,8 @@
|
|
1
|
-
require "classy_enum/
|
2
|
-
require 'classy_enum/classy_enum_helper'
|
3
|
-
|
4
|
-
class ClassyEnumValue < Object
|
5
|
-
|
6
|
-
attr_reader :to_s, :to_sym, :index, :base_class
|
7
|
-
|
8
|
-
def initialize(base_class, option, index)
|
9
|
-
@to_s = option.to_s.downcase
|
10
|
-
@to_sym = @to_s.to_sym
|
11
|
-
@index = index + 1
|
12
|
-
@base_class = base_class
|
13
|
-
end
|
14
|
-
|
15
|
-
def name
|
16
|
-
to_s.titleize
|
17
|
-
end
|
18
|
-
|
19
|
-
def <=> other
|
20
|
-
@index <=> other.index
|
21
|
-
end
|
1
|
+
require "classy_enum/attributes"
|
22
2
|
|
3
|
+
if Gem.available? 'formtastic'
|
4
|
+
require 'formtastic'
|
5
|
+
require 'classy_enum/semantic_form_builder'
|
23
6
|
end
|
24
7
|
|
25
8
|
module ClassyEnum
|
@@ -27,7 +10,8 @@ module ClassyEnum
|
|
27
10
|
module SuperClassMethods
|
28
11
|
|
29
12
|
def new(option)
|
30
|
-
|
13
|
+
return nil if option.nil?
|
14
|
+
self::OPTION_HASH[option.to_sym] || TypeError.new("Valid #{self} options are #{self.valid_options}")
|
31
15
|
end
|
32
16
|
|
33
17
|
def all
|
@@ -53,11 +37,28 @@ module ClassyEnum
|
|
53
37
|
def self.included(other)
|
54
38
|
other.extend SuperClassMethods
|
55
39
|
|
56
|
-
other.const_set("OPTION_HASH", Hash.new)
|
40
|
+
other.const_set("OPTION_HASH", Hash.new) unless other.const_defined? "OPTION_HASH"
|
57
41
|
|
58
42
|
other::OPTIONS.each do |option|
|
59
43
|
|
60
|
-
klass = Class.new
|
44
|
+
klass = Class.new do
|
45
|
+
self.send(:attr_reader, :to_s, :to_sym, :index, :base_class)
|
46
|
+
|
47
|
+
def initialize(base_class, option, index)
|
48
|
+
@to_s = option.to_s.downcase
|
49
|
+
@to_sym = @to_s.to_sym
|
50
|
+
@index = index + 1
|
51
|
+
@base_class = base_class
|
52
|
+
end
|
53
|
+
|
54
|
+
def name
|
55
|
+
to_s.titleize
|
56
|
+
end
|
57
|
+
|
58
|
+
def <=> other
|
59
|
+
@index <=> other.index
|
60
|
+
end
|
61
|
+
|
61
62
|
include other::InstanceMethods if other.const_defined?("InstanceMethods")
|
62
63
|
extend other::ClassMethods if other.const_defined?("ClassMethods")
|
63
64
|
end
|
@@ -66,7 +67,7 @@ module ClassyEnum
|
|
66
67
|
|
67
68
|
instance = klass.new(other, option, other::OPTIONS.index(option))
|
68
69
|
|
69
|
-
other::OPTION_HASH[option] =
|
70
|
+
other::OPTION_HASH[option] = instance
|
70
71
|
|
71
72
|
ClassyEnum.const_set(option.to_s.upcase, instance) unless ClassyEnum.const_defined?(option.to_s.upcase)
|
72
73
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ClassyEnum
|
2
|
+
module Attributes
|
3
|
+
|
4
|
+
def classy_enum_attr(klass, method=nil)
|
5
|
+
|
6
|
+
method ||= klass
|
7
|
+
|
8
|
+
klass = klass.to_s.camelize.constantize
|
9
|
+
|
10
|
+
# Add ActiveRecord validation to ensure it won't be saved unless it's an option
|
11
|
+
self.send(:validates_inclusion_of, method, :in => klass.all, :allow_nil => true)
|
12
|
+
|
13
|
+
self.instance_eval do
|
14
|
+
|
15
|
+
# Define getter method
|
16
|
+
define_method method do
|
17
|
+
klass.new(super())
|
18
|
+
end
|
19
|
+
|
20
|
+
# Define setter method
|
21
|
+
define_method "#{method}=" do |value|
|
22
|
+
super(value.to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
ActiveRecord::Base.send :extend, ClassyEnum::Attributes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ClassyEnum
|
2
|
+
class SemanticFormBuilder < Formtastic::SemanticFormBuilder
|
3
|
+
def enum_select_input(method, options)
|
4
|
+
enum_class = object.send(method)
|
5
|
+
|
6
|
+
if enum_class.nil?
|
7
|
+
enum_class = method.to_s.capitalize.constantize rescue ::Error.invalid_classy_enum_object
|
8
|
+
options[:collection] = enum_class.all_with_name
|
9
|
+
else
|
10
|
+
::Error.invalid_classy_enum_object unless enum_class.respond_to? :base_class
|
11
|
+
options[:collection] = enum_class.base_class.all_with_name
|
12
|
+
options[:selected] = enum_class.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
options[:include_blank] = false
|
16
|
+
|
17
|
+
select_input(method, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Error
|
22
|
+
def invalid_classy_enum_object
|
23
|
+
raise "#{method} does not refer to a defined ClassyEnum object"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class ClassyEnumGenerator < Rails::Generators::NamedBase
|
2
|
+
desc "Generate a ClassyEnum definition in app/enums/"
|
3
|
+
|
4
|
+
argument :name, :type => :string, :required => true, :banner => 'EnumName'
|
5
|
+
argument :values, :type => :array, :default => [], :banner => 'value1 value2 value3 etc...'
|
6
|
+
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
|
9
|
+
def copy_files
|
10
|
+
empty_directory 'app/enums'
|
11
|
+
template "enum.erb", "app/enums/#{file_name}.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
OPTIONS = [<%= values.map {|a| ":#{a}"}.join(", ") %>]
|
3
|
+
|
4
|
+
module InstanceMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
include ClassyEnum
|
11
|
+
end
|
12
|
+
<% values.each do |arg| %>
|
13
|
+
class <%= class_name + arg.camelize %>
|
14
|
+
end
|
15
|
+
<% end %>
|
@@ -3,7 +3,7 @@ require "spec/spec_helper"
|
|
3
3
|
describe 'using enum_select input' do
|
4
4
|
include FormtasticSpecHelper
|
5
5
|
|
6
|
-
Formtastic::SemanticFormHelper.builder =
|
6
|
+
Formtastic::SemanticFormHelper.builder = ClassyEnum::SemanticFormBuilder
|
7
7
|
|
8
8
|
context "when building a form with a classy_enum select" do
|
9
9
|
before(:each) do
|
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
|
-
require '
|
6
|
-
|
7
|
-
require '
|
8
|
-
require '
|
5
|
+
require 'active_record'
|
6
|
+
require 'active_support'
|
7
|
+
require 'action_pack'
|
8
|
+
require 'action_view'
|
9
9
|
require 'action_controller'
|
10
10
|
require 'formtastic'
|
11
11
|
require 'classy_enum'
|
@@ -33,22 +33,11 @@ class Dog < ActiveRecord::Base
|
|
33
33
|
end
|
34
34
|
|
35
35
|
module FormtasticSpecHelper
|
36
|
-
include ActionPack
|
37
36
|
include ActionView::Context if defined?(ActionView::Context)
|
38
37
|
include ActionController::RecordIdentifier
|
39
38
|
include ActionView::Helpers::FormHelper
|
40
39
|
include ActionView::Helpers::FormTagHelper
|
41
40
|
include ActionView::Helpers::FormOptionsHelper
|
42
|
-
include ActionView::Helpers::UrlHelper
|
43
|
-
include ActionView::Helpers::TagHelper
|
44
|
-
include ActionView::Helpers::TextHelper
|
45
|
-
include ActionView::Helpers::DateHelper
|
46
|
-
include ActionView::Helpers::CaptureHelper
|
47
|
-
include ActionView::Helpers::AssetTagHelper
|
48
|
-
include ActiveSupport
|
49
|
-
include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
|
50
|
-
include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
|
51
|
-
include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes)
|
52
41
|
include Formtastic::SemanticFormHelper
|
53
42
|
|
54
43
|
def self.included(base)
|
@@ -65,3 +54,8 @@ module FormtasticSpecHelper
|
|
65
54
|
|
66
55
|
end
|
67
56
|
|
57
|
+
module ActionView
|
58
|
+
class OutputBuffer < ActiveSupport::SafeBuffer
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classy_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Peter Brown
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-04 00:00:00 -04:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -24,32 +23,70 @@ dependencies:
|
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
27
|
-
- -
|
26
|
+
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 13
|
30
28
|
segments:
|
31
|
-
- 1
|
32
29
|
- 2
|
33
|
-
-
|
34
|
-
version:
|
30
|
+
- 0
|
31
|
+
version: "2.0"
|
35
32
|
type: :development
|
36
33
|
version_requirements: *id001
|
37
34
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
35
|
+
name: rspec-rails
|
39
36
|
prerelease: false
|
40
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
38
|
none: false
|
42
39
|
requirements:
|
43
40
|
- - ~>
|
44
41
|
- !ruby/object:Gem::Version
|
45
|
-
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 0
|
45
|
+
version: "2.0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: formtastic
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 1
|
58
|
+
- 1
|
59
|
+
version: "1.1"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sqlite3-ruby
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
type: :development
|
74
|
+
version_requirements: *id004
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: activerecord
|
77
|
+
prerelease: false
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
46
83
|
segments:
|
47
84
|
- 2
|
48
85
|
- 3
|
49
86
|
version: "2.3"
|
50
87
|
type: :runtime
|
51
|
-
version_requirements: *
|
52
|
-
description: A utility that adds class based enum
|
88
|
+
version_requirements: *id005
|
89
|
+
description: A utility that adds class based enum functionality to ActiveRecord attributes
|
53
90
|
email: github@lette.us
|
54
91
|
executables: []
|
55
92
|
|
@@ -61,6 +98,8 @@ extra_rdoc_files:
|
|
61
98
|
files:
|
62
99
|
- .document
|
63
100
|
- .gitignore
|
101
|
+
- Gemfile
|
102
|
+
- Gemfile.lock
|
64
103
|
- LICENSE
|
65
104
|
- README.textile
|
66
105
|
- Rakefile
|
@@ -70,12 +109,13 @@ files:
|
|
70
109
|
- generators/templates/enum.erb
|
71
110
|
- init.rb
|
72
111
|
- lib/classy_enum.rb
|
73
|
-
- lib/classy_enum/
|
74
|
-
- lib/classy_enum/
|
112
|
+
- lib/classy_enum/attributes.rb
|
113
|
+
- lib/classy_enum/semantic_form_builder.rb
|
114
|
+
- lib/generators/classy_enum/classy_enum_generator.rb
|
115
|
+
- lib/generators/classy_enum/templates/enum.erb
|
75
116
|
- spec/classy_enum_attributes_spec.rb
|
76
|
-
- spec/
|
117
|
+
- spec/classy_enum_semantic_form_builder.rb
|
77
118
|
- spec/classy_enum_spec.rb
|
78
|
-
- spec/spec.opts
|
79
119
|
- spec/spec_helper.rb
|
80
120
|
has_rdoc: true
|
81
121
|
homepage: http://github.com/beerlington/classy_enum
|
@@ -91,7 +131,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
131
|
requirements:
|
92
132
|
- - ">="
|
93
133
|
- !ruby/object:Gem::Version
|
94
|
-
hash: 3
|
95
134
|
segments:
|
96
135
|
- 0
|
97
136
|
version: "0"
|
@@ -100,7 +139,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
139
|
requirements:
|
101
140
|
- - ">="
|
102
141
|
- !ruby/object:Gem::Version
|
103
|
-
hash: 3
|
104
142
|
segments:
|
105
143
|
- 0
|
106
144
|
version: "0"
|
@@ -113,6 +151,6 @@ specification_version: 3
|
|
113
151
|
summary: A class based enumerator utility for Ruby on Rails
|
114
152
|
test_files:
|
115
153
|
- spec/classy_enum_attributes_spec.rb
|
116
|
-
- spec/
|
154
|
+
- spec/classy_enum_semantic_form_builder.rb
|
117
155
|
- spec/classy_enum_spec.rb
|
118
156
|
- spec/spec_helper.rb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module ClassyEnumAttributes
|
2
|
-
|
3
|
-
def classy_enum_attr(klass, method=nil)
|
4
|
-
|
5
|
-
method ||= klass
|
6
|
-
|
7
|
-
klass = klass.to_s.camelize.constantize
|
8
|
-
|
9
|
-
# Add ActiveRecord validation to ensure it won't be saved unless it's an option
|
10
|
-
self.send(:validates_inclusion_of, method, :in => klass.all)
|
11
|
-
|
12
|
-
self.instance_eval do
|
13
|
-
|
14
|
-
# Define getter method
|
15
|
-
define_method method do
|
16
|
-
klass.new(super())
|
17
|
-
end
|
18
|
-
|
19
|
-
# Define setter method
|
20
|
-
define_method "#{method}=" do |value|
|
21
|
-
super(value.to_s)
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
ActiveRecord::Base.send :extend, ClassyEnumAttributes
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module ClassyEnumHelper
|
2
|
-
class SemanticFormBuilder < Formtastic::SemanticFormBuilder
|
3
|
-
def enum_select_input(method, options)
|
4
|
-
enum_class = object.send(method)
|
5
|
-
|
6
|
-
raise "#{method} does not refer to a defined ClassyEnum object" unless enum_class.respond_to? :base_class
|
7
|
-
|
8
|
-
options[:collection] = enum_class.base_class.all_with_name
|
9
|
-
options[:selected] = enum_class.to_s
|
10
|
-
|
11
|
-
select_input(method, options)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|