enumlogic 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ == 1.0.1 relased 2009-09-01
2
+
3
+ * Allow nils
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :patch: 1
2
3
  :major: 1
3
4
  :minor: 0
4
- :patch: 0
data/enumlogic.gemspec ADDED
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{enumlogic}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["binarylogic"]
12
+ s.date = %q{2009-09-01}
13
+ s.description = %q{Adds enumerations to your models}
14
+ s.email = %q{bjohnson@binarylogic.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "CHANGELOG.rdoc",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION.yml",
27
+ "enumlogic.gemspec",
28
+ "lib/enumlogic.rb",
29
+ "spec/enumlogic_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/binarylogic/enumlogic}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubyforge_project = %q{enumlogic}
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{Adds enumerations to your models}
38
+ s.test_files = [
39
+ "spec/enumlogic_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<rspec>, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<rspec>, [">= 0"])
54
+ end
55
+ end
data/lib/enumlogic.rb CHANGED
@@ -39,11 +39,15 @@ module Enumlogic
39
39
  (class << self; self; end).send(:define_method, "#{field}_options") { new_hash }
40
40
 
41
41
  define_method("#{field}_key") do
42
- send(field).to_s.gsub(/[-\s]/, '_').downcase.to_sym
42
+ value = send(field)
43
+ return nil if value.nil?
44
+ value.to_s.gsub(/[-\s]/, '_').downcase.to_sym
43
45
  end
44
46
 
45
47
  define_method("#{field}_text") do
46
- values_hash.find { |key, text| key == send(field) }.last
48
+ value = send(field)
49
+ return nil if value.nil?
50
+ values_hash.find { |key, text| key == value }.last
47
51
  end
48
52
 
49
53
  values_array.each do |value|
@@ -54,7 +58,7 @@ module Enumlogic
54
58
  end
55
59
  end
56
60
 
57
- validates_inclusion_of field, :in => values_array, :message => message
61
+ validates_inclusion_of field, :in => values_array, :message => message, :allow_nil => options[:allow_nil]
58
62
  end
59
63
  end
60
64
 
@@ -69,4 +69,10 @@ describe "Enumlogic" do
69
69
  c.should_not be_valid
70
70
  c.errors[:kind].should include("kind is not included in the list")
71
71
  end
72
+
73
+ it "should allow nil during validations" do
74
+ Computer.enum :kind, ["apple", "dell", "hp"], :allow_nil => true
75
+ c = Computer.new
76
+ c.should be_valid
77
+ end
72
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - binarylogic
@@ -34,10 +34,12 @@ extra_rdoc_files:
34
34
  files:
35
35
  - .document
36
36
  - .gitignore
37
+ - CHANGELOG.rdoc
37
38
  - LICENSE
38
39
  - README.rdoc
39
40
  - Rakefile
40
41
  - VERSION.yml
42
+ - enumlogic.gemspec
41
43
  - lib/enumlogic.rb
42
44
  - spec/enumlogic_spec.rb
43
45
  - spec/spec_helper.rb