enumerize 2.0.1 → 2.1.0

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: 1b707373f1cda45d2a21fd4f4b6fa2e512e94d0c
4
- data.tar.gz: 989f1bbf21977dd0ab191ed2a41d865193702b82
3
+ metadata.gz: 1e11fc29306be657be93429d810d7d38d15633f7
4
+ data.tar.gz: 2d2f0590533e31c71432f9f1a35e0cf8e8120f50
5
5
  SHA512:
6
- metadata.gz: 55c9e20ec4db7a12db817177e8de84caa23659186312418bba4c8f96df5acde2cbea01f68485884e315dae24bbec36d4d4485dc8013591be9cae26e638f44abd
7
- data.tar.gz: 6c592bfc03f5187f9caa8a07138ea16107a37fe037c610dfe8e4cf9e71b42e88e2a89181014a1074d57b07d234bd70b80663c33b7bc43017caa2731b8403ab7c
6
+ metadata.gz: d1a583881a025b925000573c7602bbdd118485544c4fa5f3b08cc740c12e780b297013b5ccee04b4d49a1d9fbb93e7691ac0cc5f9c203fefc587cba9f35cccc3
7
+ data.tar.gz: 738971e9f0f3b253df6ae23c9d36fdf628b543cfafc8304b90b871f896b131ff491d35a1b92e81f6d34b4f3d69f97afa7798ddf6adb80a99a9835c0ed410c084
@@ -7,12 +7,18 @@ gemfile:
7
7
  - Gemfile.rails42
8
8
  - Gemfile.mongo_mapper
9
9
  rvm:
10
- - 2.2.5
11
- - 2.3.1
12
- - jruby-9.1.2.0
10
+ - 2.2.6
11
+ - 2.3.3
12
+ - ruby-head
13
+ - jruby-9.1.6.0
13
14
  matrix:
14
15
  allow_failures:
15
- - gemfile: Gemfile
16
- rvm: jruby-9.1.2.0
16
+ - gemfile: Gemfile.rails42
17
+ rvm: ruby-head
18
+ - gemfile: Gemfile.mongo_mapper
19
+ rvm: ruby-head
20
+ branches:
21
+ only:
22
+ - master
17
23
  notifications:
18
24
  email: false
@@ -4,6 +4,12 @@
4
4
 
5
5
  ### bug fix
6
6
 
7
+ ## 2.1.0 (March 31, 2017)
8
+
9
+ ### enhancements
10
+
11
+ * Support Active Record types serialization. (by [@lest](https://github.com/lest))
12
+
7
13
  ## 2.0.1 (October 18, 2016)
8
14
 
9
15
  ### bug fix
@@ -17,6 +17,12 @@ module Enumerize
17
17
 
18
18
  # https://github.com/brainspec/enumerize/issues/111
19
19
  require 'enumerize/hooks/uniqueness'
20
+
21
+ unless options[:multiple]
22
+ decorate_attribute_type(name, :enumerize) do |subtype|
23
+ Type.new(enumerized_attributes[name], subtype)
24
+ end
25
+ end
20
26
  end
21
27
  end
22
28
  end
@@ -59,5 +65,19 @@ module Enumerize
59
65
  super(updates)
60
66
  end
61
67
  end
68
+
69
+ class Type < ActiveRecord::Type::Value
70
+ delegate :type, to: :@subtype
71
+
72
+ def initialize(attr, subtype)
73
+ @attr = attr
74
+ @subtype = subtype
75
+ end
76
+
77
+ def serialize(value)
78
+ v = @attr.find_value(value)
79
+ v && v.value
80
+ end
81
+ end
62
82
  end
63
83
  end
@@ -1,3 +1,3 @@
1
1
  module Enumerize
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -469,4 +469,13 @@ describe Enumerize::ActiveRecordSupport do
469
469
  user.reload
470
470
  user.status.must_equal nil
471
471
  end
472
+
473
+ it 'supports AR types serialization' do
474
+ User.delete_all
475
+
476
+ type = User.type_for_attribute('status')
477
+ type.must_be_instance_of Enumerize::ActiveRecordSupport::Type
478
+ serialized = type.serialize('blocked')
479
+ serialized.must_equal 2
480
+ end
472
481
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerize
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Nartimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.5.1
110
+ rubygems_version: 2.6.11
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support