safrano 0.5.0 → 0.5.1

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: 1a63e3a22f60471d153475bbe642f7321cf0718e71b7ffcc693a748feed9d823
4
- data.tar.gz: 939929f69a3dfeab08ebec25bfa41b5fb7a88b2a00ef47825b4fa0030400e94a
3
+ metadata.gz: b38827d37fa3bfed54a30aa61c04b5da27470071c5e3167fb5a08aa5c48a69af
4
+ data.tar.gz: 3754e63822b6c504b42bc698df360295ab92bcf96a2ed8fdef4af7f2ed5c8d85
5
5
  SHA512:
6
- metadata.gz: c9063333a3ab01760260a8e96311af49ae428c926d25d8b56dc64aee289e909227a77a0e3c074861deec296446a5a0ddadcd951ef409ae3dd246c6c7115d9a91
7
- data.tar.gz: a9e76a33dfdfea13c9df798ac169accf729f18578f4c0fb7071f51709baa05cea56cee8e3d02934f7aef6c865ce89b3ed72aecfaaf8aad91a9c99617054d2c90
6
+ metadata.gz: 0c6a3949c741f120955b4582ddad95aa3fefe80f613030970c174b4fe000129e4d2f67dcb43deae5608a2a287a489a4c94d6ba0df5a613c5557b22b8ca4f625b
7
+ data.tar.gz: 7e5070fa657435fbc3a2932344392e58fa7105863bb045ad5a0aac7227a1e7ce5e4f54628915c81156da2f315eb359409c786243c47697877237ac08294a7872
@@ -31,8 +31,18 @@ module Safrano
31
31
  "Collection(#{@klassmod.type_name})"
32
32
  end
33
33
 
34
- def to_odata_json(coll, _req)
35
- "#{DJ_OPEN}#{{ RESULTSK => coll.map { |c| c.odata_h } }.to_json}#{DJ_CLOSE}"
34
+ def to_odata_json(coll, req)
35
+ # "#{DJ_OPEN}#{{ RESULTSK => coll.map { |c| c.odata_h } }.to_json}#{DJ_CLOSE}"
36
+ template = @klassmod.output_template
37
+ # TODO: Error handling if database contains binary BLOB data that cant be
38
+ # interpreted as UTF-8 then JSON will fail here
39
+
40
+ innerh = req.service.get_coll_odata_h(array: coll,
41
+ template: template)
42
+
43
+ innerj = innerh.to_json
44
+
45
+ "#{DJ_OPEN}#{innerj}#{DJ_CLOSE}"
36
46
  end
37
47
  end
38
48
  class ResultAsEntity < ResultDefinition
@@ -80,7 +90,8 @@ module Safrano
80
90
  # with added OData functionality
81
91
  class ComplexType
82
92
  attr_reader :values
83
-
93
+ EMPTYH = {}.freeze
94
+
84
95
  @namespace = nil
85
96
  def self.namespace
86
97
  @namespace
@@ -89,9 +100,41 @@ module Safrano
89
100
  def self.props
90
101
  @props
91
102
  end
92
-
103
+
104
+ def type_name
105
+ self.class.type_name
106
+ end
107
+
108
+ def metadata_h
109
+ { type: type_name }
110
+ end
111
+
112
+ def casted_values
113
+ # MVP... TODO: handle time mappings like in Entity models
114
+ values
115
+ end
116
+
117
+ # needed for nested json output
118
+ # this is a simpler version of model_ext#output_template
119
+ def self.default_template
120
+ template = {}
121
+ expand_e = {}
122
+
123
+ template[:all_values] = EMPTYH
124
+ @props.each { |prop, kl|
125
+ if kl.respond_to? :default_template
126
+ expand_e[prop] = kl.default_template
127
+ end
128
+ }
129
+ template[:expand_e] = expand_e
130
+ template
131
+ end
132
+
133
+ def self.output_template
134
+ default_template
135
+ end
93
136
  def self.type_name
94
- "#{@namespace}.#{self.to_s}"
137
+ @namespace ? "#{@namespace}.#{self.to_s}" : self.to_s
95
138
  end
96
139
 
97
140
  def initialize
@@ -102,6 +145,7 @@ module Safrano
102
145
 
103
146
  def odata_h
104
147
  ret = { METAK => { TYPEK => self.class.type_name } }
148
+
105
149
  @values.each { |k, v|
106
150
  ret[k] = if v.respond_to? :odata_h
107
151
  v.odata_h
@@ -94,8 +94,10 @@ module Safrano
94
94
 
95
95
  # Factory json-> Model Object instance
96
96
  def new_from_hson_h(hash)
97
- enty = new
98
- enty.set_fields(hash, data_fields, missing: :skip)
97
+ #enty = new
98
+ #enty.set_fields(hash, data_fields, missing: :skip)
99
+ enty = create(hash)
100
+ #enty.set(hash)
99
101
  enty
100
102
  end
101
103
 
@@ -62,6 +62,8 @@ module Safrano
62
62
  # All tap_valid* handlers are executed
63
63
  # tap_error* handlers are not executed
64
64
  class Valid
65
+ attr_reader :result
66
+
65
67
  def initialize(result)
66
68
  @result = result
67
69
  end
@@ -100,10 +102,6 @@ module Safrano
100
102
  def error
101
103
  nil
102
104
  end
103
-
104
- def result
105
- @result
106
- end
107
105
  end # class Valid
108
106
 
109
107
  def self.valid(result)
@@ -112,7 +112,7 @@ module Safrano
112
112
  include Safrano
113
113
  include ExpandHandler
114
114
 
115
- XML_PREAMBLE = %Q(<?xml version="1.0" encoding="utf-8" standalone="yes"?>\r\n)
115
+ XML_PREAMBLE = %(<?xml version="1.0" encoding="utf-8" standalone="yes"?>\r\n)
116
116
 
117
117
  # This is just a hash of entity Set Names to the corresponding Class
118
118
  # Example
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Safrano
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - oz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-21 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack