safrano 0.8.1 → 0.8.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
  SHA256:
3
- metadata.gz: 351f486db0cd9cfa46ac9770e739dce4fcf9b4fe4a564799febc2d23eea2f713
4
- data.tar.gz: b214e28350f97dc2a442950803773accb428f8316de8482884c56c81b0aab754
3
+ metadata.gz: 5e43512da576932288321a8e821e26fa9c70d578f52562f6a343bfe3c3711bae
4
+ data.tar.gz: e2c00621b792634355f99d2025fada0d05cd44666516d916aa2546fb72f5157f
5
5
  SHA512:
6
- metadata.gz: 3e1a12730936b436c30c909970b8d31e90358b87f10242f76c7f8b238def70391fb20bc0568825495045a095db6d799b8da8c07c9f524914eecf0a072d083d40
7
- data.tar.gz: 8a1fdd4ca3c8d4512bd6ef6890a653a1ad1e052daad13ee5355d51248c652a938cf75df16d42d97a42ee6149f111e69cce215102b69c414b58920cf4b62180a2
6
+ metadata.gz: 8ff433c52ec4406198b0988e122213f0af36a8f1a06b2eb1d2ebfc2c3736db5f8c575fa86e04b8ac9801d4d4fb363edc468c3078b3f93c66313497739ffc3c2e
7
+ data.tar.gz: 59ebba62c9a7e81496a651473fa9469d843409dab4c1703221f897425136fe02439ea400e17124a910de599378056b7b21758815d734c9807778193c791e3286
@@ -0,0 +1,14 @@
1
+ # mach_length for ruby < 3.0
2
+ module Safrano
3
+ module CoreIncl
4
+ module MatchData
5
+ module MatchLen
6
+ unless method_defined? :match_length
7
+ def match_length(i)
8
+ self[i].length
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'MatchData/matchlen'
2
+
3
+ MatchData.include Safrano::CoreIncl::MatchData::MatchLen
@@ -215,10 +215,9 @@ module Safrano
215
215
  # needed for nested json output
216
216
  # this is a simpler version of model_ext#output_template
217
217
  def self.default_template
218
- template = {}
218
+ template = { meta: EMPTYH, all_values: EMPTYH }
219
219
  expand_e = {}
220
220
 
221
- template[:all_values] = EMPTYH
222
221
  @props.each do |prop, kl|
223
222
  expand_e[prop] = kl.default_template if kl.respond_to? :default_template
224
223
  end
data/lib/odata/entity.rb CHANGED
@@ -217,7 +217,6 @@ module Safrano
217
217
  def odata_patch(req)
218
218
  req.with_parsed_data(self.class) do |data|
219
219
  data.delete('__metadata')
220
-
221
220
  # validate payload column names
222
221
  if (invalid = self.class.invalid_hash_data?(data))
223
222
  ::Safrano::Request::ON_CGST_ERROR.call(req)
data/lib/odata/error.rb CHANGED
@@ -46,6 +46,14 @@ module Safrano
46
46
  super(msg, symbname)
47
47
  end
48
48
  end
49
+
50
+ # invalid response format option
51
+ class InvalidRespFormatOption < NameError
52
+ def initialize(opt)
53
+ msg = "Invalid response format option: #{opt}"
54
+ super(msg, opt.to_s)
55
+ end
56
+ end
49
57
  end
50
58
 
51
59
  # used in function import error handling. cf. func import / do_execute_func
@@ -236,9 +236,9 @@ module Safrano
236
236
  def output_template(expand_list:,
237
237
  select: Safrano::SelectBase::ALL)
238
238
 
239
- return @default_template if expand_list.empty? && select.all_props?
239
+ return @default_template.dup if expand_list.empty? && select.all_props?
240
240
 
241
- template = {}
241
+ template = { meta: EMPTYH }
242
242
  expand_e = {}
243
243
  expand_c = {}
244
244
  deferr = []
@@ -364,7 +364,7 @@ module Safrano
364
364
  EMPTYH = {}.freeze
365
365
 
366
366
  def build_default_template
367
- @default_template = { all_values: EMPTYH }
367
+ @default_template = { meta: EMPTYH, all_values: EMPTYH }
368
368
  @default_template[:deferr] = (@nav_entity_attribs&.keys || []) + (@nav_collection_attribs&.keys || EMPTY_ARRAY) if @nav_entity_attribs || @nav_collection_attribs
369
369
  end
370
370
 
@@ -22,6 +22,13 @@ module Safrano
22
22
  Safrano::Request.new(env, @service_base).process
23
23
  end
24
24
 
25
+ # needed for testing only ? try to remove this
26
+ def self.copy(other)
27
+ copy = Class.new(Safrano::ServerApp) # <---- !!!
28
+ copy.set_servicebase(other.get_service_base.dup)
29
+ copy
30
+ end
31
+
25
32
  # needed for testing only ? try to remove this
26
33
  def self.enable_batch
27
34
  @service_base.enable_batch
@@ -32,6 +39,12 @@ module Safrano
32
39
  @service_base.path_prefix path_pr
33
40
  end
34
41
 
42
+ # needed for testing only ? try to remove this
43
+
44
+ def self.response_format_options(*args)
45
+ @service_base.response_format_options(*args)
46
+ end
47
+
35
48
  # needed for testing only ? try to remove this
36
49
  def self.get_service_base
37
50
  @service_base
@@ -12,8 +12,12 @@ require 'set'
12
12
  require 'odata/collection'
13
13
 
14
14
  module Safrano
15
- # this module has all methods related to expand/defered output preparation
15
+ # these modules have all methods related to expand/defered output preparation
16
16
  # and will be included in Service class
17
+
18
+ METADATA_K = '__metadata'
19
+ EMPTYH = {}.freeze
20
+
17
21
  module ExpandHandler
18
22
  PATH_SPLITTER = %r{\A(\w+)/?(.*)\z}.freeze
19
23
  DEFERRED = '__deferred'
@@ -40,14 +44,17 @@ module Safrano
40
44
  { uri: entity.uri }
41
45
  end
42
46
 
43
- EMPTYH = {}.freeze
44
- METADATA_K = '__metadata'
45
47
  def get_entity_odata_h(entity:, template:)
46
- # start with metadata
47
- hres = { METADATA_K => entity.metadata_h }
48
+ hres = {}
49
+ # finalise the template according to options
50
+ # (eg. skip metadata and or deferred...)
51
+ @final_template_func.call(template)
48
52
 
49
53
  template.each do |elmt, arg|
50
54
  case elmt
55
+ when :meta
56
+ hres[METADATA_K] = entity.metadata_h
57
+
51
58
  when :all_values
52
59
  hres.merge! entity.casted_values
53
60
 
@@ -143,6 +150,8 @@ module Safrano
143
150
  attr_accessor :function_imports
144
151
  attr_accessor :function_import_keys
145
152
  attr_accessor :type_mappings
153
+ attr_accessor :final_template_func
154
+ attr_accessor :response_format_options
146
155
 
147
156
  # Instance attributes for specialized Version specific Instances
148
157
  attr_accessor :v1
@@ -151,6 +160,12 @@ module Safrano
151
160
  # TODO: more elegant design
152
161
  attr_reader :data_service_version
153
162
 
163
+ # for response format options
164
+ FINAL_TEMPLATE_FUNC_DEFAULT = ->(_template) {}
165
+ FINAL_TEMPLATE_FUNC_SKIP_META = ->(template) { template.delete(:meta) }
166
+ FINAL_TEMPLATE_FUNC_SKIP_DEFERR = ->(template) { template.delete(:deferr) }
167
+ FINAL_TEMPLATE_FUNC_SKIP_META_DEFERR = ->(template) { template.delete(:meta); template.delete(:deferr) }
168
+
154
169
  def initialize(&block)
155
170
  # Warning: if you add attributes here, you shall need add them
156
171
  # in copy_attribs_to as well
@@ -164,6 +179,8 @@ module Safrano
164
179
  @function_import_keys = []
165
180
  @cmap = {}
166
181
  @type_mappings = {}
182
+ @response_format_options = []
183
+ @final_template_func = FINAL_TEMPLATE_FUNC_DEFAULT
167
184
  # enabled per default starting from 0.6
168
185
  @bugfix_create_response = true
169
186
  instance_eval(&block) if block_given?
@@ -214,12 +231,42 @@ module Safrano
214
231
  (@v2.xserver_url = @xserver_url) if @v2
215
232
  end
216
233
 
234
+ VALID_RESP_FORMAT_OPTS = [:skip_deferred, :skip_metadata]
235
+ def valid_resp_format_options(*args)
236
+ args.map!(&:to_sym)
237
+ args.each { |arg|
238
+ raise API::InvalidRespFormatOption.new(arg) unless VALID_RESP_FORMAT_OPTS.include?(arg)
239
+ }
240
+ yield(args)
241
+ end
242
+
243
+ def response_format_options(*args)
244
+ valid_resp_format_options(*args) do |vargs|
245
+ @response_format_options = vargs.dup
246
+ process_response_format_options
247
+ @v1.response_format_options(*vargs) if @v1
248
+ @v2.response_format_options(*vargs) if @v2
249
+ end
250
+ end
251
+
217
252
  # keep the bug active for now, but allow to de-activate the fix
218
253
  def bugfix_create_response(bool)
219
254
  @bugfix_create_response = bool
220
255
  end
221
256
 
222
257
  # end public API
258
+ def process_response_format_options
259
+ @final_template_func = if (@response_format_options.include?(:skip_metadata) &&
260
+ @response_format_options.include?(:skip_deferred))
261
+ FINAL_TEMPLATE_FUNC_SKIP_META_DEFERR
262
+ elsif @response_format_options.include?(:skip_metadata)
263
+ FINAL_TEMPLATE_FUNC_SKIP_META
264
+ elsif @response_format_options.include?(:skip_deferred)
265
+ FINAL_TEMPLATE_FUNC_SKIP_DEFERR
266
+ else
267
+ FINAL_TEMPLATE_FUNC_DEFAULT
268
+ end
269
+ end
223
270
 
224
271
  def set_uribase
225
272
  @uribase = if @xpath_prefix.empty?
@@ -250,6 +297,8 @@ module Safrano
250
297
  other.function_imports = @function_imports
251
298
  other.function_import_keys = @function_import_keys
252
299
  other.type_mappings = @type_mappings
300
+ other.response_format_options = @response_format_options
301
+ other.final_template_func = @final_template_func
253
302
  other.bugfix_create_response(@bugfix_create_response)
254
303
  other
255
304
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Safrano
4
- VERSION = '0.8.1'
4
+ VERSION = '0.8.2'
5
5
  end
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.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - oz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-18 00:00:00.000000000 Z
11
+ date: 2024-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -187,6 +187,7 @@ files:
187
187
  - lib/core_ext/Dir/iter.rb
188
188
  - lib/core_ext/Hash/transform.rb
189
189
  - lib/core_ext/Integer/edm.rb
190
+ - lib/core_ext/MatchData/matchlen.rb
190
191
  - lib/core_ext/Numeric/convert.rb
191
192
  - lib/core_ext/REXML/Document/output.rb
192
193
  - lib/core_ext/String/convert.rb
@@ -197,6 +198,7 @@ files:
197
198
  - lib/core_ext/dir.rb
198
199
  - lib/core_ext/hash.rb
199
200
  - lib/core_ext/integer.rb
201
+ - lib/core_ext/matchdata.rb
200
202
  - lib/core_ext/numeric.rb
201
203
  - lib/core_ext/rexml.rb
202
204
  - lib/core_ext/string.rb