emp_json 1.3.0 → 1.4.0.pre.g2af295da5

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
  SHA256:
3
- metadata.gz: 25bc9fd422b25a7c170b13e139529cdb920407263eddfea6090ff8f5db26efcf
4
- data.tar.gz: 06211e95f73424b5223fb48777332369346d6ded8b9b1b2ee91271e013e97c87
3
+ metadata.gz: 0000730e028c2cdcce57ac6cecd0574b22bcf80d68f6f1fb196361ef15df4a53
4
+ data.tar.gz: e03477c1b347d1dc453001c6b4ef0ae15084840f5d3c6628d01ece770ca10ef0
5
5
  SHA512:
6
- metadata.gz: 627063d466d24b937749ef9a86dff810f09da1c3b51ed5160b7db71a8369e1e3e8af393f95dc2a3ec1bfb45b8ad763e341a2aeb27ae6a4e4d19b1939f772f89c
7
- data.tar.gz: 70af1948aaad44518cac9bb2e666aba0462186add2425bfaafe9661878d9ccf691efe7e1fd36d31e8741b0dceb8a743143138edebb0ca4a3d7f8aecfa6986471
6
+ metadata.gz: 2d949a1e98f9edd8ee029f9b491fdedafd02c385267cf5c6e5289793045de2c428f4a6e01e712766e6ba263c23098bcd7968a16d7f844443b7e832db1af9d4b3
7
+ data.tar.gz: 23aec55675f54967665264ffdf2e51c267affe0b473ba987bd3219628526fca91126d6efe9ce0609fc2cd4a33e9c68a3beaeb3f077fb2bb93bfd0138d3ffa5b5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- emp_json (1.3.0)
4
+ emp_json (1.4.0.pre.g2af295da5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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,9 @@ 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_FLOAT = "#{RDF_XSD}float"
33
+ RDF_XSD_DOUBLE = "#{RDF_XSD}double"
34
+ RDF_XSD_DECIMAL = "#{RDF_XSD}decimal"
31
35
 
32
36
  def object_to_value(value)
33
37
  return primitive_to_value(value.iri) if value.respond_to?(:iri)
@@ -59,7 +63,9 @@ module Empathy
59
63
  shorthand(EMP_TYPE_BOOL, value.to_s)
60
64
  when Integer
61
65
  integer_to_value(value)
62
- when Float, Numeric
66
+ when Float
67
+ shorthand(EMP_TYPE_DOUBLE, value.to_s)
68
+ when Numeric
63
69
  use_rdf_rb_for_primitive(value)
64
70
  when RDF::Literal
65
71
  rdf_literal_to_value(value)
@@ -79,7 +85,7 @@ module Empathy
79
85
  end
80
86
  end
81
87
 
82
- def rdf_literal_to_value(value) # rubocop:disable Metrics/AbcSize
88
+ def rdf_literal_to_value(value) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
83
89
  case value.datatype.to_s
84
90
  when RDF_RDFV_LANGSTRING
85
91
  {
@@ -95,10 +101,14 @@ module Empathy
95
101
  shorthand(EMP_TYPE_DATETIME, value.value)
96
102
  when RDF_XSD_BOOLEAN
97
103
  shorthand(EMP_TYPE_BOOL, value.value)
104
+ when RDF_XSD_DOUBLE
105
+ shorthand(EMP_TYPE_DOUBLE, value.value)
106
+ when RDF_XSD_DECIMAL, RDF_XSD_FLOAT
107
+ primitive(value.datatype.to_s, value.value)
98
108
  when RDF_XSD_INTEGER
99
109
  integer_to_value(value.to_i)
100
110
  else
101
- throw "unknown RDF::Literal"
111
+ throw "unknown RDF::Literal: #{value.datatype}"
102
112
  end
103
113
  end
104
114
 
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Empathy
4
4
  module EmpJson
5
- VERSION = "1.3.0"
5
+ VERSION = "1.4.0"
6
6
  end
7
7
  end
@@ -10,9 +10,21 @@ require "empathy/emp_json/serializer"
10
10
 
11
11
  module Empathy
12
12
  module EmpJson
13
- SUPPORTS_RDF_RB = Object.const_defined?("RDF")
14
- SUPPORTS_SEQUENCE = Object.const_defined?("LinkedRails")
15
- SUPPORTS_AR = Object.const_defined?("ActiveRecord")
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,12 @@ module Empathy
42
44
 
43
45
  RDF_XSD_INTEGER: "http://www.w3.org/2001/XMLSchema#integer"
44
46
 
47
+ RDF_XSD_FLOAT: "http://www.w3.org/2001/XMLSchema#float"
48
+
49
+ RDF_XSD_DOUBLE: "http://www.w3.org/2001/XMLSchema#double"
50
+
51
+ RDF_XSD_DECIMAL: "http://www.w3.org/2001/XMLSchema#decimal"
52
+
45
53
  type shorthand = { type: string, v: string }
46
54
  type primitive = { type: string, dt: string, v: string }
47
55
 
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.3.0
4
+ version: 1.4.0.pre.g2af295da5
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-02 00:00:00.000000000 Z
11
+ date: 2022-08-17 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: '0'
80
+ version: 1.3.1
81
81
  requirements: []
82
82
  rubygems_version: 3.3.7
83
83
  signing_key: