attr_json 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attr_json/attribute_definition.rb +9 -2
- data/lib/attr_json/record.rb +1 -1
- data/lib/attr_json/type/model.rb +7 -4
- data/lib/attr_json/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80130e194fdf715bf967ea25fc6fff1d7e043f53479c1e539d9b9e2122233404
|
4
|
+
data.tar.gz: df2d7d442df1dfec49becd935321a0fbdc8aebec5892e34d84d415c4f5a87471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e2712bca13ff4fa2b874b5f141070cd5f8e5ab306c6ff9f5e41a7129c4a7b740f6ce0a79a7f9cdf759195cb1c7d144bd0d8ea7ef6d46682487f8d75a47a1c25
|
7
|
+
data.tar.gz: 1c86d1e8cea7a9413960fa357507fd5ba25e55c6f27820fb091bd8f4921c3aa7aa3274c90bd30f93b8cdde521d177d6a3cebe9154757038f2b30ba5cebbf970e
|
@@ -12,7 +12,9 @@
|
|
12
12
|
attr_reader :name, :type, :original_args, :container_attribute
|
13
13
|
|
14
14
|
# @param name [Symbol,String]
|
15
|
-
# @param type [Symbol,ActiveModel::Type::Value]
|
15
|
+
# @param type [Symbol,ActiveModel::Type::Value] Symbol is looked up in
|
16
|
+
# ActiveRecord::Type.lookup, but with `adapter: nil` for no custom
|
17
|
+
# adapter-specific lookup.
|
16
18
|
#
|
17
19
|
# @option options store_key [Symbol,String]
|
18
20
|
# @option options container_attribute [Symbol,ActiveModel::Type::Value]
|
@@ -40,7 +42,12 @@
|
|
40
42
|
# ActiveModel::Type.lookup may make more sense, but ActiveModel::Type::Date
|
41
43
|
# seems to have a bug with multi-param assignment. Mostly they return
|
42
44
|
# the same types, but ActiveRecord::Type::Date works with multi-param assignment.
|
43
|
-
|
45
|
+
#
|
46
|
+
# We pass `adapter: nil` to avoid triggering a db connection.
|
47
|
+
# See: https://github.com/jrochkind/attr_json/issues/41
|
48
|
+
# This is at the "cost" of not using any adapter-specific types... which
|
49
|
+
# maybe preferable anyway?
|
50
|
+
type = ActiveRecord::Type.lookup(type, adapter: nil)
|
44
51
|
elsif ! type.is_a? ActiveModel::Type::Value
|
45
52
|
raise ArgumentError, "Second argument (#{type}) must be a symbol or instance of an ActiveModel::Type::Value subclass"
|
46
53
|
end
|
data/lib/attr_json/record.rb
CHANGED
@@ -18,7 +18,7 @@ module AttrJson
|
|
18
18
|
extend ActiveSupport::Concern
|
19
19
|
|
20
20
|
included do
|
21
|
-
unless self
|
21
|
+
unless self <= ActiveRecord::Base
|
22
22
|
raise TypeError, "AttrJson::Record can only be used with an ActiveRecord::Base model. #{self} does not appear to be one. Are you looking for ::AttrJson::Model?"
|
23
23
|
end
|
24
24
|
|
data/lib/attr_json/type/model.rb
CHANGED
@@ -8,6 +8,8 @@ module AttrJson
|
|
8
8
|
# but normally that's only done in AttrJson::Model.to_type, there isn't
|
9
9
|
# an anticipated need to create from any other place.
|
10
10
|
class Model < ::ActiveModel::Type::Value
|
11
|
+
class BadCast < ArgumentError ; end
|
12
|
+
|
11
13
|
attr_accessor :model
|
12
14
|
def initialize(model)
|
13
15
|
#TODO type check, it really better be a AttrJson::Model. maybe?
|
@@ -34,10 +36,11 @@ module AttrJson
|
|
34
36
|
# TODO Maybe we ought not to do this on #to_h?
|
35
37
|
model.new_from_serializable(v.to_h)
|
36
38
|
else
|
37
|
-
# Bad input
|
38
|
-
#
|
39
|
-
#
|
40
|
-
|
39
|
+
# Bad input. Originally we were trying to return nil, to be like
|
40
|
+
# existing ActiveRecord which kind of silently does a basic value
|
41
|
+
# with null input. But that ended up making things confusing, let's
|
42
|
+
# just raise.
|
43
|
+
raise BadCast.new("Can not cast from #{v.inspect} to #{self.type}")
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
data/lib/attr_json/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
192
|
version: '0'
|
193
193
|
requirements: []
|
194
194
|
rubyforge_project:
|
195
|
-
rubygems_version: 2.7.
|
195
|
+
rubygems_version: 2.7.6
|
196
196
|
signing_key:
|
197
197
|
specification_version: 4
|
198
198
|
summary: ActiveRecord attributes stored serialized in a json column, super smooth.
|