enumerate_it 0.7.12 → 0.7.13

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enumerate_it (0.7.12)
4
+ enumerate_it (0.7.13)
5
5
  activesupport (>= 2.3.2)
6
6
 
7
7
  GEM
@@ -21,6 +21,7 @@ GEM
21
21
  builder (2.1.2)
22
22
  diff-lcs (1.1.2)
23
23
  i18n (0.5.0)
24
+ rake (0.9.2.2)
24
25
  rspec (2.5.0)
25
26
  rspec-core (~> 2.5.0)
26
27
  rspec-expectations (~> 2.5.0)
@@ -37,4 +38,5 @@ PLATFORMS
37
38
  DEPENDENCIES
38
39
  activerecord (>= 3.0.5)
39
40
  enumerate_it!
41
+ rake
40
42
  rspec (>= 2.5.0)
data/README.rdoc CHANGED
@@ -225,7 +225,7 @@ located on enumerations.'enumeration_name'.'key' :
225
225
 
226
226
  You can also translate specific values:
227
227
 
228
- RelationshipStatis.t(1) # => 'Casado'
228
+ RelationshipStatus.t(1) # => 'Casado'
229
229
 
230
230
  == Installation
231
231
 
data/lib/enumerate_it.rb CHANGED
@@ -224,6 +224,10 @@ module EnumerateIt
224
224
  enumeration.values.map {|value| [translate(value[1]), value[0]] }.sort_by { |value| value[0] }
225
225
  end
226
226
 
227
+ def self.to_json
228
+ enumeration.values.collect {|value| { value: value[0], label: translate(value[1]) } }.to_json
229
+ end
230
+
227
231
  def self.t(value)
228
232
  target = to_a.detect { |item| item[1] == value }
229
233
  target ? target[0] : value
@@ -319,7 +323,7 @@ module EnumerateIt
319
323
  def create_scopes(klass, attribute_name)
320
324
  klass.enumeration.keys.each do |option|
321
325
  if respond_to? :scope
322
- scope option, where(attribute_name => klass.enumeration[option].first)
326
+ scope option, lambda { where(attribute_name => klass.enumeration[option].first)}
323
327
  end
324
328
  end
325
329
  end
@@ -1,3 +1,3 @@
1
1
  module EnumerateIt
2
- VERSION = "0.7.12"
2
+ VERSION = "0.7.13"
3
3
  end
@@ -232,6 +232,18 @@ describe EnumerateIt::Base do
232
232
  end
233
233
  end
234
234
 
235
+ describe ".to_json" do
236
+ it "gives a valid json back" do
237
+ I18n.locale = :inexsistent
238
+ TestEnumerationWithoutArray.to_json.should == '[{"value":"1","label":"Value One"},{"value":"2","label":"Value Two"}]'
239
+ end
240
+
241
+ it "give translated values when available" do
242
+ I18n.locale = :pt
243
+ TestEnumerationWithoutArray.to_json.should == '[{"value":"1","label":"Primeiro Valor"},{"value":"2","label":"Value Two"}]'
244
+ end
245
+ end
246
+
235
247
  describe ".t" do
236
248
  it "translates a given value" do
237
249
  I18n.locale = :pt
data/spec/spec_helper.rb CHANGED
@@ -7,5 +7,6 @@ require 'rspec/autorun'
7
7
  require 'rubygems'
8
8
  require "active_support"
9
9
  require "active_support/core_ext/string/inflections"
10
+ require 'active_support/core_ext/object/to_json'
10
11
 
11
12
  I18n.load_path = Dir['spec/i18n/*.yml']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.12
4
+ version: 0.7.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-16 00:00:00.000000000 Z
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &2164309620 !ruby/object:Gem::Requirement
16
+ requirement: &2163414300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: 2.3.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2164309620
24
+ version_requirements: *2163414300
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &2163413840 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2163413840
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- requirement: &2164309020 !ruby/object:Gem::Requirement
38
+ requirement: &2163412980 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: 2.5.0
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *2164309020
46
+ version_requirements: *2163412980
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: activerecord
38
- requirement: &2164308360 !ruby/object:Gem::Requirement
49
+ requirement: &2163412240 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,7 +54,7 @@ dependencies:
43
54
  version: 3.0.5
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *2164308360
57
+ version_requirements: *2163412240
47
58
  description: Have a legacy database and need some enumerations in your models to match
48
59
  those stupid '4 rows/2 columns' tables with foreign keys and stop doing joins just
49
60
  to fetch a simple description? Or maybe use some integers instead of strings as