odata-model 0.3.0 → 0.4.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: 6d9d0c38d9a9e5b4480cc15ec55c330911e4b79f
4
- data.tar.gz: 5090acae175c544469e672293e617cf93ad94f3a
3
+ metadata.gz: 995370eea78ea8a601aa51f63c24d4c5b44ca21f
4
+ data.tar.gz: 8407abe05108d9cd8ea77715de0b34feb45d0256
5
5
  SHA512:
6
- metadata.gz: 79d40b08cec2be355243b83c4b0ed47d35515daf9d26f47c9b470c45d29e198789140bb4affff9d1f40c65ca5254c0e3c7c839f8739e81dd295890564503cc35
7
- data.tar.gz: c1ff959f5ae6818b7fe1c1aa2e4e291bf6a90d72d155382c56258ec70a582e28c3cc407c80718cb5cd458147f42139ccc7a73bc970d227dc81bbed1e0ef2ff04
6
+ metadata.gz: 83cbbcb630063ab7b5ea5b09842890da0e2bbbad209904f44118e7c7acd4b923b62c176e7fbe9e3795cf9d776fcc1d0d171f8e5f3c17112a8f376c0373673c80
7
+ data.tar.gz: 43e2eabce06e6bf56c687ba98714263943673aafc1bf15abe967fcded63f7681c6d5da38907373565be0ff141ba8f30edfd5e9b4567513e504883e695819ab6c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.0
4
+
5
+ * Removed strict dependency on ActiveModel.
6
+ * Added `limit_default_selection` setting to limit default queries to only the
7
+ supplied properties of a model.
8
+
3
9
  ## 0.3.0
4
10
 
5
11
  * Added OData::Model::Railtie for Ruby on Rails integration.
@@ -90,7 +90,7 @@ module OData
90
90
  property_map[attribute_name] = literal_name
91
91
 
92
92
  # Ties into ActiveModel::Dirty
93
- define_attribute_methods attribute_name
93
+ define_attribute_methods attribute_name if defined?(::ActiveModel)
94
94
 
95
95
  nil
96
96
  end
@@ -70,6 +70,14 @@ module OData
70
70
  nil
71
71
  end
72
72
 
73
+ # Sets the configuration option to cause a select operation to be set
74
+ # by default that only queries for the properties defined in the model.
75
+ #
76
+ # @return [nil]
77
+ def limit_default_selection
78
+ odata_config[:limit_default_selection] = true
79
+ end
80
+
73
81
  # Get the OData::Service
74
82
  # @return [OData::Service]
75
83
  # @api private
@@ -14,6 +14,7 @@ module OData
14
14
  @target = model_class
15
15
  @query = target.odata_entity_set.query
16
16
  @last_criteria = nil
17
+ set_default_select
17
18
  end
18
19
 
19
20
  # Sets up a new criteria for filters for the given property name.
@@ -80,9 +81,19 @@ module OData
80
81
  end
81
82
  end
82
83
 
84
+ # By default we only select the properties defined on the Model.
85
+ # @api private
86
+ def set_default_select
87
+ if target.odata_config[:limit_default_selection]
88
+ query.select(target.property_map.values)
89
+ end
90
+ self
91
+ end
92
+
83
93
  private
84
94
 
85
95
  attr_reader :target, :query
96
+
86
97
  end
87
98
  end
88
99
  end
@@ -1,5 +1,5 @@
1
1
  module OData
2
2
  module Model
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
data/lib/odata/model.rb CHANGED
@@ -5,7 +5,7 @@ require 'active_support/concern'
5
5
  require 'odata'
6
6
 
7
7
  require 'odata/model/version'
8
- require 'odata/model/active_model'
8
+ require 'odata/model/active_model' if defined?(::ActiveModel)
9
9
  require 'odata/model/configuration'
10
10
  require 'odata/model/attributes'
11
11
  require 'odata/model/persistence'
@@ -22,7 +22,7 @@ module OData
22
22
  module Model
23
23
  extend ActiveSupport::Concern
24
24
 
25
- include OData::Model::ActiveModel
25
+ include OData::Model::ActiveModel if defined?(::ActiveModel)
26
26
  include OData::Model::Configuration
27
27
  include OData::Model::Attributes
28
28
  include OData::Model::Persistence
data/odata-model.gemspec CHANGED
@@ -24,9 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'codeclimate-test-reporter'
25
25
  spec.add_development_dependency 'rspec', '~> 3.0.0'
26
26
 
27
+ spec.add_development_dependency 'activemodel', '>= 3.0.0'
28
+
27
29
  spec.add_dependency 'odata', '~> 0.5'
28
30
  spec.add_dependency 'activesupport', '>= 3.0.0'
29
- spec.add_dependency 'activemodel', '>= 3.0.0'
30
31
 
31
32
  spec.add_dependency 'slop', '~> 3.6.0'
32
33
  end
@@ -0,0 +1,13 @@
1
+ class LimitedProduct
2
+ include OData::Model
3
+
4
+ use_service 'ODataDemo'
5
+ for_entity 'Product'
6
+
7
+ limit_default_selection
8
+
9
+ property 'ID'
10
+ property 'Name'
11
+ property 'Rating'
12
+ property 'Price'
13
+ end
@@ -1,3 +1,4 @@
1
+ require 'active_model'
1
2
  require 'spec_helper'
2
3
 
3
4
  describe OData::Model do
@@ -5,6 +5,12 @@ describe OData::Model::QueryProxy do
5
5
  let(:query_proxy) { OData::Model::QueryProxy.new(Product) }
6
6
  let(:query_string) { subject.send(:query).to_s }
7
7
 
8
+ it 'allows limiting default selection to only selecting defined properties' do
9
+ query_proxy = OData::Model::QueryProxy.new(LimitedProduct)
10
+ query_string = query_proxy.send(:query).to_s
11
+ expect(query_string).to eq('Products?$select=ID,Name,Rating,Price')
12
+ end
13
+
8
14
  it { expect(subject).to respond_to(:where) }
9
15
  describe '#where' do
10
16
  let(:subject) { query_proxy.where(:name) }
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,7 @@ OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDem
20
20
 
21
21
  require 'example_models/bare_model'
22
22
  require 'example_models/odatademo_product'
23
+ require 'example_models/odatademo_limited_product'
23
24
  require 'example_models/odatademo_person'
24
25
 
25
26
  RSpec::Matchers.define :be_boolean do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odata-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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-25 00:00:00.000000000 Z
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,35 +81,35 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 3.0.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: odata
84
+ name: activemodel
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '0.5'
90
- type: :runtime
89
+ version: 3.0.0
90
+ type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '0.5'
96
+ version: 3.0.0
97
97
  - !ruby/object:Gem::Dependency
98
- name: activesupport
98
+ name: odata
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 3.0.0
103
+ version: '0.5'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 3.0.0
110
+ version: '0.5'
111
111
  - !ruby/object:Gem::Dependency
112
- name: activemodel
112
+ name: activesupport
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -167,6 +167,7 @@ files:
167
167
  - lib/odata/model/version.rb
168
168
  - odata-model.gemspec
169
169
  - spec/example_models/bare_model.rb
170
+ - spec/example_models/odatademo_limited_product.rb
170
171
  - spec/example_models/odatademo_person.rb
171
172
  - spec/example_models/odatademo_product.rb
172
173
  - spec/model/active_model_lint_spec.rb
@@ -202,6 +203,7 @@ specification_version: 4
202
203
  summary: An ActiveModel mapping layer for the OData gem
203
204
  test_files:
204
205
  - spec/example_models/bare_model.rb
206
+ - spec/example_models/odatademo_limited_product.rb
205
207
  - spec/example_models/odatademo_person.rb
206
208
  - spec/example_models/odatademo_product.rb
207
209
  - spec/model/active_model_lint_spec.rb