simple_descriptor 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
- 0.2.1 fixed on primary key
1
+ 0.2.2 fixed validation on boolean fields, now boolean fields
2
+ are not anymore flagged as required
3
+ added option to avoid unwanted required fields
4
+ 0.2.1 fixed validation primary key
2
5
  0.2.0 added direct bindings for ActiveRecord
3
6
  2006 11 26 first release 0.1.0
@@ -184,10 +184,11 @@ module SimpleDescriptor #:nodoc:
184
184
  #will return the maximum length of post title as defined in the database
185
185
  #
186
186
  def load_ar_descriptions
187
+ system_fields = ['created_at', 'updated_at', 'created_on', 'updated_on', 'position', primary_key]
187
188
  if respond_to? :columns_hash
188
189
  columns_hash.each do |k, v|
189
190
  describe k.to_sym, :as => v.type
190
- describe k.to_sym, :as => :required if !v.null && k!= primary_key
191
+ describe k.to_sym, :as => :required if !v.null && !system_fields.member?(k) && v.type != :boolean
191
192
  case v.type
192
193
  when :string : describe k.to_sym, :as => :limited, :with_value => v.limit
193
194
  end
@@ -205,10 +206,15 @@ module SimpleDescriptor #:nodoc:
205
206
  # 5 validates float format for every float field unless :float => false in options
206
207
  # 6 validates decimal format for every decimal field unless :decimal => false in options
207
208
  # 7 if numbers => false in options then float, decimal and integer validations won't be done
209
+ #
210
+ # the optional option :ignore_required can be specified as an array of fields for which
211
+ # the validates_presence_of shouldn't be inferred from a NOT NULL column in the DB
208
212
  def validates_ar_descriptions(options = {})
209
213
  options = {:load_desc => true, :required => true, :length => true, :numbers => true, :float => true, :decimal => true, :integer => true}.update options
210
214
  load_ar_descriptions if options[:load_desc]
211
215
  yield if block_given?
216
+ required = described_as(:required)
217
+ required = described_as(:required) - options[:ignore_required] if options[:ignore_required]
212
218
  send(:validates_presence_of, described_as(:required)) if options[:required]
213
219
  described_as(:limited).each { |field| validates_length_of field, :maximum => maxlength(field), :allow_nil => true } if options[:length]
214
220
  if options[:numbers]
@@ -2,7 +2,7 @@ module SimpleDescriptor #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: simple_descriptor
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.1
7
- date: 2007-06-07 00:00:00 +01:00
6
+ version: 0.2.2
7
+ date: 2007-07-06 00:00:00 +01:00
8
8
  summary: add description to your classes and make your ActiveRecord validations smarter
9
9
  require_paths:
10
10
  - lib