emp_json 1.3.0 → 1.4.0.pre.g41bf02753
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/empathy/emp_json/helpers/primitives.rb +12 -3
- data/lib/empathy/emp_json/serializer/fields.rb +1 -1
- data/lib/empathy/emp_json/version.rb +1 -1
- data/lib/empathy/emp_json.rb +15 -3
- data/sig/lib/empathy/emp_json/helpers/primitives.rbs +6 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5f8e3136621bfd8b2017c23529c955ff84635a5cd42e2da36628adb039b67e6
|
4
|
+
data.tar.gz: d780b6c30a993811b1c3b9547d63bdf2583480379a4c4fa77d000208d7e6fd7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 788b38c53b9917a2f5f82d3302190d5ddeebace976b4ebd5d1b348855f538314e30d3abb3c7b90434ba809a31b166f6a41a47748cddf541b5449f4fa31a311e2
|
7
|
+
data.tar.gz: efa78974a239b2cb38aa2aab182849d3a1024c060398ae036dcbf57203b9b7604a452724aaa793608a94ae50e7d1659811826e202e3a196636b2ceaf80aca617
|
data/Gemfile.lock
CHANGED
@@ -14,6 +14,7 @@ module Empathy
|
|
14
14
|
EMP_TYPE_STRING = "s"
|
15
15
|
EMP_TYPE_BOOL = "b"
|
16
16
|
EMP_TYPE_INTEGER = "i"
|
17
|
+
EMP_TYPE_DOUBLE = "d"
|
17
18
|
EMP_TYPE_LONG = "l"
|
18
19
|
EMP_TYPE_PRIMITIVE = "p"
|
19
20
|
EMP_TYPE_LANGSTRING = "ls"
|
@@ -28,6 +29,8 @@ module Empathy
|
|
28
29
|
RDF_XSD_DATETIME = "#{RDF_XSD}dateTime"
|
29
30
|
RDF_XSD_BOOLEAN = "#{RDF_XSD}boolean"
|
30
31
|
RDF_XSD_INTEGER = "#{RDF_XSD}integer"
|
32
|
+
RDF_XSD_DECIMAL = "#{RDF_XSD}decimal"
|
33
|
+
RDF_XSD_DOUBLE = "#{RDF_XSD}double"
|
31
34
|
|
32
35
|
def object_to_value(value)
|
33
36
|
return primitive_to_value(value.iri) if value.respond_to?(:iri)
|
@@ -59,7 +62,9 @@ module Empathy
|
|
59
62
|
shorthand(EMP_TYPE_BOOL, value.to_s)
|
60
63
|
when Integer
|
61
64
|
integer_to_value(value)
|
62
|
-
when Float
|
65
|
+
when Float
|
66
|
+
shorthand(EMP_TYPE_DOUBLE, value.to_s)
|
67
|
+
when Numeric
|
63
68
|
use_rdf_rb_for_primitive(value)
|
64
69
|
when RDF::Literal
|
65
70
|
rdf_literal_to_value(value)
|
@@ -79,7 +84,7 @@ module Empathy
|
|
79
84
|
end
|
80
85
|
end
|
81
86
|
|
82
|
-
def rdf_literal_to_value(value) # rubocop:disable Metrics/AbcSize
|
87
|
+
def rdf_literal_to_value(value) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
83
88
|
case value.datatype.to_s
|
84
89
|
when RDF_RDFV_LANGSTRING
|
85
90
|
{
|
@@ -95,10 +100,14 @@ module Empathy
|
|
95
100
|
shorthand(EMP_TYPE_DATETIME, value.value)
|
96
101
|
when RDF_XSD_BOOLEAN
|
97
102
|
shorthand(EMP_TYPE_BOOL, value.value)
|
103
|
+
when RDF_XSD_DOUBLE
|
104
|
+
shorthand(EMP_TYPE_DOUBLE, value.value)
|
105
|
+
when RDF_XSD_DECIMAL
|
106
|
+
primitive(value.datatype.to_s, value.value)
|
98
107
|
when RDF_XSD_INTEGER
|
99
108
|
integer_to_value(value.to_i)
|
100
109
|
else
|
101
|
-
throw "unknown RDF::Literal"
|
110
|
+
throw "unknown RDF::Literal: #{value.datatype}"
|
102
111
|
end
|
103
112
|
end
|
104
113
|
|
@@ -58,7 +58,7 @@ module Empathy
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def value_for_attribute(attr, resource, serialization_params)
|
61
|
-
return resource.try(attr.method) if attr.method.is_a?(Symbol)
|
61
|
+
return resource.try(attr.method) if attr.method.is_a?(Symbol) || attr.method.is_a?(String)
|
62
62
|
|
63
63
|
FastJsonapi.call_proc(attr.method, resource, serialization_params)
|
64
64
|
end
|
data/lib/empathy/emp_json.rb
CHANGED
@@ -10,9 +10,21 @@ require "empathy/emp_json/serializer"
|
|
10
10
|
|
11
11
|
module Empathy
|
12
12
|
module EmpJson
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# Class for checking if certain gems are present
|
14
|
+
class SupportChecker
|
15
|
+
class << self
|
16
|
+
def check(gem)
|
17
|
+
require gem
|
18
|
+
true
|
19
|
+
rescue LoadError
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
SUPPORTS_RDF_RB = SupportChecker.check("rdf")
|
26
|
+
SUPPORTS_SEQUENCE = SupportChecker.check("linked_rails")
|
27
|
+
SUPPORTS_AR = SupportChecker.check("active_record")
|
16
28
|
|
17
29
|
class Error < StandardError; end
|
18
30
|
end
|
@@ -16,6 +16,8 @@ module Empathy
|
|
16
16
|
|
17
17
|
EMP_TYPE_INTEGER: "i"
|
18
18
|
|
19
|
+
EMP_TYPE_DOUBLE: "d"
|
20
|
+
|
19
21
|
EMP_TYPE_LONG: "l"
|
20
22
|
|
21
23
|
EMP_TYPE_PRIMITIVE: "p"
|
@@ -42,6 +44,10 @@ module Empathy
|
|
42
44
|
|
43
45
|
RDF_XSD_INTEGER: "http://www.w3.org/2001/XMLSchema#integer"
|
44
46
|
|
47
|
+
RDF_XSD_DECIMAL: "http://www.w3.org/2001/XMLSchema#decimal"
|
48
|
+
|
49
|
+
RDF_XSD_DOUBLE: "http://www.w3.org/2001/XMLSchema#double"
|
50
|
+
|
45
51
|
type shorthand = { type: string, v: string }
|
46
52
|
type primitive = { type: string, dt: string, v: string }
|
47
53
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emp_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0.pre.g41bf02753
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom van Kalkeren
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Serializer for the EmpJson specification.
|
14
14
|
email:
|
@@ -75,9 +75,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: 2.7.0.preview1
|
76
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: 1.3.1
|
81
81
|
requirements: []
|
82
82
|
rubygems_version: 3.3.7
|
83
83
|
signing_key:
|