enumerated_field 0.3.5 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -79,6 +79,8 @@ these.
79
79
  => [['Pacific Crest Trail', 'pct'], ['Continental Divide Trail', 'cdt'], ['Superior Hiking Trail', 'sht']]
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
+ > Hike.trail_values_for_json # or get a has for injecting into JSON or wherever
83
+ => [{:display => 'Pacific Crest Trail', :value => 'pct'}, {:display => 'Continental Divide Trail', :value => 'cdt'}, {:display => 'Superior Hiking Trail', :value => 'sht'}]
82
84
 
83
85
  ### ActiveRecord Scopes
84
86
 
@@ -90,6 +92,12 @@ These scopes are only created when your object is an ActiveRecord model.
90
92
  # performs Hike.where(:duration => Hike::DURATION_LONG)
91
93
  > Hike.duration_long
92
94
 
95
+ # performs Hike.where(Hike.arel_table[:trail].not_eq(Hike::TRAIL_CDT))
96
+ > Hike.trail_not_cdt
97
+
98
+ # performs Hike.where(Hike.arel_table[:duration].not_eq(Hike::DURATION_LONG))
99
+ > Hike.duration_not_long
100
+
93
101
  ### Use Constants for Keys
94
102
 
95
103
  > Hike::TRAIL_PCT
@@ -1,3 +1,3 @@
1
1
  module EnumeratedField
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -90,6 +90,7 @@ module EnumeratedField
90
90
  if defined? ActiveRecord::Base and ancestors.include? ActiveRecord::Base
91
91
  values_hash.keys.each do |key|
92
92
  scope "#{field_name}_#{key}", where(field_name => key)
93
+ scope "#{field_name}_not_#{key}", where(arel_table[field_name].not_eq(key))
93
94
  end
94
95
  end
95
96
 
@@ -124,6 +124,7 @@ class EnumeratedFieldTest < Test::Unit::TestCase
124
124
  ['color', 'kind'].each do |column|
125
125
  subject.send("#{column}_values").each do |a,b|
126
126
  assert subject.respond_to? "#{column}_#{b}"
127
+ assert subject.respond_to? "#{column}_not_#{b}"
127
128
  assert subject.send("#{column}_#{b}").any?
128
129
  assert_equal 2, subject.send("#{column}_#{b}").size
129
130
  end
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.3.5
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-05-23 00:00:00.000000000 Z
14
+ date: 2012-05-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activemodel