enumerated_field 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,6 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - ree
5
- - jruby
6
5
  - ruby-head
7
6
  - rbx-2.0
8
7
  notifications:
@@ -0,0 +1,67 @@
1
+
2
+ v0.0.2
3
+
4
+ * bumped version
5
+ * added allow_blank choice for validation
6
+ * added :allow_nil => true choice to accept nil values for validation
7
+ * more tweaks to the README
8
+ * added README entry for the constants
9
+ * cleaning up validation test descriptions
10
+ * added constants for the enumerated keys
11
+ * merged add_validation into master
12
+ * updated validation tests to use shoulda
13
+ * merged master, with jon's additions, into branch
14
+ * Merge pull request #1 from jonkarna/master
15
+ * switched from not validating by default to validation by default
16
+ * cleared TODO
17
+ * add activemodel as a dependency (for validations)
18
+ * updated readme and included validation information
19
+ * Added rake test to make executing tests easier
20
+ * Added test for the #{field_name}_values class method. Reformatted existing tests to use shoulda.
21
+ * Added turn and shoulda to development dependencies to spice up the testing
22
+ * Forgot to pass options as a splat within the instance method
23
+ * Added (field_name)_values method to class
24
+ * moved ActiveModel from the module to the test since it is a development dependency, not a dependency of the gem
25
+ * testing the contra example that unless you specify to validate, it won't
26
+ * added TODO
27
+ * added capability to validate that the value is in the enumerated list
28
+
29
+ v0.0.3
30
+
31
+ * bumped version
32
+ * added code to handle creating constants from constant-unsafe keys
33
+
34
+ v0.0.4
35
+
36
+ * bumped gem version
37
+ * fixed error about undefined method validates in Apple
38
+ * Merge pull request #2 from jonkarna/master
39
+ * Added test for validating a string value that has an equivalent value in the enumerated field key list
40
+ * Added string equivalent of symbol key to validation and vice versa
41
+
42
+ v0.1.0
43
+
44
+ * bumped to version 0.1.0
45
+ * Updated gem to handle strings and symbols as equivalent keys
46
+
47
+ v0.2.0
48
+
49
+ * Bumped version number
50
+ * added jon and me to the list of authors
51
+ * tweaking who gets alerted from travis-ci
52
+ * tweaking which rubies to target
53
+ * trying again to trigger travis
54
+ * adding travis configuration
55
+ * triggering travis-ci
56
+ * More comprehensive active record scope test
57
+ * Made test the default rake task, in prep for integration with Travis CI
58
+ * Moved models to test_helper
59
+ * Apple fixture file
60
+ * Changed Apple to be an ActiveRecord model. Moved models to test_helper. Loading fixtures.
61
+ * Added section of code for adding scopes if a decendent from ActiveRecord::Base
62
+ * Added activerecord and sqlite3 to dev dependencies
63
+ * hard-wrap README
64
+ * add activesupport to gem dependencies
65
+ * tests pass with ruby 1.9
66
+ * fix test load path for ruby 1.9
67
+ * changed to use class_eval for the values_array
data/README.md CHANGED
@@ -80,6 +80,16 @@ these.
80
80
  > Hike.trail_values # or get it from the class instead of the instance, if you like
81
81
  => [['Pacific Crest Trail', 'pct'], ['Continental Divide Trail', 'cdt'], ['Superior Hiking Trail', 'sht']]
82
82
 
83
+ ### ActiveRecord Scopes
84
+
85
+ These scopes are only created when your object is an ActiveRecord model.
86
+
87
+ # performs Hike.where(:trail => Hike::TRAIL_CDT)
88
+ > Hike.trail_cdt
89
+
90
+ # performs Hike.where(:duration => Hike::DURATION_LONG)
91
+ > Hike.duration_long
92
+
83
93
  ### Use Constants for Keys
84
94
 
85
95
  > Hike::TRAIL_PCT
@@ -87,6 +97,22 @@ these.
87
97
  > Hike::TRAIL_SHT
88
98
  => :sht
89
99
 
100
+ ### Display Specified Value
101
+
102
+ > hike.trail_display_for("sht")
103
+ => "Superior Hiking Trail"
104
+
105
+ > hike.duration_display_for("short")
106
+ => "Short"
107
+
108
+ ### Value for Specified Display
109
+
110
+ > hike.trail_value_for("Superior Hiking Trail")
111
+ => "sht"
112
+
113
+ > hike.duration_value_for("Short")
114
+ => "short"
115
+
90
116
  These methods are all prefixed with the field name by design, which
91
117
  allows multiple fields on a model to exist which potentially have the
92
118
  same values.
@@ -11,7 +11,7 @@ module EnumeratedField
11
11
 
12
12
  # ex. enum_field(:league, [['National Football League', :nfl], ['Major League Baseball', :mlb]])
13
13
  # field_name typically corresponds to the database column name
14
- # values_array is a double array (not a hash to preserve order for when order matters.. ie select options)
14
+ # values_array is a double array (not a hash to preserve order for when order matters.. ie select options)
15
15
  def enum_field(field_name, values_array, options = {})
16
16
  values_hash = ActiveSupport::HashWithIndifferentAccess.new
17
17
  values_array.each { |value, key| values_hash[key] = value }
@@ -51,7 +51,7 @@ module EnumeratedField
51
51
  :allow_nil => options[:allow_nil], :allow_blank => options[:allow_blank]
52
52
  end
53
53
 
54
- values_hash.each do |key, value|
54
+ values_array.each do |value, key|
55
55
  const_name = "#{field_name}_#{key}".upcase.gsub(/[^\w_]/, "_").to_sym
56
56
  const_set(const_name, key)
57
57
  end
@@ -1,3 +1,3 @@
1
1
  module EnumeratedField
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -17,8 +17,8 @@ class EnumeratedFieldTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  should 'create contstants for the field keys' do
20
- assert_equal "chiquita", Banana::BRAND_CHIQUITA
21
- assert_equal "delmonte", Banana::BRAND_DELMONTE
20
+ assert_equal :chiquita, Banana::BRAND_CHIQUITA
21
+ assert_equal :delmonte, Banana::BRAND_DELMONTE
22
22
  end
23
23
 
24
24
  should 'create underscored constants from field keys which contain invalid constant name characters' do
@@ -59,6 +59,7 @@ class EnumeratedFieldTest < Test::Unit::TestCase
59
59
 
60
60
  should 'have 2 values without first option' do
61
61
  assert_equal @red_apple.color_values.length, 2
62
+ assert_equal @red_apple.color_values, [['Red', :red], ['Green', :green]]
62
63
  end
63
64
 
64
65
  should 'have 3 values with first option' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerated_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,12 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-30 00:00:00.000000000 -05:00
15
- default_executable:
14
+ date: 2011-10-05 00:00:00.000000000Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: activemodel
19
- requirement: &2157839460 !ruby/object:Gem::Requirement
18
+ requirement: &2153550040 !ruby/object:Gem::Requirement
20
19
  none: false
21
20
  requirements:
22
21
  - - ! '>='
@@ -24,10 +23,10 @@ dependencies:
24
23
  version: '0'
25
24
  type: :runtime
26
25
  prerelease: false
27
- version_requirements: *2157839460
26
+ version_requirements: *2153550040
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: activesupport
30
- requirement: &2157838800 !ruby/object:Gem::Requirement
29
+ requirement: &2153549260 !ruby/object:Gem::Requirement
31
30
  none: false
32
31
  requirements:
33
32
  - - ! '>='
@@ -35,10 +34,10 @@ dependencies:
35
34
  version: '0'
36
35
  type: :runtime
37
36
  prerelease: false
38
- version_requirements: *2157838800
37
+ version_requirements: *2153549260
39
38
  - !ruby/object:Gem::Dependency
40
39
  name: rake
41
- requirement: &2157838060 !ruby/object:Gem::Requirement
40
+ requirement: &2153548240 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
44
43
  - - ! '>='
@@ -46,10 +45,10 @@ dependencies:
46
45
  version: '0'
47
46
  type: :development
48
47
  prerelease: false
49
- version_requirements: *2157838060
48
+ version_requirements: *2153548240
50
49
  - !ruby/object:Gem::Dependency
51
50
  name: bundler
52
- requirement: &2157837460 !ruby/object:Gem::Requirement
51
+ requirement: &2153546240 !ruby/object:Gem::Requirement
53
52
  none: false
54
53
  requirements:
55
54
  - - ! '>='
@@ -57,10 +56,10 @@ dependencies:
57
56
  version: '0'
58
57
  type: :development
59
58
  prerelease: false
60
- version_requirements: *2157837460
59
+ version_requirements: *2153546240
61
60
  - !ruby/object:Gem::Dependency
62
61
  name: turn
63
- requirement: &2157836860 !ruby/object:Gem::Requirement
62
+ requirement: &2153545020 !ruby/object:Gem::Requirement
64
63
  none: false
65
64
  requirements:
66
65
  - - ! '>='
@@ -68,10 +67,10 @@ dependencies:
68
67
  version: '0'
69
68
  type: :development
70
69
  prerelease: false
71
- version_requirements: *2157836860
70
+ version_requirements: *2153545020
72
71
  - !ruby/object:Gem::Dependency
73
72
  name: shoulda
74
- requirement: &2157836200 !ruby/object:Gem::Requirement
73
+ requirement: &2153544100 !ruby/object:Gem::Requirement
75
74
  none: false
76
75
  requirements:
77
76
  - - ! '>='
@@ -79,10 +78,10 @@ dependencies:
79
78
  version: '0'
80
79
  type: :development
81
80
  prerelease: false
82
- version_requirements: *2157836200
81
+ version_requirements: *2153544100
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: activerecord
85
- requirement: &2157835540 !ruby/object:Gem::Requirement
84
+ requirement: &2153542200 !ruby/object:Gem::Requirement
86
85
  none: false
87
86
  requirements:
88
87
  - - ! '>='
@@ -90,10 +89,10 @@ dependencies:
90
89
  version: '0'
91
90
  type: :development
92
91
  prerelease: false
93
- version_requirements: *2157835540
92
+ version_requirements: *2153542200
94
93
  - !ruby/object:Gem::Dependency
95
94
  name: sqlite3
96
- requirement: &2157834860 !ruby/object:Gem::Requirement
95
+ requirement: &2153541380 !ruby/object:Gem::Requirement
97
96
  none: false
98
97
  requirements:
99
98
  - - ! '>='
@@ -101,7 +100,7 @@ dependencies:
101
100
  version: '0'
102
101
  type: :development
103
102
  prerelease: false
104
- version_requirements: *2157834860
103
+ version_requirements: *2153541380
105
104
  description: EnumeratedField is a library that provides some nice methods when a string
106
105
  column is used like an enumeration, meaning there is a list of allowable values
107
106
  for the string column.
@@ -115,6 +114,7 @@ extra_rdoc_files: []
115
114
  files:
116
115
  - .gitignore
117
116
  - .travis.yml
117
+ - CHANGELOG
118
118
  - Gemfile
119
119
  - README.md
120
120
  - Rakefile
@@ -124,7 +124,6 @@ files:
124
124
  - test/enumerated_field_test.rb
125
125
  - test/fixtures/apples.yml
126
126
  - test/test_helper.rb
127
- has_rdoc: true
128
127
  homepage: https://github.com/tstmedia/enumerated_field
129
128
  licenses: []
130
129
  post_install_message:
@@ -139,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
138
  version: '0'
140
139
  segments:
141
140
  - 0
142
- hash: 1613582628289302536
141
+ hash: -3545795576421567660
143
142
  required_rubygems_version: !ruby/object:Gem::Requirement
144
143
  none: false
145
144
  requirements:
@@ -148,10 +147,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
147
  version: '0'
149
148
  segments:
150
149
  - 0
151
- hash: 1613582628289302536
150
+ hash: -3545795576421567660
152
151
  requirements: []
153
152
  rubyforge_project: enumerated_field
154
- rubygems_version: 1.6.2
153
+ rubygems_version: 1.8.6
155
154
  signing_key:
156
155
  specification_version: 3
157
156
  summary: EnumeratedField is a library that provides some nice methods when a string