enumerate 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0db9d3a63909d2f1e942fc7c9d72ee6df9129de4
4
- data.tar.gz: bac591dc7038aa835d7244bde5573f1e328fdcbd
3
+ metadata.gz: 7d919858d8c1c54b7566bafe2fa92f2277fe4509
4
+ data.tar.gz: b73bac61dd57eb7c67bd178672af1be33dda7949
5
5
  SHA512:
6
- metadata.gz: 781cedc5ede92afbdb33ba49cc4b659f7d61d0627c15ac76bf46e8c3bb2f0d26b27b3b955506b1ce540fca604d1d191c0f2d2abc4fd94fd85ef8857918b308ff
7
- data.tar.gz: cdb2002e9c61cc372c8093e7c00b9de5fdc2f77787c8bb150218232404c5aa99399631213e190de45bd089036fca5a31da80cd667bb6c06fb17f7eb97acb3ff9
6
+ metadata.gz: bbc00303f7ee43b06ce9756c4b3e44209afdde7279139130c524c471f389309451abec299e3a174f5c1367281b6eaa94e9e3ec300f568e422c9f031701b817fa
7
+ data.tar.gz: dc1efa39fb468eea0aefa6694604157fe4d571caf3c692707f73ba6d64d844d7fe765d36ec261374b0daf4fb58f3ea2fd9ae0f5606406cb49eb6b9ee976ea434
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ vendor
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- # Enumerate [![Build Status](https://secure.travis-ci.org/TwilightCoders/enumerate.png)](http://travis-ci.org/TwilightCoders/enumerate)
2
- # Enumerate [![Gem Version](https://badge.fury.io/rb/enumerate.png)](http://badge.fury.io/rb/enumerate)
1
+ # Enumerate [![Build Status](https://secure.travis-ci.org/TwilightCoders/enumerate.png)](http://travis-ci.org/TwilightCoders/enumerate) [![Gem Version](https://badge.fury.io/rb/enumerate.png)](http://badge.fury.io/rb/enumerate) [![Code Climate](https://codeclimate.com/github/TwilightCoders/enumerate.png)](https://codeclimate.com/github/TwilightCoders/enumerate)
3
2
 
4
3
  Enumerate adds an enum command to all ActiveRecord models which enables you to work with integer and string attributes as if they were enums
5
4
 
@@ -28,9 +28,9 @@ Gem::Specification.new do |s|
28
28
  s.require_paths = ["lib"]
29
29
 
30
30
  # specify any dependencies here; for example:
31
- s.add_development_dependency "rake"
32
- s.add_development_dependency "rspec"
33
- s.add_development_dependency "activerecord", '>= 3.0'
34
- s.add_development_dependency "sqlite3"
35
- s.add_development_dependency 'appraisal', '>= 0.3.8'
31
+ s.add_development_dependency "rake", '~> 0.9', '>= 0.9.3'
32
+ s.add_development_dependency 'rspec', '~> 2.3', '>= 2.3.0'
33
+ s.add_development_dependency 'activerecord', '~> 3.0', '>= 3.0.6'
34
+ s.add_development_dependency "sqlite3", '~> 1.3', '>= 1.3.3'
35
+ s.add_development_dependency 'appraisal', '~> 0.3', '>= 0.3.8'
36
36
  end
@@ -4,8 +4,13 @@ module Enumerate
4
4
 
5
5
  validates_inclusion_of attribute, :in => vals, :allow_nil => !!opts[:allow_nil]
6
6
 
7
+
7
8
  # Get the column type of the attribute. We support int and string
8
- col_type = self.columns_hash[attribute.to_s].type
9
+ if self.columns_hash[attribute.to_s].nil?
10
+ raise "Column '#{attribute}' does not exist in #{self.class.name}"
11
+ else
12
+ col_type = self.columns_hash[attribute.to_s].type
13
+ end
9
14
 
10
15
  const_hash_name = attribute.to_s.pluralize.upcase
11
16
 
@@ -44,31 +49,41 @@ module Enumerate
44
49
  unless methods.include?("#{attribute.to_s}=")
45
50
  self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
46
51
  def #{attribute.to_s}=(s)
47
- write_attribute(:#{attribute}, #{const_hash_name}[s.to_sym])
52
+ if (s.kind_of?(Fixnum))
53
+ write_attribute(:#{attribute}, s)
54
+ elsif (s.kind_of?(Symbol) or s.kind_of?(String))
55
+ # puts "changing to \#{s}"
56
+ write_attribute(:#{attribute}, #{const_hash_name}[s.to_sym])
57
+ # puts "is now \#{#{attribute}}"
58
+ end
48
59
  end
49
60
  RUBY
50
61
  end
51
62
  end
52
63
 
53
64
  def setup_predicates(vals, attribute)
54
- vals.each do |key, val|
55
- raise "Collision in enumeration predicate method(s) #{key}" if respond_to?("#{key.to_s}?") or respond_to?("#{key.to_s}!") or respond_to?("#{key.to_s}")
65
+ vals.each do |key, val|
66
+ raise "Collision in enumeration predicate method(s) #{key}" if respond_to?("#{key.to_s}?") or respond_to?("#{key.to_s}!") or respond_to?("not_#{key.to_s}?") or respond_to?("#{attribute.to_s}")
56
67
 
57
- define_method "#{key.to_s}?" do
58
- send("#{attribute.to_s}") == key
59
- end
68
+ define_method "#{key.to_s}?" do
69
+ send("#{attribute.to_s}") == key
70
+ end
71
+
72
+ define_method "not_#{key.to_s}?" do
73
+ send("#{attribute.to_s}") != key
74
+ end
60
75
 
61
- define_method "#{key.to_s}!" do
62
- send("#{attribute.to_s}=", key)
63
- end
76
+ define_method "#{key.to_s}!" do
77
+ send("#{attribute.to_s}=", key)
78
+ end
64
79
 
65
- # Define helper scopes
66
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
67
- scope :#{key}, lambda { where(:#{attribute} => #{val}) }
68
- RUBY
69
- end
80
+ # Define helper scopes
81
+ self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
82
+ scope :#{key}, lambda { where(:#{attribute} => #{val}) }
83
+ scope :not_#{key}, lambda { where("#{attribute} != #{val}") }
84
+ RUBY
85
+ end
70
86
  end
71
-
72
87
  end
73
88
 
74
89
  end
@@ -1,4 +1,4 @@
1
- module UrlFormatter
1
+ module Enumerate
2
2
  class Railtie < Rails::Railtie
3
3
  initializer 'enumerate.model' do
4
4
  ActiveSupport.on_load :active_record do
@@ -1,3 +1,3 @@
1
1
  module Enumerate
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -11,7 +11,7 @@ class OtherModel < ActiveRecord::Base
11
11
 
12
12
  belongs_to :model
13
13
 
14
- enumerate :status, [:active, :expired, :not_expired]
14
+ enumerate :status, [:active, :expired]
15
15
  end
16
16
 
17
17
  class ModelAllowingNil < ActiveRecord::Base
@@ -21,7 +21,7 @@ class ModelAllowingNil < ActiveRecord::Base
21
21
 
22
22
  belongs_to :model
23
23
 
24
- enumerate :status, [:active, :expired, :not_expired], :allow_nil => true
24
+ enumerate :status, [:active, :expired], :allow_nil => true
25
25
  end
26
26
 
27
27
 
@@ -37,7 +37,6 @@ describe :Enumerate do
37
37
 
38
38
  @active_obj = OtherModel.create!(:status => :active, :model => @obj)
39
39
  @expired_obj = OtherModel.create!(:status => :expired, :model => @canceled_obj)
40
- @not_expired_obj = OtherModel.create!(:status => :not_expired, :model => @canceled_obj)
41
40
  end
42
41
 
43
42
  describe "allow nil" do
@@ -65,11 +64,13 @@ describe :Enumerate do
65
64
  describe "short hand methods" do
66
65
  describe "question mark (?)" do
67
66
  it "should return true if value of enum equals a value" do
68
- @obj.available?.should be_true
67
+ @obj.available?.should be_true
68
+ @obj.not_canceled?.should be_true
69
69
  end
70
-
70
+
71
71
  it "should return false if value of enum is different " do
72
- @obj.canceled?.should be_false
72
+ @obj.canceled?.should be_false
73
+ @obj.not_available?.should be_false
73
74
  end
74
75
 
75
76
  end
@@ -81,9 +82,10 @@ describe :Enumerate do
81
82
  end
82
83
  end
83
84
 
84
- it "should have two shorthand methods for each possible value" do
85
- Model::STATUSES.each do |key, val|
86
- @obj.respond_to?("#{key}?").should be_true
85
+ it "should have three shorthand methods for each possible value" do
86
+ Model::STATUSES.each do |key, val|
87
+ @obj.respond_to?("#{key}?").should be_true
88
+ @obj.respond_to?("not_#{key}?").should be_true
87
89
  @obj.respond_to?("#{key}!").should be_true
88
90
  end
89
91
  end
@@ -91,9 +93,9 @@ describe :Enumerate do
91
93
 
92
94
  describe "getting value" do
93
95
  it "should always return the enums value as a symbol" do
94
- @obj.status.should == :available
96
+ @obj.status.kind_of?(Symbol).should be_true
95
97
  @obj.status = "canceled"
96
- @obj.status.should == :canceled
98
+ @obj.status.kind_of?(Symbol).should be_true
97
99
  end
98
100
 
99
101
  end
metadata CHANGED
@@ -1,83 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.9'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.3
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - '>='
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 0.9.3
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rspec
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - '>='
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.3'
40
+ - - ">="
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 2.3.0
34
43
  type: :development
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - '>='
47
+ - - "~>"
39
48
  - !ruby/object:Gem::Version
40
- version: '0'
49
+ version: '2.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: activerecord
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
- - - '>='
57
+ - - "~>"
46
58
  - !ruby/object:Gem::Version
47
59
  version: '3.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.6
48
63
  type: :development
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
52
- - - '>='
67
+ - - "~>"
53
68
  - !ruby/object:Gem::Version
54
69
  version: '3.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.0.6
55
73
  - !ruby/object:Gem::Dependency
56
74
  name: sqlite3
57
75
  requirement: !ruby/object:Gem::Requirement
58
76
  requirements:
59
- - - '>='
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '1.3'
80
+ - - ">="
60
81
  - !ruby/object:Gem::Version
61
- version: '0'
82
+ version: 1.3.3
62
83
  type: :development
63
84
  prerelease: false
64
85
  version_requirements: !ruby/object:Gem::Requirement
65
86
  requirements:
66
- - - '>='
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ - - ">="
67
91
  - !ruby/object:Gem::Version
68
- version: '0'
92
+ version: 1.3.3
69
93
  - !ruby/object:Gem::Dependency
70
94
  name: appraisal
71
95
  requirement: !ruby/object:Gem::Requirement
72
96
  requirements:
73
- - - '>='
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.3'
100
+ - - ">="
74
101
  - !ruby/object:Gem::Version
75
102
  version: 0.3.8
76
103
  type: :development
77
104
  prerelease: false
78
105
  version_requirements: !ruby/object:Gem::Requirement
79
106
  requirements:
80
- - - '>='
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.3'
110
+ - - ">="
81
111
  - !ruby/object:Gem::Version
82
112
  version: 0.3.8
83
113
  description: |2
@@ -93,8 +123,8 @@ executables: []
93
123
  extensions: []
94
124
  extra_rdoc_files: []
95
125
  files:
96
- - .gitignore
97
- - .travis.yml
126
+ - ".gitignore"
127
+ - ".travis.yml"
98
128
  - Gemfile
99
129
  - LICENSE
100
130
  - README.md
@@ -120,17 +150,17 @@ require_paths:
120
150
  - lib
121
151
  required_ruby_version: !ruby/object:Gem::Requirement
122
152
  requirements:
123
- - - '>='
153
+ - - ">="
124
154
  - !ruby/object:Gem::Version
125
155
  version: '0'
126
156
  required_rubygems_version: !ruby/object:Gem::Requirement
127
157
  requirements:
128
- - - '>='
158
+ - - ">="
129
159
  - !ruby/object:Gem::Version
130
160
  version: '0'
131
161
  requirements: []
132
162
  rubyforge_project:
133
- rubygems_version: 2.0.3
163
+ rubygems_version: 2.2.2
134
164
  signing_key:
135
165
  specification_version: 4
136
166
  summary: Enumerate adds an `enumerate` command to all ActiveRecord models, enabling