odata 0.4.0 → 0.5.0

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: dfcfb15f804fca66b30e664860a33a1b7f3cf4ac
4
- data.tar.gz: 1d91e95f9b75f8c0b463dca6fd2a1067a1b35064
3
+ metadata.gz: 44a27c048ec4706996d0eccc9aff655a5c60be94
4
+ data.tar.gz: de691ae9f3cb75ab544642f9826521cfc3bb09e5
5
5
  SHA512:
6
- metadata.gz: e9b7873e447d44334dc0d9aaa69cc9be08e4d216de3ced58d4ed161417e8c3ebb932084ff68c303569d766216ce12024dd12094e20fa8d59f00dadc446647c72
7
- data.tar.gz: 3f0c963f4f24887243ecc79442dfd868f9b71954b1ebd6c53a0ffd3aa9f7957a2e5035b1f108b7ab6553a73c2e094bf682836bcba5041c15aa1515a65ff1ff9b
6
+ metadata.gz: cdaae668ecb311bbb45f7abd54b116c9576d6c158c86968379405890aafad70bd14b0deda585c8f7e0cdbe9cb50e258d2590ccec2e3f78561ea851e58cc7a096
7
+ data.tar.gz: 84222c7cf63702ccc0f6073962a3ce3317cfb32507560dc49ada9c6ac6fb676cf66061a264fba8fa72849638448739d03c2a47bccdd684097499e1cf473a3cc2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.5.0
4
+
5
+ * Stopped using namespace from OData service as unique identifier in favor of
6
+ a supplied name option when opening a service.
7
+
3
8
  ## 0.4.0
4
9
 
5
10
  * Added OData::Query#execute to run query and return a result.
data/README.md CHANGED
@@ -43,22 +43,28 @@ to it like this:
43
43
 
44
44
  OData::Service.open('http://services.odata.org/OData/OData.svc')
45
45
 
46
+ You may also provide an options hash after the URL. It is suggested that you
47
+ supply a name for the service via this hash like so:
48
+
49
+ OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
50
+
46
51
  This one call will setup the service and allow for the discovery of everything
47
52
  the other parts of the OData gem need to function. The two methods you will
48
- want to remember from `OData::Service` are `#service_url` and `#namespace`. Both
53
+ want to remember from `OData::Service` are `#service_url` and `#name`. Both
49
54
  of these methods are available on instances and will allow for lookup in the
50
55
  `OData::ServiceRegistry`, should you need it.
51
56
 
52
- Using either the service URL or the namespace provided by a service's CSDL
53
- schema will allow for quick lookup in the `OData::ServiceRegistry` like such:
57
+ Using either the service URL or the name provided as an option when creating an
58
+ `OData::Service` will allow for quick lookup in the `OData::ServiceRegistry`
59
+ like such:
54
60
 
55
61
  OData::ServiceRegistry['http://services.odata.org/OData/OData.svc']
56
62
  OData::ServiceRegistry['ODataDemo']
57
63
 
58
64
  Both of the above calls would retrieve the same service from the registry. At
59
- the moment there is no protection against namespace collisions provided in
65
+ the moment there is no protection against name collisions provided in
60
66
  `OData::ServiceRegistry`. So, looking up services by their service URL is the
61
- most exact method, but lookup by namespace is provided for convenience.
67
+ most exact method, but lookup by name is provided for convenience.
62
68
 
63
69
  ### Entity Sets
64
70
 
data/lib/odata/entity.rb CHANGED
@@ -7,14 +7,17 @@ module OData
7
7
  class Entity
8
8
  # The Entity type name
9
9
  attr_reader :type
10
- # The OData::Service namespace
10
+ # The OData::Service's namespace
11
11
  attr_reader :namespace
12
+ # The OData::Service's identifying name
13
+ attr_reader :service_name
12
14
 
13
15
  # Initializes a bare Entity
14
16
  # @param options [Hash]
15
17
  def initialize(options = {})
16
18
  @type = options[:type]
17
19
  @namespace = options[:namespace]
20
+ @service_name = options[:service_name]
18
21
  end
19
22
 
20
23
  # Returns name of Entity from Service specified type.
@@ -14,8 +14,10 @@ module OData
14
14
  attr_reader :name
15
15
  # The Entity type for the EntitySet
16
16
  attr_reader :type
17
- # The OData::Service namespace
17
+ # The OData::Service's namespace
18
18
  attr_reader :namespace
19
+ # The OData::Service's identifiable name
20
+ attr_reader :service_name
19
21
  # The EntitySet's container name
20
22
  attr_reader :container
21
23
 
@@ -24,11 +26,11 @@ module OData
24
26
  # @param options [Hash] the options to setup the EntitySet
25
27
  # @return [OData::EntitySet] an instance of the EntitySet
26
28
  def initialize(options = {})
27
- @name = options[:name]
28
- @type = options[:type]
29
- @namespace = options[:namespace]
30
- @container = options[:container]
31
- self
29
+ @name = options[:name]
30
+ @type = options[:type]
31
+ @namespace = options[:namespace]
32
+ @service_name = options[:service_name]
33
+ @container = options[:container]
32
34
  end
33
35
 
34
36
  # Provided for Enumerable functionality
@@ -108,7 +110,7 @@ module OData
108
110
  # @return [OData::Service]
109
111
  # @api private
110
112
  def service
111
- @service ||= OData::ServiceRegistry[namespace]
113
+ @service ||= OData::ServiceRegistry[service_name]
112
114
  end
113
115
 
114
116
  # Options used for instantiating a new OData::Entity for this set.
@@ -116,8 +118,9 @@ module OData
116
118
  # @api private
117
119
  def entity_options
118
120
  {
119
- namespace: namespace,
120
- type: type
121
+ namespace: namespace,
122
+ service_name: service_name,
123
+ type: type
121
124
  }
122
125
  end
123
126
 
data/lib/odata/service.rb CHANGED
@@ -4,7 +4,6 @@ module OData
4
4
  class Service
5
5
  # The OData Service's URL
6
6
  attr_reader :service_url
7
-
8
7
  # Options to pass around
9
8
  attr_reader :options
10
9
 
@@ -31,6 +30,12 @@ module OData
31
30
  Service.new(service_url, options)
32
31
  end
33
32
 
33
+ # Returns user supplied name for service, or its URL
34
+ # @return [String]
35
+ def name
36
+ @name ||= options[:name] || service_url
37
+ end
38
+
34
39
  # Returns a list of entities exposed by the service
35
40
  def entity_types
36
41
  @entity_types ||= metadata.xpath('//EntityType').collect {|entity| entity.attributes['Name'].value}
@@ -58,7 +63,7 @@ module OData
58
63
 
59
64
  # Returns a more compact inspection of the service object
60
65
  def inspect
61
- "#<#{self.class.name}:#{self.object_id} namespace='#{self.namespace}' service_url='#{self.service_url}'>"
66
+ "#<#{self.class.name}:#{self.object_id} name='#{name}' service_url='#{self.service_url}'>"
62
67
  end
63
68
 
64
69
  # Retrieves the EntitySet associated with a specific EntityType by name
@@ -74,6 +79,7 @@ module OData
74
79
  OData::EntitySet.new(name: entity_set_name,
75
80
  namespace: namespace,
76
81
  type: entity_type_name.to_s,
82
+ service_name: name,
77
83
  container: container_name)
78
84
  end
79
85
 
@@ -11,17 +11,17 @@ module OData
11
11
  def add(service)
12
12
  initialize_instance_variables
13
13
  @services << service if service.is_a?(OData::Service) && !@services.include?(service)
14
- @services_by_namespace[service.namespace] = @services.find_index(service)
14
+ @services_by_name[service.name] = @services.find_index(service)
15
15
  @services_by_url[service.service_url] = @services.find_index(service)
16
16
  end
17
17
 
18
- # Lookup a service by URL or namespace
18
+ # Lookup a service by URL or name
19
19
  #
20
- # @param lookup_key [String] the URL or namespace to lookup
20
+ # @param lookup_key [String] the URL or name to lookup
21
21
  # @return [OData::Service, nil] the OData::Service or nil
22
22
  def [](lookup_key)
23
23
  initialize_instance_variables
24
- index = @services_by_namespace[lookup_key] || @services_by_url[lookup_key]
24
+ index = @services_by_name[lookup_key] || @services_by_url[lookup_key]
25
25
  index.nil? ? nil : @services[index]
26
26
  end
27
27
 
@@ -39,13 +39,13 @@ module OData
39
39
 
40
40
  def initialize_instance_variables
41
41
  @services ||= []
42
- @services_by_namespace ||= {}
42
+ @services_by_name ||= {}
43
43
  @services_by_url ||= {}
44
44
  end
45
45
 
46
46
  def flush
47
47
  @services = []
48
- @services_by_namespace = {}
48
+ @services_by_name = {}
49
49
  @services_by_url = {}
50
50
  end
51
51
  end
data/lib/odata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OData
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -41,7 +41,7 @@ http_interactions:
41
41
  Set-Cookie:
42
42
  - ARRAffinity=a9aad020fb0149d28d0efdb1e8bab24ad3481a904c8fb94abced8813c01ee265;Path=/;Domain=services.odata.org
43
43
  Date:
44
- - Sat, 19 Jul 2014 02:59:51 GMT
44
+ - Mon, 21 Jul 2014 17:13:14 GMT
45
45
  body:
46
46
  encoding: UTF-8
47
47
  string: <?xml version="1.0" encoding="utf-8"?><edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"><edmx:DataServices
@@ -160,5 +160,5 @@ http_interactions:
160
160
  http_version: '1.1'
161
161
  adapter_metadata:
162
162
  effective_url: http://services.odata.org/OData/OData.svc/$metadata
163
- recorded_at: Sat, 19 Jul 2014 02:59:52 GMT
163
+ recorded_at: Mon, 21 Jul 2014 17:13:14 GMT
164
164
  recorded_with: VCR 2.9.2
@@ -2,19 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  describe OData::EntitySet, vcr: {cassette_name: 'entity_set_specs'} do
4
4
  before(:example) do
5
- OData::Service.open('http://services.odata.org/OData/OData.svc')
5
+ OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
6
6
  end
7
7
 
8
8
  let(:subject) { OData::EntitySet.new(options) }
9
9
  let(:options) { {
10
10
  container: 'DemoService', namespace: 'ODataDemo', name: 'Products',
11
- type: 'Product'
11
+ type: 'Product', service_name: 'ODataDemo'
12
12
  } }
13
13
 
14
14
  it { expect(subject).to respond_to(:name) }
15
15
  it { expect(subject).to respond_to(:type) }
16
16
  it { expect(subject).to respond_to(:container) }
17
17
  it { expect(subject).to respond_to(:namespace) }
18
+ it { expect(subject).to respond_to(:service_name) }
18
19
  it { expect(subject).to respond_to(:new_entity) }
19
20
  it { expect(subject).to respond_to(:[]) }
20
21
  it { expect(subject).to respond_to(:<<) }
@@ -22,6 +23,7 @@ describe OData::EntitySet, vcr: {cassette_name: 'entity_set_specs'} do
22
23
  it { expect(subject.name).to eq('Products') }
23
24
  it { expect(subject.container).to eq('DemoService') }
24
25
  it { expect(subject.namespace).to eq('ODataDemo') }
26
+ it { expect(subject.service_name).to eq('ODataDemo') }
25
27
  it { expect(subject.type).to eq('Product') }
26
28
 
27
29
  describe '#each' do
@@ -2,20 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  describe OData::Entity, vcr: {cassette_name: 'entity_specs'} do
4
4
  before(:example) do
5
- OData::Service.open('http://services.odata.org/OData/OData.svc')
5
+ OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
6
6
  end
7
7
 
8
8
  let(:subject) { OData::Entity.new(options) }
9
9
  let(:options) { {
10
- type: 'ODataDemo.Product',
11
- namespace: 'ODataDemo'
10
+ type: 'ODataDemo.Product',
11
+ namespace: 'ODataDemo',
12
+ service_name: 'ODataDemo'
12
13
  } }
13
14
 
14
- it { expect(subject).to respond_to(:name, :type, :namespace) }
15
+ it { expect(subject).to respond_to(:name, :type, :namespace, :service_name) }
15
16
 
16
17
  it { expect(subject.name).to eq('Product') }
17
18
  it { expect(subject.type).to eq('ODataDemo.Product') }
18
19
  it { expect(subject.namespace).to eq('ODataDemo') }
20
+ it { expect(subject.service_name).to eq('ODataDemo') }
19
21
 
20
22
  describe '.from_xml' do
21
23
  let(:subject) { OData::Entity.from_xml(product_xml, options) }
@@ -31,6 +33,7 @@ describe OData::Entity, vcr: {cassette_name: 'entity_specs'} do
31
33
  it { expect(subject.name).to eq('Product') }
32
34
  it { expect(subject.type).to eq('ODataDemo.Product') }
33
35
  it { expect(subject.namespace).to eq('ODataDemo') }
36
+ it { expect(subject.service_name).to eq('ODataDemo') }
34
37
 
35
38
  it { expect(subject['ID']).to eq(0) }
36
39
  it { expect(subject['Name']).to eq('Bread') }
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe OData::Query::Result, vcr: {cassette_name: 'query/result_specs'} do
4
4
  before(:example) do
5
- OData::Service.open('http://services.odata.org/OData/OData.svc')
5
+ OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
6
6
  end
7
7
 
8
8
  let(:subject) { query.execute }
@@ -1,17 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OData::Query, vcr: {cassette_name: 'query_specs'} do
4
+ before(:example) do
5
+ OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
6
+ end
7
+
4
8
  let(:subject) { OData::Query.new(entity_set) }
5
9
  let(:entity_set) { OData::EntitySet.new(options) }
6
10
  let(:options) { {
7
11
  container: 'DemoService', namespace: 'ODataDemo', name: 'Products',
8
- type: 'Product'
12
+ service_name: 'ODataDemo', type: 'Product'
9
13
  } }
10
14
 
11
- before(:example) do
12
- OData::Service.open('http://services.odata.org/OData/OData.svc')
13
- end
14
-
15
15
  it { expect(subject).to respond_to(:to_s) }
16
16
  it { expect(subject.to_s).to eq('Products')}
17
17
 
@@ -2,17 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe OData::ServiceRegistry, vcr: {cassette_name: 'service_registry_specs'} do
4
4
  let(:subject) { OData::ServiceRegistry }
5
- let(:sample_service) { OData::Service.open('http://services.odata.org/OData/OData.svc') }
5
+ let(:sample_service) { OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'demoService') }
6
6
 
7
7
  it { expect(subject).to respond_to(:add) }
8
8
  it { expect(subject).to respond_to(:[]) }
9
9
 
10
10
  describe '#add' do
11
- before :each do
11
+ before(:example) do
12
12
  subject.add(sample_service)
13
13
  end
14
14
 
15
- it { expect(subject[sample_service.namespace]).to eq(sample_service) }
16
- it { expect(subject[sample_service.service_url]).to eq(sample_service) }
15
+ it { expect(subject['demoService']).to eq(sample_service) }
16
+ it { expect(subject['http://services.odata.org/OData/OData.svc']).to eq(sample_service) }
17
17
  end
18
18
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OData::Service, vcr: {cassette_name: 'service_specs'} do
4
- let(:subject) { OData::Service.open('http://services.odata.org/OData/OData.svc') }
4
+ let(:subject) { OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo') }
5
5
  let(:entity_types) { %w{Product FeaturedProduct ProductDetail Category Supplier Person Customer Employee PersonDetail Advertisement} }
6
6
  let(:entity_sets) { %w{Products ProductDetails Categories Suppliers Persons PersonDetails Advertisements} }
7
7
  let(:entity_set_types) { %w{Product ProductDetail Category Supplier Person PersonDetail Advertisement} }
@@ -15,7 +15,7 @@ describe OData::Service, vcr: {cassette_name: 'service_specs'} do
15
15
  expect(OData::ServiceRegistry['ODataDemo']).to be_nil
16
16
  expect(OData::ServiceRegistry['http://services.odata.org/OData/OData.svc']).to be_nil
17
17
 
18
- service = OData::Service.open('http://services.odata.org/OData/OData.svc')
18
+ service = OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
19
19
 
20
20
  expect(OData::ServiceRegistry['ODataDemo']).to eq(service)
21
21
  expect(OData::ServiceRegistry['http://services.odata.org/OData/OData.svc']).to eq(service)
data/spec/spec_helper.rb CHANGED
@@ -17,7 +17,8 @@ require 'vcr'
17
17
  VCR.configure do |c|
18
18
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
19
19
  c.hook_into :typhoeus
20
- c.default_cassette_options = { record: :new_episodes, erb: true }
20
+ c.default_cassette_options = { record: :new_episodes }
21
+ c.debug_logger = File.open(ENV['VCR_LOG'], 'w') if ENV['VCR_LOG']
21
22
  c.configure_rspec_metadata!
22
23
  end
23
24
 
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.4.0
4
+ version: 0.5.0
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-07-20 00:00:00.000000000 Z
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler