odata 0.5.5 → 0.5.6

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
  SHA1:
3
- metadata.gz: 64f90a5ad13079e0238b44ce57d7bd8e0fc3f93a
4
- data.tar.gz: 7afb091b0a7dcfdade84a5f1ebbd8e8feab25076
3
+ metadata.gz: aa4d834f3960bec296cd529858811a0ae77483ad
4
+ data.tar.gz: 95870d1562b87cd913148cb5c62d9f894579c92a
5
5
  SHA512:
6
- metadata.gz: 11f24245a4d87f00fa7b1acd6103d1e5ccd9f190f149afac192d025175ed1b9edecedbfe205ef91abf41b14d6f235c5f176eb92550e16e706abd96ebdf79733e
7
- data.tar.gz: bcf9ae832061fe082c715b01bd22fa8cd41f3fce929c7943267a03889c8f97032f3ac192fca92aaa11ecd74743a335a343cbe3ec535eb3cb9e36c1e890c893fa
6
+ metadata.gz: 22e48b9956b60803f12a0eb70fb18f9c602d844387368f8fb7e1f8cae5c68a11e6fc2c3b31fd43eb2fa9b3d9539793b679df04baca0eeca7bd233e389e993ecd
7
+ data.tar.gz: e6bbcf71180124d2f689c0be23bfab9abc9babc4af83cdcd47913d4dbd2c8c7e71c51b3e267e546f40b4376fe475373f4290a9348b88f7aeb3fd47299d4e200c
@@ -9,6 +9,7 @@ require 'typhoeus'
9
9
  # require 'active_support/concern'
10
10
 
11
11
  require 'odata/version'
12
+ require 'odata/property_registry'
12
13
  require 'odata/property'
13
14
  require 'odata/properties'
14
15
  require 'odata/complex_type'
@@ -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
- if value_type =~ /^#{namespace}\./
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
- ::OData::Properties.const_get(klass_name).new(property_name, value)
136
+ klass.new(property_name, value)
134
137
  end
135
138
  end
136
139
 
@@ -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
@@ -1,6 +1,9 @@
1
1
  module OData
2
2
  module Properties
3
3
  class GeographyPoint < OData::Property
4
+ def type
5
+ 'Edm.GeographyPoint'
6
+ end
4
7
  end
5
8
  end
6
9
  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
@@ -74,7 +74,7 @@ module OData
74
74
  end
75
75
 
76
76
  def value_for_string
77
- value.is_a?(String) ? "'#{value}'" : value
77
+ value.is_a?(String) ? "#{value}" : value
78
78
  end
79
79
  end
80
80
  end
@@ -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
- if value_type =~ /^#{namespace}\./
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 = ::OData::Properties.const_get(klass_name).new(property_name, nil, property_options)
225
+ property = klass.new(property_name, nil, property_options)
227
226
  end
228
227
 
229
228
  return [property_name, property]
@@ -1,3 +1,3 @@
1
1
  module OData
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
  end
@@ -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.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-16 00:00:00.000000000 Z
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