values_for 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +109 -0
- data/Rakefile +21 -0
- data/lib/values_for.rb +80 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/values_for_spec.rb +230 -0
- data/values_for.gemspec +52 -0
- metadata +107 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mal McKay and Justin S. Leitgeb
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
= values_for
|
2
|
+
|
3
|
+
values_for is an ActiveRecord extension enabling the easy use of enumerated types for your models.
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
values_for makes your ActiveRecord-backed class work with an enumerable type. Instead of existing
|
8
|
+
ActiveRecord plugins such as enum_fu, which store the enumerable attribute as an integer, values_for
|
9
|
+
stores the content of the enumerable attribute in a varchar column of the database. The field will
|
10
|
+
automatically validate using validates_inclusion_of and accepts all the same options.
|
11
|
+
|
12
|
+
values_for will also optionally create named scopes, predicate methods, and constants defining the
|
13
|
+
possible values for enumerable types on your model. By default, however, it avoids polluting your
|
14
|
+
model with things you may not need unless these features are specifically requested.
|
15
|
+
|
16
|
+
== Installation
|
17
|
+
|
18
|
+
values_for is available as a gem available on GitHub. Install with:
|
19
|
+
|
20
|
+
sudo gem install mcommons-values_for
|
21
|
+
|
22
|
+
You'll probable want a line like the following in your environment.rb:
|
23
|
+
|
24
|
+
config.gem 'mcommons-values_for', :lib => 'values_for'
|
25
|
+
|
26
|
+
== Basic Usage
|
27
|
+
|
28
|
+
The following example sets up an enumerable attribute on an ActiveRecord model. This assumes that a previous
|
29
|
+
migration has created a column of type VARCHAR on the table "taco".
|
30
|
+
|
31
|
+
class Taco < ActiveRecord::Base
|
32
|
+
values_for :state, :has => [ :new, :composed, :served, :eaten ]
|
33
|
+
end
|
34
|
+
|
35
|
+
For all values_for-enabled models, valid states are able to be read for an attribute by calling the plural of
|
36
|
+
the attribute name:
|
37
|
+
|
38
|
+
>> Taco.states
|
39
|
+
=> [ :new, :composed, :served, :eaten ]
|
40
|
+
|
41
|
+
== Options
|
42
|
+
|
43
|
+
values_for automatically runs validates_inclusion_of on this field. All the validates_inclusion_of options are
|
44
|
+
supported. For example, you can pass :allow_nil=>true to allow the field to be nil.
|
45
|
+
|
46
|
+
values_for will optionally create named scopes, predicate methods, and constants defining values for
|
47
|
+
enumerable types on your model. These may be specified on a case-by-case basis by using the :add
|
48
|
+
option. As an example, the following would create an enumerable attribute called "flavor" with the
|
49
|
+
possible values "sour" and "sweet", while creating named scopes, predicate methods, and constants on
|
50
|
+
your class:
|
51
|
+
|
52
|
+
values_for :flavor, :has => [ :sour, :sweet ], :add => [ :named_scopes, :predicate_methods, :constants ]
|
53
|
+
|
54
|
+
The different additive options are described below.
|
55
|
+
|
56
|
+
=== Named Scopes
|
57
|
+
|
58
|
+
The named_scopes option adds a named scope, with either the default or custom prefix, to your model.
|
59
|
+
For example, the following model definition would create a named_scope Taco.flavor_sour on your class:
|
60
|
+
|
61
|
+
class Taco < ActiveRecord::Base
|
62
|
+
values_for :flavor, :has => [ :sour, :sweet ], :add => :named_scopes
|
63
|
+
end
|
64
|
+
|
65
|
+
Afterwards, you may use the named scopes as follows. Remember to add the prefix!
|
66
|
+
|
67
|
+
Taco.flavor_sour
|
68
|
+
Taco.flavor_sweet
|
69
|
+
|
70
|
+
The prefix may be overridden or omitted by using the :prefix option.
|
71
|
+
|
72
|
+
=== Predicate methods
|
73
|
+
|
74
|
+
values_for also creates predicate methods on instances of your class so that you can ask if they have any
|
75
|
+
of the given enumerable states. For example, if a Taco class has an enumerable type :taste with values
|
76
|
+
:good and :bad, taco.good? would return a boolean value indicating whether or not the taste is good.
|
77
|
+
|
78
|
+
This option is only enabled when the additive option predicate_methods is specified.
|
79
|
+
|
80
|
+
=== Constants
|
81
|
+
|
82
|
+
values_for optionally defines constants corresponding to each of the valid enumerable types on your model.
|
83
|
+
For example, if you have an enumerable column called "states" with valid states :starting and :finished,
|
84
|
+
values_for would define constants on your model Model::STATE_STARTING and Model::STATE_FINISHED with the
|
85
|
+
contents of these constants :starting and :finished respectively. This is only enabled when the additive
|
86
|
+
option :constants is specified.
|
87
|
+
|
88
|
+
== Configuration
|
89
|
+
|
90
|
+
values_for by default adds the attribute being modified as a prefix to constant declarations, named scopes,
|
91
|
+
and predicate methods. If you wish to modify this prefix, pass the :prefix option to values_for. You may
|
92
|
+
also omit the addition of the prefix by passing :prefix => nil to values_for. Example:
|
93
|
+
|
94
|
+
class Taco < ActiveRecord::Base
|
95
|
+
values_for :state, :has => [ :new, :composed, :served, :eaten ], :prefix => 'wacky'
|
96
|
+
end
|
97
|
+
|
98
|
+
This makes Taco respond to named scopes like Taco.wacky_composed instead of the default, which
|
99
|
+
would have prefixed the named_scopes with the name of the attribute.
|
100
|
+
|
101
|
+
== Notes
|
102
|
+
|
103
|
+
This plugin doesn't implement default values for a model. If this behavior is desired, you may be interested
|
104
|
+
in the default_value_for plugin (available http://github.com/FooBarWidget/default_value_for/tree/master),
|
105
|
+
which has been successfully tested with values_for.
|
106
|
+
|
107
|
+
== Authors
|
108
|
+
|
109
|
+
Justin Leitgeb, with contributions from Mal McKay and Ben Stein
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
desc 'Test the plugin.'
|
6
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
7
|
+
t.libs << 'lib'
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Run all the tests"
|
12
|
+
task :default => :spec
|
13
|
+
|
14
|
+
desc 'Generate documentation for the values_for plugin.'
|
15
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Enum For'
|
18
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
data/lib/values_for.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
module ValuesFor
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(SingletonMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module SingletonMethods
|
8
|
+
|
9
|
+
# Creates an enumerable attribute on an ActiveRecord model. Usage is as
|
10
|
+
# follows:
|
11
|
+
#
|
12
|
+
# values_for :state, :has => [ :new, :composed, :served, :eaten ]
|
13
|
+
#
|
14
|
+
# Any additional options will be passed directly to the ActiveRecord method
|
15
|
+
# :validates_inclusion_of, which is used to validate the assigned values to
|
16
|
+
# this attribute. Requires a column of type VARCHAR with the name of the
|
17
|
+
# first argument to +values_for+.
|
18
|
+
def values_for(*args)
|
19
|
+
opts = args.extract_options!
|
20
|
+
attribute = args.first
|
21
|
+
|
22
|
+
attribute_s = attribute.to_s
|
23
|
+
|
24
|
+
additives = Array.wrap(opts[:add])
|
25
|
+
plural_attribute = attribute_s.pluralize
|
26
|
+
|
27
|
+
prefix = opts.has_key?(:prefix) ? opts[:prefix] : attribute_s
|
28
|
+
|
29
|
+
# We don't accept the case where an empty string is a valid value, but we should provide a useful error message
|
30
|
+
raise ArgumentError, "Can't use values_for with an empty string" if opts[:has].any?{|v| v.respond_to?(:empty?) && v.empty? }
|
31
|
+
|
32
|
+
# Valid values are most likely Symbols anyway, but coerce them to be safe.
|
33
|
+
valid_symbols = opts[:has].map{|v| v.to_sym }
|
34
|
+
|
35
|
+
valid_symbols.each do |val_sym|
|
36
|
+
val_s = val_sym.to_s
|
37
|
+
|
38
|
+
prefixed_val = [ prefix, val_s ].compact.join('_')
|
39
|
+
|
40
|
+
# Create +optional+ constants
|
41
|
+
const_set(prefixed_val.upcase, val_sym) if additives.include?(:constants)
|
42
|
+
|
43
|
+
# Create +optional+ named scopes
|
44
|
+
named_scope prefixed_val, :conditions => { attribute => val_s } if additives.include?(:named_scopes)
|
45
|
+
|
46
|
+
# Create +optional+ predicate methods, but don't overwrite existing methods
|
47
|
+
if additives.include?(:predicate_methods) && !self.instance_methods.include?(prefixed_val)
|
48
|
+
define_method(prefixed_val + '?') do # def foo?
|
49
|
+
read_attribute(attribute) == val_s # read_attribute(:foo) == 'foo'
|
50
|
+
end # end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Accepts assignment both from String and Symbol form of valid values.
|
55
|
+
validates_inclusion_of attribute, opts.except(:has, :prefix, :add).
|
56
|
+
merge(:in => valid_symbols | valid_symbols.map{|s| s.to_s } )
|
57
|
+
|
58
|
+
# Custom reader method presents attribute value in Symbol form.
|
59
|
+
define_method(attribute_s) do # def foo
|
60
|
+
unless self[attribute].nil? || self[attribute].empty? # unless self[:foo].nil? || self[:foo].empty?
|
61
|
+
self[attribute].to_sym # self[:foo].to_sym unless self[:foo].nil?
|
62
|
+
end # end
|
63
|
+
end # end
|
64
|
+
|
65
|
+
# Custom setter method casting all attribute input to String, allows
|
66
|
+
# assignment from Symbol form.
|
67
|
+
define_method(attribute_s + '=') do |other| # def foo=(other)
|
68
|
+
self[attribute] = other.nil? ? nil : other.to_s # self[foo] = other unless other.nil?
|
69
|
+
end # end
|
70
|
+
|
71
|
+
# Make collection of all valid attribute Symbols available to user
|
72
|
+
# from plural name of attribute as class method.
|
73
|
+
cattr_reader plural_attribute.to_sym
|
74
|
+
class_variable_set(:"@@#{plural_attribute}", opts[:has])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
ActiveRecord::Base.send(:include, ValuesFor)
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activerecord'
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection(
|
7
|
+
:adapter => 'sqlite3',
|
8
|
+
:dbfile => ":memory:"
|
9
|
+
)
|
10
|
+
|
11
|
+
ActiveRecord::Migration.verbose = false
|
12
|
+
|
13
|
+
ActiveRecord::Base.silence do
|
14
|
+
ActiveRecord::Schema.define do
|
15
|
+
create_table :tacos do |table|
|
16
|
+
table.string :state
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
describe ValuesFor do
|
23
|
+
before do
|
24
|
+
@taco = Taco.new(:state => 'new')
|
25
|
+
end
|
26
|
+
|
27
|
+
class Taco < ActiveRecord::Base
|
28
|
+
values_for :state, :has => [ :new, :composed, :served, :eaten ]
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "model validation" do
|
32
|
+
it "should make a valid model when given a valid state" do
|
33
|
+
@taco.should be_valid
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should retrieve a symbol when the model is created with attribute set to string" do
|
37
|
+
@taco.state.should == :new
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be valid when an attribute is set to a valid symbol" do
|
41
|
+
Taco.new(:state => :composed).should be_valid
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not be valid when an attribute is set to an invalid symbol" do
|
45
|
+
Taco.new(:state => :bogus).should_not be_valid
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not create a valid model when given an invalid state" do
|
49
|
+
Taco.create(:state => 'barfed').should_not be_valid
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "storage and retrieval of possible states in class" do
|
54
|
+
it "should return all possible states when plural of attribute is called as class method" do
|
55
|
+
Taco.states.should == [ :new, :composed, :served, :eaten ]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "definition of constants for each attribute value" do
|
60
|
+
class WithoutConstants < ActiveRecord::Base
|
61
|
+
values_for :state, :has => [ :new, :composed, :served, :eaten ]
|
62
|
+
end
|
63
|
+
|
64
|
+
class WithConstants < ActiveRecord::Base
|
65
|
+
values_for :state, :has => [ :new, :composed, :served, :eaten ], :add => :constants
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be disabled by default" do
|
69
|
+
WithoutConstants.constants.should_not include('WithoutConstants::STATE_NEW')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be enabled when added" do
|
73
|
+
WithConstants.constants.should_not include('WithoutConstants::STATE_NEW')
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should define constants for each type" do
|
77
|
+
WithConstants::STATE_EATEN.should == :eaten
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "definition of predicate methods" do
|
82
|
+
class WithPredicateMethods < ActiveRecord::Base
|
83
|
+
set_table_name "tacos"
|
84
|
+
values_for :state, :has => [ :new, :composed, :served, :eaten ], :add => :predicate_methods
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not define predicate methods for each valid state by default" do
|
88
|
+
@taco.should_not respond_to(:state_eaten?)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should define predicate methods for each state when specified" do
|
92
|
+
WithPredicateMethods.new.should respond_to(:state_eaten?)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "with prefix option" do
|
97
|
+
class Food < ActiveRecord::Base
|
98
|
+
set_table_name "tacos"
|
99
|
+
values_for :state, :has => [:stuff, :morestuff], :prefix => nil, :add => :predicate_methods
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should not prefix predicate methods if asked not to" do
|
103
|
+
Food.new(:state => :stuff).should respond_to(:stuff?)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "casting of values set and retrieved to correct type" do
|
108
|
+
it "should allow strings for attribute values even when initialized with symbols" do
|
109
|
+
Food.new(:state => 'stuff').should be_valid
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should retrieve a symbol when a string is set and the attribute value is a symbol" do
|
113
|
+
f = Food.new(:state => 'stuff')
|
114
|
+
f.state.should == :stuff
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "with an Array of additives" do
|
119
|
+
class BeefJerkey < ActiveRecord::Base
|
120
|
+
set_table_name "tacos"
|
121
|
+
values_for :flavor, :has => [:sour, :spicy], :add => [:named_scopes, :predicate_methods]
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should construct named scopes" do
|
125
|
+
BeefJerkey.should respond_to(:flavor_sour)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should construct predicate methods" do
|
129
|
+
BeefJerkey.new.should respond_to(:flavor_sour?)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "when a user tries to set an empty String as a valid value" do
|
134
|
+
it "should raise an IllegalArgumentError" do
|
135
|
+
lambda {
|
136
|
+
class Food2 < ActiveRecord::Base
|
137
|
+
set_table_name "tacos"
|
138
|
+
values_for :state, :has => ['stuff', '']
|
139
|
+
end
|
140
|
+
}.should raise_error(ArgumentError)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "behavior with existing methods of same name" do
|
145
|
+
class Balloon < ActiveRecord::Base
|
146
|
+
set_table_name "tacos"
|
147
|
+
values_for :state, :has => [:stuff, :morestuff], :prefix => nil
|
148
|
+
|
149
|
+
def stuff?
|
150
|
+
"not a boolean"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should not define a predicate method when a one already exists" do
|
155
|
+
Balloon.new(:state => :stuff).stuff?.should == "not a boolean"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "with validation options" do
|
160
|
+
class Food2 < ActiveRecord::Base
|
161
|
+
set_table_name "tacos"
|
162
|
+
values_for :state, :has => ['stuff', 'morestuff'], :prefix => nil, :allow_nil => true, :message => "is great!"
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should allow validation message to be set" do
|
166
|
+
Food2.create(:state => :junk).errors.full_messages.should include('State is great!')
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should respect :allow_nil setting" do
|
170
|
+
Food2.new.should be_valid
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "getting and setting nil values" do
|
175
|
+
class Food2 < ActiveRecord::Base
|
176
|
+
set_table_name "tacos"
|
177
|
+
values_for :state, :has => ['stuff', 'morestuff'], :prefix => nil, :allow_nil => true, :message => "is great!"
|
178
|
+
end
|
179
|
+
|
180
|
+
before do
|
181
|
+
@f = Food2.new
|
182
|
+
@f.state = nil
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should return a nil value without error" do
|
186
|
+
lambda {
|
187
|
+
@f.state
|
188
|
+
}.should_not raise_error
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should return nil when nil is set" do
|
192
|
+
@f.state.should == nil
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should store nil when nil is set" do
|
196
|
+
@f.state_before_type_cast.should == nil
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "named scope creation" do
|
201
|
+
describe "when not added" do
|
202
|
+
it "should not create named scopes" do
|
203
|
+
Taco.should_not respond_to(:state_composed)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "when added" do
|
208
|
+
class Tequila < ActiveRecord::Base
|
209
|
+
set_table_name "tacos"
|
210
|
+
values_for :state, :has => [ :wormy, :delicious ], :add => :named_scopes
|
211
|
+
end
|
212
|
+
|
213
|
+
before do
|
214
|
+
Tequila.delete_all
|
215
|
+
|
216
|
+
2.times { Tequila.create(:state => 'wormy') }
|
217
|
+
3.times { Tequila.create(:state => 'delicious') }
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should have two wormy tequilas" do
|
221
|
+
Tequila.state_wormy.size.should == 2
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should have three delicious tequilas" do
|
225
|
+
Tequila.state_delicious.size.should == 3
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
data/values_for.gemspec
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "values_for"
|
3
|
+
s.version = "0.0.9"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.author = "Justin Leitgeb"
|
7
|
+
|
8
|
+
s.date = "2009-06-17"
|
9
|
+
s.description = <<-EOS
|
10
|
+
values_for makes your ActiveRecord-backed class work with an enumerable type. Instead of existing
|
11
|
+
ActiveRecord plugins such as enum_fu, which store the enumerable attribute as an integer, values_for
|
12
|
+
stores the content of the enumerable attribute in a varchar column of the database. The field will
|
13
|
+
automatically validate using validates_inclusion_of and accepts all the same options.
|
14
|
+
|
15
|
+
values_for will also optionally create named scopes, predicate methods, and constants defining the
|
16
|
+
possible values for enumerable types on your model. By default, however, it avoids polluting your
|
17
|
+
model with things you may not need unless these features are specifically requested.
|
18
|
+
EOS
|
19
|
+
|
20
|
+
s.email = "justin@stackbuilders.com"
|
21
|
+
|
22
|
+
s.files = [
|
23
|
+
"values_for.gemspec", "lib/values_for.rb", "LICENSE", "Rakefile", "README.rdoc",
|
24
|
+
"spec/values_for_spec.rb", "spec/spec_helper.rb"
|
25
|
+
]
|
26
|
+
|
27
|
+
s.has_rdoc = true
|
28
|
+
s.homepage = "http://github.com/jsl/values_for"
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.3.1}
|
32
|
+
s.summary = "Adds an enumerable attribute to an ActiveRecord-backed class"
|
33
|
+
s.test_files = ["spec/values_for_spec.rb", "spec/spec_helper.rb"]
|
34
|
+
|
35
|
+
s.extra_rdoc_files = [ "README.rdoc" ]
|
36
|
+
|
37
|
+
s.rdoc_options += [
|
38
|
+
'--title', 'Values For',
|
39
|
+
'--main', 'README.rdoc',
|
40
|
+
'--line-numbers',
|
41
|
+
'--inline-source'
|
42
|
+
]
|
43
|
+
|
44
|
+
%w[ activerecord activesupport ].each do |dep|
|
45
|
+
s.add_dependency(dep)
|
46
|
+
end
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 2
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: values_for
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 13
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Justin Leitgeb
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2009-06-17 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activerecord
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: " values_for makes your ActiveRecord-backed class work with an enumerable type. Instead of existing \n ActiveRecord plugins such as enum_fu, which store the enumerable attribute as an integer, values_for \n stores the content of the enumerable attribute in a varchar column of the database. The field will\n automatically validate using validates_inclusion_of and accepts all the same options. \n\n values_for will also optionally create named scopes, predicate methods, and constants defining the \n possible values for enumerable types on your model. By default, however, it avoids polluting your\n model with things you may not need unless these features are specifically requested.\n"
|
50
|
+
email: justin@stackbuilders.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README.rdoc
|
57
|
+
files:
|
58
|
+
- values_for.gemspec
|
59
|
+
- lib/values_for.rb
|
60
|
+
- LICENSE
|
61
|
+
- Rakefile
|
62
|
+
- README.rdoc
|
63
|
+
- spec/values_for_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/jsl/values_for
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
72
|
+
- --title
|
73
|
+
- Values For
|
74
|
+
- --main
|
75
|
+
- README.rdoc
|
76
|
+
- --line-numbers
|
77
|
+
- --inline-source
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.7
|
102
|
+
signing_key:
|
103
|
+
specification_version: 2
|
104
|
+
summary: Adds an enumerable attribute to an ActiveRecord-backed class
|
105
|
+
test_files:
|
106
|
+
- spec/values_for_spec.rb
|
107
|
+
- spec/spec_helper.rb
|