safrano 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/odata/edm/primitive_types.rb +8 -2
- data/lib/odata/entity.rb +5 -1
- data/lib/odata/model_ext.rb +10 -3
- data/lib/safrano/service.rb +5 -2
- data/lib/safrano/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64699787371f5e9f696461faac80382cf2d53fe78d387742d8650e5a4b2c54df
|
4
|
+
data.tar.gz: 530e7619b4b27a1a50a63f832d4f3a8894850c6cea36e638769cdffbc6b7d942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d118f15a3a3ba78f5385867c82370e36612585b7f83329343babb2e3a8a7220d1059ad766fbe7c9e1f7f74a57945c086e60624d0301259c1427f0053b59052
|
7
|
+
data.tar.gz: 52b283be3e8902226f14864a74eae30bc62c65908be748ea37c5a150f574f3130c8957f26251e1958e298eba221eeada9f0155fcc73ed2591034e97466f1e629
|
@@ -20,13 +20,15 @@ module Safrano
|
|
20
20
|
# cf. Sequel Database column_schema_default_to_ruby_value
|
21
21
|
# schema_column_type
|
22
22
|
# https://www.odata.org/documentation/odata-version-2-0/overview/
|
23
|
-
def self.default_edm_type(ruby_type:)
|
23
|
+
def self.default_edm_type(ruby_type:, db_type: )
|
24
24
|
case ruby_type
|
25
25
|
when :integer
|
26
26
|
'Edm.Int32'
|
27
27
|
when :string
|
28
28
|
'Edm.String'
|
29
|
-
when :date
|
29
|
+
when :date
|
30
|
+
'Edm.DateTime'
|
31
|
+
when :datetime
|
30
32
|
'Edm.DateTime'
|
31
33
|
when :time
|
32
34
|
'Edm.Time'
|
@@ -38,6 +40,10 @@ module Safrano
|
|
38
40
|
'Edm.Decimal'
|
39
41
|
when :blob
|
40
42
|
'Edm.Binary'
|
43
|
+
else # try with db_type:
|
44
|
+
if ( db_type =~ /\ANUMERIC/ )
|
45
|
+
'Edm.Decimal'
|
46
|
+
end
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
data/lib/odata/entity.rb
CHANGED
@@ -311,7 +311,7 @@ module Safrano
|
|
311
311
|
end
|
312
312
|
|
313
313
|
module MappingBeforeOutput
|
314
|
-
# needed for proper datetime output
|
314
|
+
# needed for proper datetime or Decimal output
|
315
315
|
def casted_values(cols = nil)
|
316
316
|
vals = case cols
|
317
317
|
when nil
|
@@ -322,6 +322,10 @@ module Safrano
|
|
322
322
|
else
|
323
323
|
selected_values_for_odata(cols)
|
324
324
|
end
|
325
|
+
# TODO better design (perf/ do more during startup and less during request runtime )
|
326
|
+
# TODO replace the quick and dirty BigDecimal hack with something better
|
327
|
+
self.class.decimal_cols.each { |dc| vals[dc] = BigDecimal(vals[dc].to_s).to_s('F') if vals.key?(dc) }
|
328
|
+
|
325
329
|
self.class.time_cols.each { |tc| vals[tc] = vals[tc]&.iso8601 if vals.key?(tc) }
|
326
330
|
vals
|
327
331
|
end
|
data/lib/odata/model_ext.rb
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'json'
|
8
8
|
require 'rexml/document'
|
9
|
+
require 'bigdecimal'
|
9
10
|
require_relative '../safrano/core'
|
10
11
|
require_relative 'error'
|
11
12
|
require_relative 'collection_filter'
|
@@ -32,6 +33,7 @@ module Safrano
|
|
32
33
|
attr_reader :uri
|
33
34
|
attr_reader :odata_upk_parts
|
34
35
|
attr_reader :time_cols
|
36
|
+
attr_reader :decimal_cols
|
35
37
|
attr_reader :namespace
|
36
38
|
|
37
39
|
# initialising block of code to be executed at end of
|
@@ -73,7 +75,7 @@ module Safrano
|
|
73
75
|
@uparms = nil
|
74
76
|
@params = nil
|
75
77
|
@cx = nil
|
76
|
-
@@time_cols = nil
|
78
|
+
# @@time_cols = nil
|
77
79
|
end
|
78
80
|
|
79
81
|
def build_uri(uribase)
|
@@ -358,11 +360,16 @@ module Safrano
|
|
358
360
|
# Time columns
|
359
361
|
@time_cols = db_schema.select { |_c, v| v[:type] == :datetime }.map { |c, _v| c }
|
360
362
|
|
363
|
+
|
364
|
+
|
361
365
|
# add edm_types into schema
|
362
366
|
db_schema.each do |_col, props|
|
363
|
-
props[:odata_edm_type] = Safrano.default_edm_type(ruby_type: props[:type]
|
367
|
+
props[:odata_edm_type] = Safrano.default_edm_type(ruby_type: props[:type],
|
368
|
+
db_type: props[:db_type])
|
364
369
|
end
|
365
|
-
|
370
|
+
# Edm.Decimal cols
|
371
|
+
@decimal_cols = db_schema.select { |_c, v| v[:odata_edm_type] == 'Edm.Decimal' }.map { |c, _v| c }
|
372
|
+
|
366
373
|
# and finally build the path lists and allowed tr's
|
367
374
|
build_attribute_path_list
|
368
375
|
build_expand_path_list
|
data/lib/safrano/service.rb
CHANGED
@@ -375,7 +375,8 @@ module Safrano
|
|
375
375
|
# finalize the uri's and include NoMappingBeforeOutput or MappingBeforeOutput as needed
|
376
376
|
@collections.each do |klass|
|
377
377
|
klass.build_uri(@uribase)
|
378
|
-
|
378
|
+
# TODO perf
|
379
|
+
klass.include( (klass.time_cols.empty? && klass.decimal_cols.empty?) ? Safrano::NoMappingBeforeOutput : Safrano::MappingBeforeOutput)
|
379
380
|
|
380
381
|
# Output create (POST) as single entity (Standard) or as array (non-standard buggy)
|
381
382
|
klass.include ( @bugfix_create_response ? Safrano::EntityCreateStandardOutput : Safrano::EntityCreateArrayOutput)
|
@@ -504,7 +505,9 @@ module Safrano
|
|
504
505
|
doc.add_element('edmx:Edmx', 'Version' => '1.0')
|
505
506
|
doc.root.add_namespace('xmlns:edmx', XMLNS::MSFT_ADO_2007_EDMX)
|
506
507
|
serv = doc.root.add_element('edmx:DataServices',
|
507
|
-
|
508
|
+
# TODO: export the real version (result from version negotions)
|
509
|
+
# but currently we support only v1 and v2, and most users will use v2
|
510
|
+
'm:DataServiceVersion' => '2.0')
|
508
511
|
# 'm:DataServiceVersion' => "#{self.dataServiceVersion}" )
|
509
512
|
# DataServiceVersion: This attribute MUST be in the data service
|
510
513
|
# metadata namespace
|
data/lib/safrano/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safrano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|