odata 0.5.5 → 0.5.6
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 +4 -4
- data/lib/odata.rb +1 -0
- data/lib/odata/entity.rb +6 -3
- data/lib/odata/properties.rb +9 -1
- data/lib/odata/properties/geography_point.rb +3 -0
- data/lib/odata/property_registry.rb +41 -0
- data/lib/odata/query/criteria.rb +1 -1
- data/lib/odata/service.rb +6 -7
- data/lib/odata/version.rb +1 -1
- data/spec/odata/property_registry_spec.rb +16 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa4d834f3960bec296cd529858811a0ae77483ad
|
4
|
+
data.tar.gz: 95870d1562b87cd913148cb5c62d9f894579c92a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22e48b9956b60803f12a0eb70fb18f9c602d844387368f8fb7e1f8cae5c68a11e6fc2c3b31fd43eb2fa9b3d9539793b679df04baca0eeca7bd233e389e993ecd
|
7
|
+
data.tar.gz: e6bbcf71180124d2f689c0be23bfab9abc9babc4af83cdcd47913d4dbd2c8c7e71c51b3e267e546f40b4376fe475373f4290a9348b88f7aeb3fd47299d4e200c
|
data/lib/odata.rb
CHANGED
data/lib/odata/entity.rb
CHANGED
@@ -120,17 +120,20 @@ module OData
|
|
120
120
|
|
121
121
|
def instantiate_property(property_name, value)
|
122
122
|
value_type = service.get_property_type(name, property_name)
|
123
|
-
|
123
|
+
klass = ::OData::PropertyRegistry[value_type]
|
124
|
+
|
125
|
+
if klass.nil? && value_type =~ /^#{namespace}\./
|
124
126
|
type_name = value_type.gsub(/^#{namespace}\./, '')
|
125
127
|
property = ::OData::ComplexType.new(name: type_name, service: service)
|
126
128
|
value.element_children.each do |node|
|
127
129
|
property[node.name] = node.content
|
128
130
|
end
|
129
131
|
property
|
132
|
+
elsif klass.nil?
|
133
|
+
raise RuntimeError, "Unknown property type: #{value_type}"
|
130
134
|
else
|
131
|
-
klass_name = value_type.gsub(/^Edm\./, '')
|
132
135
|
value = value.content unless value.nil?
|
133
|
-
|
136
|
+
klass.new(property_name, value)
|
134
137
|
end
|
135
138
|
end
|
136
139
|
|
data/lib/odata/properties.rb
CHANGED
@@ -12,4 +12,12 @@ require 'odata/properties/guid'
|
|
12
12
|
require 'odata/properties/integer'
|
13
13
|
require 'odata/properties/string'
|
14
14
|
require 'odata/properties/time'
|
15
|
-
require 'odata/properties/geography_point'
|
15
|
+
require 'odata/properties/geography_point'
|
16
|
+
|
17
|
+
OData::Properties.constants.each do |property_name|
|
18
|
+
klass = OData::Properties.const_get(property_name)
|
19
|
+
if klass.is_a?(Class)
|
20
|
+
property = klass.new('test', nil)
|
21
|
+
OData::PropertyRegistry.add(property.type, property.class)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module OData
|
4
|
+
# Provides a registry for keeping track of various property types used by
|
5
|
+
# OData.
|
6
|
+
class PropertyRegistry
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
# Add a property type to the registry
|
10
|
+
#
|
11
|
+
# @param type_name [String] property type name to register
|
12
|
+
# @param klass [Class] Ruby class to use for the specified type
|
13
|
+
def add(type_name, klass)
|
14
|
+
properties[type_name] = klass
|
15
|
+
end
|
16
|
+
|
17
|
+
# Lookup a property by name and get the Ruby class to use for its instances
|
18
|
+
#
|
19
|
+
# @param type_name [String] the type name to lookup
|
20
|
+
# @return [Class, nil] the proper class or nil
|
21
|
+
def [](type_name)
|
22
|
+
properties[type_name]
|
23
|
+
end
|
24
|
+
|
25
|
+
# (see #add)
|
26
|
+
def self.add(type_name, klass)
|
27
|
+
OData::PropertyRegistry.instance.add(type_name, klass)
|
28
|
+
end
|
29
|
+
|
30
|
+
# (see #[])
|
31
|
+
def self.[](type_name)
|
32
|
+
OData::PropertyRegistry.instance[type_name]
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def properties
|
38
|
+
@properties ||= {}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/odata/query/criteria.rb
CHANGED
data/lib/odata/service.rb
CHANGED
@@ -188,10 +188,6 @@ module OData
|
|
188
188
|
|
189
189
|
private
|
190
190
|
|
191
|
-
def get_property_class(klass_name)
|
192
|
-
::OData::Properties.const_get(klass_name)
|
193
|
-
end
|
194
|
-
|
195
191
|
def default_options
|
196
192
|
{
|
197
193
|
typhoeus: {}
|
@@ -217,13 +213,16 @@ module OData
|
|
217
213
|
value_type = property_xml.attributes['Type'].value
|
218
214
|
property_options = {}
|
219
215
|
|
220
|
-
|
216
|
+
klass = ::OData::PropertyRegistry[value_type]
|
217
|
+
|
218
|
+
if klass.nil? && value_type =~ /^#{namespace}\./
|
221
219
|
type_name = value_type.gsub(/^#{namespace}\./, '')
|
222
220
|
property = ::OData::ComplexType.new(name: type_name, service: self)
|
221
|
+
elsif klass.nil?
|
222
|
+
raise RuntimeError, "Unknown property type: #{value_type}"
|
223
223
|
else
|
224
|
-
klass_name = value_type.gsub(/^Edm\./, '')
|
225
224
|
property_options[:allows_nil] = false if property_xml.attributes['Nullable'] == 'false'
|
226
|
-
property =
|
225
|
+
property = klass.new(property_name, nil, property_options)
|
227
226
|
end
|
228
227
|
|
229
228
|
return [property_name, property]
|
data/lib/odata/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::PropertyRegistry do
|
4
|
+
let(:subject) { OData::PropertyRegistry }
|
5
|
+
|
6
|
+
it { expect(subject).to respond_to(:add) }
|
7
|
+
it { expect(subject).to respond_to(:[]) }
|
8
|
+
|
9
|
+
describe '#add' do
|
10
|
+
before(:each) do
|
11
|
+
subject.add('Edm.Guid', OData::Properties::Guid)
|
12
|
+
end
|
13
|
+
|
14
|
+
it { expect(subject['Edm.Guid']).to eq(OData::Properties::Guid) }
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/odata/properties/string.rb
|
171
171
|
- lib/odata/properties/time.rb
|
172
172
|
- lib/odata/property.rb
|
173
|
+
- lib/odata/property_registry.rb
|
173
174
|
- lib/odata/query.rb
|
174
175
|
- lib/odata/query/criteria.rb
|
175
176
|
- lib/odata/query/result.rb
|
@@ -213,6 +214,7 @@ files:
|
|
213
214
|
- spec/odata/properties/integer_spec.rb
|
214
215
|
- spec/odata/properties/string_spec.rb
|
215
216
|
- spec/odata/properties/time_spec.rb
|
217
|
+
- spec/odata/property_registry_spec.rb
|
216
218
|
- spec/odata/property_spec.rb
|
217
219
|
- spec/odata/query/criteria_spec.rb
|
218
220
|
- spec/odata/query/result_spec.rb
|
@@ -280,6 +282,7 @@ test_files:
|
|
280
282
|
- spec/odata/properties/integer_spec.rb
|
281
283
|
- spec/odata/properties/string_spec.rb
|
282
284
|
- spec/odata/properties/time_spec.rb
|
285
|
+
- spec/odata/property_registry_spec.rb
|
283
286
|
- spec/odata/property_spec.rb
|
284
287
|
- spec/odata/query/criteria_spec.rb
|
285
288
|
- spec/odata/query/result_spec.rb
|