odata-model 0.2.0 → 0.3.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: c9af1e9a92b9ecf511d9da7347473c779824b9b8
4
- data.tar.gz: 6172738728c6b5ed9349611bb700c5b578c3d383
3
+ metadata.gz: 6d9d0c38d9a9e5b4480cc15ec55c330911e4b79f
4
+ data.tar.gz: 5090acae175c544469e672293e617cf93ad94f3a
5
5
  SHA512:
6
- metadata.gz: 344ff2fb53b0bc6feb3f2a9cf7ca2936a44335cb5af249d773618967d808c1772cce02bbab53a510e90a214aa79722f9091b0710e43475c745ca4dc54b525e19
7
- data.tar.gz: c286f7a764c5597b190466b20e3a457d2dab750aed01ee91e214c06621f181807b80f9a886ea80d03b2c03f89ad13c3289172a5d1c8b1e2d471f2a96979f2661
6
+ metadata.gz: 79d40b08cec2be355243b83c4b0ed47d35515daf9d26f47c9b470c45d29e198789140bb4affff9d1f40c65ca5254c0e3c7c839f8739e81dd295890564503cc35
7
+ data.tar.gz: c1ff959f5ae6818b7fe1c1aa2e4e291bf6a90d72d155382c56258ec70a582e28c3cc407c80718cb5cd458147f42139ccc7a73bc970d227dc81bbed1e0ef2ff04
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.3.0
4
+
5
+ * Added OData::Model::Railtie for Ruby on Rails integration.
6
+
3
7
  ## 0.2.0
4
8
 
5
9
  * Added `odata_service_name` to private API methods
@@ -0,0 +1,51 @@
1
+ module OData
2
+ module Model
3
+ # Defines the necessary hooks to work correctly with Ruby on Rails.
4
+ # @api private
5
+ class Railtie < ::Rails::Railtie
6
+ attr_accessor :configuration
7
+
8
+ config.odata = ActiveSupport::OrderedOptions.new
9
+
10
+ initializer('odata_configuration') do |app|
11
+ parse_configuration(app)
12
+ process_configuration(app)
13
+ end
14
+
15
+ private
16
+
17
+ def parse_configuration(app)
18
+ config_file = File.open(File.join(Rails.root, 'config/odata.yml'))
19
+ configuration = YAML.load(config_file).symbolize_keys[Rails.env]
20
+ end
21
+
22
+ def process_configuration(app)
23
+ configuration.each do |service_name, service_details|
24
+ url = service_details[:url]
25
+ options = generate_options(service_name, service_details)
26
+ OData::Service.open(url, options)
27
+ validate_service_setup(service_name)
28
+ end
29
+ end
30
+
31
+ def generate_options(service_name, service_details)
32
+ options = { name: service_name }
33
+ if service_details[:username] && service_details[:password]
34
+ options[:typohoeus] = {
35
+ username: service_details[:username],
36
+ password: service_details[:password]
37
+ }
38
+ options[:typhoeus][:auth_type] = service_details[:auth_type]
39
+ end
40
+ options
41
+ end
42
+
43
+ def validate_service_setup(service_name)
44
+ service = OData::ServiceRegistry[service_name]
45
+ service.namespace
46
+ rescue StandardError
47
+ raise RuntimeError, "could not access service at #{service.service_url}"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  module OData
2
2
  module Model
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
data/lib/odata/model.rb CHANGED
@@ -12,6 +12,8 @@ require 'odata/model/persistence'
12
12
  require 'odata/model/query'
13
13
  require 'odata/model/query_proxy'
14
14
 
15
+ require 'odata/model/railtie' if defined?(::Rails)
16
+
15
17
  # OData is the parent namespace for the OData::Model project.
16
18
  module OData
17
19
  # OData::Model provides a way to map from OData::Entity instances, as
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odata-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thompson
@@ -163,6 +163,7 @@ files:
163
163
  - lib/odata/model/persistence.rb
164
164
  - lib/odata/model/query.rb
165
165
  - lib/odata/model/query_proxy.rb
166
+ - lib/odata/model/railtie.rb
166
167
  - lib/odata/model/version.rb
167
168
  - odata-model.gemspec
168
169
  - spec/example_models/bare_model.rb