safrano 0.4.0 → 0.4.5

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/core_ext/Dir/iter.rb +18 -0
  3. data/lib/core_ext/Hash/transform.rb +21 -0
  4. data/lib/core_ext/Integer/edm.rb +13 -0
  5. data/lib/core_ext/REXML/Document/output.rb +16 -0
  6. data/lib/core_ext/String/convert.rb +25 -0
  7. data/lib/core_ext/String/edm.rb +13 -0
  8. data/lib/core_ext/dir.rb +3 -0
  9. data/lib/core_ext/hash.rb +3 -0
  10. data/lib/core_ext/integer.rb +3 -0
  11. data/lib/core_ext/rexml.rb +3 -0
  12. data/lib/core_ext/string.rb +5 -0
  13. data/lib/odata/attribute.rb +15 -10
  14. data/lib/odata/batch.rb +15 -13
  15. data/lib/odata/collection.rb +144 -535
  16. data/lib/odata/collection_filter.rb +47 -40
  17. data/lib/odata/collection_media.rb +145 -74
  18. data/lib/odata/collection_order.rb +50 -37
  19. data/lib/odata/common_logger.rb +36 -34
  20. data/lib/odata/complex_type.rb +152 -0
  21. data/lib/odata/edm/primitive_types.rb +184 -0
  22. data/lib/odata/entity.rb +151 -197
  23. data/lib/odata/error.rb +175 -32
  24. data/lib/odata/expand.rb +126 -0
  25. data/lib/odata/filter/base.rb +74 -0
  26. data/lib/odata/filter/error.rb +49 -6
  27. data/lib/odata/filter/parse.rb +44 -36
  28. data/lib/odata/filter/sequel.rb +136 -67
  29. data/lib/odata/filter/sequel_function_adapter.rb +148 -0
  30. data/lib/odata/filter/token.rb +26 -19
  31. data/lib/odata/filter/tree.rb +113 -63
  32. data/lib/odata/function_import.rb +168 -0
  33. data/lib/odata/model_ext.rb +637 -0
  34. data/lib/odata/navigation_attribute.rb +44 -61
  35. data/lib/odata/relations.rb +5 -5
  36. data/lib/odata/select.rb +54 -0
  37. data/lib/odata/transition.rb +71 -0
  38. data/lib/odata/url_parameters.rb +128 -37
  39. data/lib/odata/walker.rb +19 -11
  40. data/lib/safrano.rb +17 -37
  41. data/lib/safrano/contract.rb +143 -0
  42. data/lib/safrano/core.rb +29 -104
  43. data/lib/safrano/core_ext.rb +13 -0
  44. data/lib/safrano/deprecation.rb +73 -0
  45. data/lib/safrano/multipart.rb +39 -43
  46. data/lib/safrano/rack_app.rb +68 -67
  47. data/lib/safrano/{odata_rack_builder.rb → rack_builder.rb} +18 -2
  48. data/lib/safrano/request.rb +102 -51
  49. data/lib/safrano/response.rb +5 -3
  50. data/lib/safrano/sequel_join_by_paths.rb +2 -2
  51. data/lib/safrano/service.rb +264 -220
  52. data/lib/safrano/version.rb +3 -1
  53. data/lib/sequel/plugins/join_by_paths.rb +17 -29
  54. metadata +34 -12
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Safrano
2
- VERSION = '0.4.0'
4
+ VERSION = '0.4.5'
3
5
  end
@@ -1,31 +1,14 @@
1
- #!/usr/bin/env ruby
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'set'
4
4
  require 'sequel'
5
5
 
6
- # some helpers
7
- class String
8
- # thanks https://stackoverflow.com/questions/1448670/ruby-stringto-class
9
- def constantize
10
- names = split('::')
11
- names.shift if names.empty? || names.first.empty?
12
-
13
- const = Object
14
- names.each do |name|
15
- const = if const.const_defined?(name)
16
- const.const_get(name)
17
- else
18
- const.const_missing(name)
19
- end
20
- end
21
- const
22
- end
23
- end
6
+ require 'safrano/core_ext'
24
7
 
25
8
  class PathNode < String
26
- attr_reader :table_name
27
9
  attr_accessor :model_class
28
10
  attr_accessor :path_str
11
+
29
12
  def initialize(str, start_model)
30
13
  super(str)
31
14
  @start_model = start_model
@@ -80,14 +63,14 @@ class QPath
80
63
  path_nodes = []
81
64
  start_node.path_str = path_str
82
65
  nodes = [start_node]
83
- nodes.concat @qpath.split('/').map { |nstr| @start_model.create_path_node(nstr) }
84
- if (ns = nodes.size) > 1
85
- nodes[0...-1].each_with_index do |node, i|
86
- nodes[i + 1].set_model_class_by_parent_model(node.model_class)
87
- path_nodes << nodes[i + 1]
88
- nodes[i + 1].path_str = path_nodes.join('/')
89
- @segments << [node, nodes[i + 1]]
90
- end
66
+ nodes.concat(@qpath.split('/').map { |nstr| @start_model.create_path_node(nstr) })
67
+ return unless nodes.size > 1
68
+
69
+ nodes[0...-1].each_with_index do |node, i|
70
+ nodes[i + 1].set_model_class_by_parent_model(node.model_class)
71
+ path_nodes << nodes[i + 1]
72
+ nodes[i + 1].path_str = path_nodes.join('/')
73
+ @segments << [node, nodes[i + 1]]
91
74
  end
92
75
  end
93
76
  end
@@ -96,13 +79,15 @@ class JoinByPathsHelper < Set
96
79
  attr_reader :result
97
80
  attr_reader :start_model
98
81
 
82
+ EMPTY_ARRAY = [].freeze
83
+
99
84
  def initialize(smodel)
100
85
  super()
101
86
  @start_model = smodel
102
87
  end
103
88
 
104
89
  def build_unique_join_segments
105
- return (@result = []) if empty?
90
+ return (@result = EMPTY_ARRAY) if empty?
106
91
 
107
92
  maxlen = map(&:size).max
108
93
  iset = nil
@@ -118,6 +103,7 @@ class JoinByPathsHelper < Set
118
103
  jseg.map do |seg|
119
104
  leftm = seg.first.model_class
120
105
  assoc = leftm.association_reflection(seg.last.to_sym)
106
+
121
107
  rightm = seg.last.model_class
122
108
  # cf. documentation in sequel/model/associations.rb
123
109
  case assoc[:type]
@@ -205,6 +191,7 @@ module Sequel
205
191
  module ClassMethods
206
192
  attr_reader :aliases_sym
207
193
  attr_reader :alias_cnt
194
+
208
195
  Plugins.inherited_instance_variables(self,
209
196
  :@aliases_sym => :dup,
210
197
  :@alias_cnt => :dup)
@@ -231,6 +218,7 @@ module Sequel
231
218
 
232
219
  module DatasetMethods
233
220
  attr_reader :join_helper
221
+
234
222
  def join_by_paths(*pathlist)
235
223
  model.join_by_paths_helper(*pathlist).dataset
236
224
  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.4.0
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
- - D.M.
7
+ - oz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-26 00:00:00.000000000 Z
11
+ date: 2020-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rfc2047
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.3'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '0.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,12 +108,23 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.51'
111
- description: Safrano is an OData server framework based on Ruby, Rack and Sequel.
111
+ description: Safrano is an OData server library based on Ruby, Rack and Sequel.
112
112
  email: dev@aithscel.eu
113
113
  executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
+ - lib/core_ext/Dir/iter.rb
118
+ - lib/core_ext/Hash/transform.rb
119
+ - lib/core_ext/Integer/edm.rb
120
+ - lib/core_ext/REXML/Document/output.rb
121
+ - lib/core_ext/String/convert.rb
122
+ - lib/core_ext/String/edm.rb
123
+ - lib/core_ext/dir.rb
124
+ - lib/core_ext/hash.rb
125
+ - lib/core_ext/integer.rb
126
+ - lib/core_ext/rexml.rb
127
+ - lib/core_ext/string.rb
117
128
  - lib/odata/attribute.rb
118
129
  - lib/odata/batch.rb
119
130
  - lib/odata/collection.rb
@@ -121,22 +132,34 @@ files:
121
132
  - lib/odata/collection_media.rb
122
133
  - lib/odata/collection_order.rb
123
134
  - lib/odata/common_logger.rb
135
+ - lib/odata/complex_type.rb
136
+ - lib/odata/edm/primitive_types.rb
124
137
  - lib/odata/entity.rb
125
138
  - lib/odata/error.rb
139
+ - lib/odata/expand.rb
140
+ - lib/odata/filter/base.rb
126
141
  - lib/odata/filter/error.rb
127
142
  - lib/odata/filter/parse.rb
128
143
  - lib/odata/filter/sequel.rb
144
+ - lib/odata/filter/sequel_function_adapter.rb
129
145
  - lib/odata/filter/token.rb
130
146
  - lib/odata/filter/tree.rb
147
+ - lib/odata/function_import.rb
148
+ - lib/odata/model_ext.rb
131
149
  - lib/odata/navigation_attribute.rb
132
150
  - lib/odata/relations.rb
151
+ - lib/odata/select.rb
152
+ - lib/odata/transition.rb
133
153
  - lib/odata/url_parameters.rb
134
154
  - lib/odata/walker.rb
135
155
  - lib/safrano.rb
156
+ - lib/safrano/contract.rb
136
157
  - lib/safrano/core.rb
158
+ - lib/safrano/core_ext.rb
159
+ - lib/safrano/deprecation.rb
137
160
  - lib/safrano/multipart.rb
138
- - lib/safrano/odata_rack_builder.rb
139
161
  - lib/safrano/rack_app.rb
162
+ - lib/safrano/rack_builder.rb
140
163
  - lib/safrano/request.rb
141
164
  - lib/safrano/response.rb
142
165
  - lib/safrano/sequel_join_by_paths.rb
@@ -166,9 +189,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
189
  - !ruby/object:Gem::Version
167
190
  version: '0'
168
191
  requirements: []
169
- rubyforge_project:
170
- rubygems_version: 2.7.6.2
192
+ rubygems_version: 3.2.0.rc.2
171
193
  signing_key:
172
194
  specification_version: 4
173
- summary: Safrano is a Ruby OData provider based on Sequel and Rack
195
+ summary: Safrano is a Ruby OData server library based on Sequel and Rack
174
196
  test_files: []