enumerize 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcc222d35f7bc7e96f344ebac473c10324a42bd9
4
- data.tar.gz: 4509894cf1723e3df5403c8c93108c316b1ffbb1
3
+ metadata.gz: f5a43e5546fd78ed42c35abfccc3314e52b7671f
4
+ data.tar.gz: 727be0571656833f27ee73ff8d65d6455c7511e4
5
5
  SHA512:
6
- metadata.gz: b1237ba9ede67eefc02b235ec0b74ff2bc6774f89479c22e0e5733dba911b487449bf24e49e82a3be2623cfb432198d6cedf59425f26fab11e36c8c11c073769
7
- data.tar.gz: 98234b48c034f98cdd43e2379b8ad277dbad8d68088b3cabdfffe71767584028be87ead75629db81fc036862743e16bb5554c680f75d3aa22e814fada961c113
6
+ metadata.gz: 88cfa3f67475bf8d18279b7f53124051237c3a5bfe302e88860f5c405834cd95ebe9cfca67eb0d721c52ca746a15458cf284d2a376b049ede0b6b69379f667a6
7
+ data.tar.gz: f57a1bca5a058f2074d834968418865455f4e0ccf3aa2441064f05cb5901a4eb8ec4776cd2e95c938635a41659723679108d873caa338e8487879e91fbcafb25
@@ -4,6 +4,12 @@
4
4
 
5
5
  ### bug fix
6
6
 
7
+ ## 2.1.2 (May 18, 2017)
8
+
9
+ ### bug fix
10
+
11
+ * Support YAML serialization for the custom AR type. (by [@lest](https://github.com/lest))
12
+
7
13
  ## 2.1.1 (May 1, 2017)
8
14
 
9
15
  ### enhancements
@@ -90,6 +90,19 @@ module Enumerize
90
90
  def as_json(options = nil)
91
91
  {attr: @attr.name, subtype: @subtype}.as_json(options)
92
92
  end
93
+
94
+ def encode_with(coder)
95
+ coder[:class_name] = @attr.klass.name
96
+ coder[:attr_name] = @attr.name
97
+ coder[:subtype] = @subtype
98
+ end
99
+
100
+ def init_with(coder)
101
+ initialize(
102
+ coder[:class_name].constantize.enumerized_attributes[coder[:attr_name]],
103
+ coder[:subtype]
104
+ )
105
+ end
93
106
  end
94
107
  end
95
108
  end
@@ -1,6 +1,6 @@
1
1
  module Enumerize
2
2
  class Attribute
3
- attr_reader :name, :values, :default_value, :i18n_scope
3
+ attr_reader :klass, :name, :values, :default_value, :i18n_scope
4
4
 
5
5
  def initialize(klass, name, options={})
6
6
  raise ArgumentError, ':in option is required' unless options[:in]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enumerize
4
- VERSION = '2.1.1'
4
+ VERSION = '2.1.2'
5
5
  end
@@ -517,4 +517,9 @@ describe Enumerize::ActiveRecordSupport do
517
517
  type = User.type_for_attribute('status')
518
518
  type.as_json['attr'].must_equal 'status'
519
519
  end
520
+
521
+ it "doesn't break YAML serialization" do
522
+ user = YAML.load(User.create(status: :blocked).to_yaml)
523
+ user.status.must_equal 'blocked'
524
+ end
520
525
  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.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Nartimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-01 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport