has_constant 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.8.2
data/has_constant.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_constant}
8
- s.version = "0.8.1"
8
+ s.version = "0.8.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mattbeedle"]
12
- s.date = %q{2011-04-24}
12
+ s.date = %q{2011-05-13}
13
13
  s.description = %q{Allows certain fields to be limited to a set of values}
14
14
  s.email = %q{mattbeedle@gmail.com}
15
15
  s.extra_rdoc_files = [
data/lib/has_constant.rb CHANGED
@@ -65,7 +65,11 @@ module HasConstant
65
65
  end
66
66
 
67
67
  define_method("#{singular}_is?") do |value|
68
- send(singular) == value.to_s
68
+ truth = send(singular) == value.to_s
69
+ if !truth && I18n.locale.to_s != 'en'
70
+ truth = I18n.with_locale(:en) { send(singular) == value.to_s }
71
+ end
72
+ truth
69
73
  end
70
74
 
71
75
  define_method("#{singular}_is_not?") do |value|
@@ -73,7 +77,11 @@ module HasConstant
73
77
  end
74
78
 
75
79
  define_method("#{singular}_in?") do |value_list|
76
- value_list.include? send(singular)
80
+ truth = value_list.include? send(singular)
81
+ if !truth && I18n.locale.to_s != 'en'
82
+ truth = I18n.with_locale(:en) { value_list.include?(send(singular)) }
83
+ end
84
+ truth
77
85
  end
78
86
 
79
87
  define_method("#{singular}_not_in?") do |value_list|
@@ -43,8 +43,14 @@ module HasConstant
43
43
  named_scope :by_constant, lambda { |constant, value|
44
44
  if self.send(constant.pluralize).respond_to?(:key)
45
45
  value_for_query = self.send(constant.pluralize).key(value)
46
+ value_for_query ||= I18n.with_locale(:en) do
47
+ self.send(constant.pluralize).key(value)
48
+ end
46
49
  else
47
50
  value_for_query = self.send(constant.pluralize).index(value)
51
+ value_for_query ||= I18n.with_locale(:en) do
52
+ send(contant.pluralize).index(value)
53
+ end
48
54
  end
49
55
  where(constant.to_sym => value_for_query)
50
56
  }
@@ -120,21 +126,26 @@ module HasConstant
120
126
  define_method "#{singular}_is".to_sym do |values|
121
127
  values = values.lines.to_a if values.respond_to?(:lines)
122
128
  where(singular.to_sym.in => values.map do |v|
123
- options = self.send(name.to_sym)
124
- if options.respond_to?(:key)
125
- options.key(v)
129
+ if send(name).respond_to?(:key)
130
+ send(name).key(v) || I18n.with_locale(:en) { send(name).key(v) }
126
131
  else
127
- options.index(v)
132
+ send(name).index(v) || I18n.with_locale(:en) { send(name).key(v) }
128
133
  end
129
134
  end)
130
135
  end
131
136
 
132
137
  define_method "#{singular}_is_not".to_sym do |values|
133
138
  values = values.lines.to_a if values.respond_to?(:lines)
134
- if self.send(plural).respond_to?(:key)
135
- values_for_query = values.map { |v| self.send(plural).key(v) }
139
+ if send(plural).respond_to?(:key)
140
+ values_for_query = values.map { |v| send(plural).key(v) }.compact
141
+ values_for_query = values.map do |v|
142
+ I18n.with_locale(:en) { send(plural).key(v) }
143
+ end.compact if values_for_query.blank?
136
144
  else
137
- values_for_query = values.map { |v| self.send(plural).index(v) }
145
+ values_for_query = values.map { |v| send(plural).index(v) }.compact
146
+ values_for_query = values.map do |v|
147
+ I18n.with_locale(:en) { send(plural).index(v) }
148
+ end.compact if values_for_query.blank?
138
149
  end
139
150
  where(singular.to_sym.nin => values_for_query)
140
151
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_constant
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 1
10
- version: 0.8.1
9
+ - 2
10
+ version: 0.8.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - mattbeedle
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-24 00:00:00 +02:00
18
+ date: 2011-05-13 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency