odata-model 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/bin/odata-model +12 -67
- data/lib/odata/model/cli/generator_configuration.rb +72 -0
- data/lib/odata/model/cli/model_template.rb +41 -0
- data/lib/odata/model/configuration.rb +18 -0
- data/lib/odata/model/version.rb +1 -1
- data/spec/example_models/odatademo_person.rb +9 -0
- data/spec/model/entity_set_identification_spec.rb +13 -0
- data/spec/model/service_integration_spec.rb +3 -0
- data/spec/spec_helper.rb +1 -0
- metadata +8 -3
- data/lib/odata/model/templates/model.erb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9af1e9a92b9ecf511d9da7347473c779824b9b8
|
4
|
+
data.tar.gz: 6172738728c6b5ed9349611bb700c5b578c3d383
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 344ff2fb53b0bc6feb3f2a9cf7ca2936a44335cb5af249d773618967d808c1772cce02bbab53a510e90a214aa79722f9091b0710e43475c745ca4dc54b525e19
|
7
|
+
data.tar.gz: c286f7a764c5597b190466b20e3a457d2dab750aed01ee91e214c06621f181807b80f9a886ea80d03b2c03f89ad13c3289172a5d1c8b1e2d471f2a96979f2661
|
data/CHANGELOG.md
CHANGED
data/bin/odata-model
CHANGED
@@ -1,58 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'odata/model'
|
3
2
|
require 'slop'
|
4
|
-
require 'erb'
|
5
|
-
|
6
|
-
def validate_service_url(opts)
|
7
|
-
unless opts[:service_url]
|
8
|
-
puts 'You must supply a service_url (-s, --service_url=)'
|
9
|
-
exit(1)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def handle_auth_options(opts)
|
14
|
-
service_options = {}
|
15
|
-
if opts[:username] && opts[:password]
|
16
|
-
service_options[:typhoeus] = {
|
17
|
-
username: opts[:username],
|
18
|
-
password: opts[:password]
|
19
|
-
}
|
20
|
-
if opts[:auth_type]
|
21
|
-
auth_type = opts[:auth_type].to_sym
|
22
|
-
service_options[:typhoeus][:httpauth] = auth_type
|
23
|
-
end
|
24
|
-
end
|
25
|
-
service_options
|
26
|
-
end
|
27
|
-
|
28
|
-
class ModelTemplate
|
29
|
-
attr_reader :class_name, :service_name, :properties
|
30
|
-
|
31
|
-
def initialize(class_name, service_name, properties)
|
32
|
-
@class_name = class_name
|
33
|
-
@service_name = service_name
|
34
|
-
@properties = properties
|
35
|
-
end
|
36
3
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
include OData::Model
|
41
|
-
|
42
|
-
use_service '<%= @service_name %>'
|
43
|
-
|
44
|
-
<% properties.each do |property_name, as_name| %>
|
45
|
-
property '<%= property_name %>'<%= as_name.nil? ? nil : ", as: :\#\{as_name\}" %>
|
46
|
-
<% end %>
|
47
|
-
end
|
48
|
-
EOS
|
49
|
-
end
|
50
|
-
|
51
|
-
def render
|
52
|
-
renderer = ERB.new(template, 0, '<>')
|
53
|
-
renderer.result(binding)
|
54
|
-
end
|
55
|
-
end
|
4
|
+
require 'odata/model'
|
5
|
+
require 'odata/model/cli/model_template'
|
6
|
+
require 'odata/model/cli/generator_configuration'
|
56
7
|
|
57
8
|
opts = Slop.parse do
|
58
9
|
banner 'Usage: odata-model <command> [options]'
|
@@ -69,10 +20,10 @@ opts = Slop.parse do
|
|
69
20
|
on :a, :auth_type=, 'CURL authentication type (optional)', argument: :optional
|
70
21
|
|
71
22
|
run do |opts, args|
|
72
|
-
validate_service_url(opts)
|
23
|
+
OData::Model::CLI::GeneratorConfiguration.validate_service_url(opts)
|
24
|
+
generator = OData::Model::CLI::GeneratorConfiguration.new(opts)
|
73
25
|
|
74
|
-
service
|
75
|
-
service.entity_sets.each do |type, name|
|
26
|
+
generator.service.entity_sets.each do |type, name|
|
76
27
|
puts "#{name} <EntityType: #{type}>"
|
77
28
|
end
|
78
29
|
|
@@ -86,23 +37,17 @@ opts = Slop.parse do
|
|
86
37
|
on :p, :password=, 'password (optional)', argument: :optional
|
87
38
|
on :a, :auth_type=, 'CURL authentication type (optional)', argument: :optional
|
88
39
|
|
89
|
-
on :
|
40
|
+
on :n, :service_name=, 'OData service name to use', argument: :optional
|
90
41
|
on :m, :model_name=, 'name to give model', argument: :optional
|
91
42
|
on :e, :entity_set=, 'EntitySet to generate model for'
|
92
43
|
|
93
|
-
|
94
|
-
validate_service_url(opts)
|
44
|
+
on :properties=, as: Array, argument: :optional
|
95
45
|
|
96
|
-
|
97
|
-
|
98
|
-
properties = service.properties_for(entity_set.type)
|
99
|
-
|
100
|
-
class_name = opts[:model_name] || entity_set.type
|
101
|
-
service_name = opts[:service_name] || opts[:service_url]
|
102
|
-
properties = Hash[properties.collect {|k,v| [k, nil]}]
|
46
|
+
run do |opts, args|
|
47
|
+
OData::Model::CLI::GeneratorConfiguration.validate_service_url(opts)
|
103
48
|
|
104
|
-
|
105
|
-
puts
|
49
|
+
generator = OData::Model::CLI::GeneratorConfiguration.new(opts)
|
50
|
+
puts generator.generate
|
106
51
|
|
107
52
|
exit(0)
|
108
53
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module OData
|
2
|
+
module Model
|
3
|
+
# Module for classes related to command-line tools
|
4
|
+
module CLI
|
5
|
+
# Represents the configuration for the command-line tool responsible for
|
6
|
+
# model generation.
|
7
|
+
# @api private
|
8
|
+
class GeneratorConfiguration
|
9
|
+
attr_reader :service, :options
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@options = options
|
13
|
+
@service = OData::Service.open(service_url, handle_auth_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
template = ModelTemplate.new(class_name, service_name, properties)
|
18
|
+
template.render
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.validate_service_url(opts)
|
22
|
+
unless opts[:service_url]
|
23
|
+
puts 'You must supply a service_url (-s, --service_url=)'
|
24
|
+
exit(1)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def class_name
|
31
|
+
options[:model_name] || entity_set.type
|
32
|
+
end
|
33
|
+
|
34
|
+
def properties
|
35
|
+
if options[:properties]
|
36
|
+
Hash[options[:properties].collect {|property_set| property_set.split(':')}]
|
37
|
+
else
|
38
|
+
properties = service.properties_for(entity_set.type)
|
39
|
+
Hash[properties.collect {|k,v| [k, nil]}]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def service_name
|
44
|
+
options[:service_name] || service_url
|
45
|
+
end
|
46
|
+
|
47
|
+
def service_url
|
48
|
+
options[:service_url]
|
49
|
+
end
|
50
|
+
|
51
|
+
def entity_set
|
52
|
+
service[options[:entity_set]]
|
53
|
+
end
|
54
|
+
|
55
|
+
def handle_auth_options
|
56
|
+
service_options = {}
|
57
|
+
if options[:username] && options[:password]
|
58
|
+
service_options[:typhoeus] = {
|
59
|
+
username: options[:username],
|
60
|
+
password: options[:password]
|
61
|
+
}
|
62
|
+
if options[:auth_type]
|
63
|
+
auth_type = options[:auth_type].to_sym
|
64
|
+
service_options[:typhoeus][:httpauth] = auth_type
|
65
|
+
end
|
66
|
+
end
|
67
|
+
service_options
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module OData
|
4
|
+
module Model
|
5
|
+
# Module for classes related to command-line tools
|
6
|
+
module CLI
|
7
|
+
# Represents the model template used by the command-line generator.
|
8
|
+
# @api private
|
9
|
+
class ModelTemplate
|
10
|
+
attr_reader :class_name, :service_name, :properties
|
11
|
+
|
12
|
+
def initialize(class_name, service_name, properties, entity_name)
|
13
|
+
@class_name = class_name
|
14
|
+
@service_name = service_name
|
15
|
+
@properties = properties
|
16
|
+
@entity_name = entity_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def template
|
20
|
+
<<-EOS
|
21
|
+
class <%= @class_name %>
|
22
|
+
include OData::Model
|
23
|
+
|
24
|
+
use_service '<%= @service_name %>'
|
25
|
+
<%= @entity_name.nil? ? nil : "use_entity_set '\#\{@entity_name\}'" %>
|
26
|
+
|
27
|
+
<% properties.each do |property_name, as_name| %>
|
28
|
+
property '<%= property_name %>'<%= as_name.nil? ? nil : ", as: :\#\{as_name\}" %>
|
29
|
+
<% end %>
|
30
|
+
end
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
def render
|
35
|
+
renderer = ERB.new(template, 0, '<>')
|
36
|
+
renderer.result(binding)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -59,6 +59,17 @@ module OData
|
|
59
59
|
nil
|
60
60
|
end
|
61
61
|
|
62
|
+
# Define the entity set to use for the current OData::Model. This
|
63
|
+
# method will look up the correct EntitySet using the Entity's type
|
64
|
+
# name.
|
65
|
+
#
|
66
|
+
# @param entity_name [to_s] name of EntityType used by OData Service
|
67
|
+
# @return [nil]
|
68
|
+
def for_entity(entity_name)
|
69
|
+
odata_config[:entity_set_name] = odata_service.entity_sets[entity_name]
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
|
62
73
|
# Get the OData::Service
|
63
74
|
# @return [OData::Service]
|
64
75
|
# @api private
|
@@ -66,6 +77,13 @@ module OData
|
|
66
77
|
odata_config[:service]
|
67
78
|
end
|
68
79
|
|
80
|
+
# Returns the name of the OData::Service used.
|
81
|
+
# @return [String]
|
82
|
+
# @api private
|
83
|
+
def odata_service_name
|
84
|
+
odata_config[:service].name
|
85
|
+
end
|
86
|
+
|
69
87
|
# Get the OData::Service's namespace
|
70
88
|
# @return [String] OData Service's namespace
|
71
89
|
# @api private
|
data/lib/odata/model/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Model do
|
4
|
+
describe 'EntitySet identification and configuration' do
|
5
|
+
describe 'default behavior' do
|
6
|
+
it { expect(Product.odata_entity_set_name).to eq('Products') }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'using for_entity' do
|
10
|
+
it { expect(Person.odata_entity_set_name).to eq('Persons') }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -10,5 +10,8 @@ describe OData::Model do
|
|
10
10
|
|
11
11
|
it { expect(Product).to respond_to(:odata_namespace) }
|
12
12
|
it { expect(Product.odata_namespace).to eq('ODataDemo') }
|
13
|
+
|
14
|
+
it { expect(Product).to respond_to(:odata_service_name) }
|
15
|
+
it { expect(Product.odata_service_name).to eq('ODataDemo') }
|
13
16
|
end
|
14
17
|
end
|
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_person'
|
23
24
|
|
24
25
|
RSpec::Matchers.define :be_boolean do
|
25
26
|
match do |actual|
|
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,16 +157,19 @@ files:
|
|
157
157
|
- lib/odata/model.rb
|
158
158
|
- lib/odata/model/active_model.rb
|
159
159
|
- lib/odata/model/attributes.rb
|
160
|
+
- lib/odata/model/cli/generator_configuration.rb
|
161
|
+
- lib/odata/model/cli/model_template.rb
|
160
162
|
- lib/odata/model/configuration.rb
|
161
163
|
- lib/odata/model/persistence.rb
|
162
164
|
- lib/odata/model/query.rb
|
163
165
|
- lib/odata/model/query_proxy.rb
|
164
|
-
- lib/odata/model/templates/model.erb
|
165
166
|
- lib/odata/model/version.rb
|
166
167
|
- odata-model.gemspec
|
167
168
|
- spec/example_models/bare_model.rb
|
169
|
+
- spec/example_models/odatademo_person.rb
|
168
170
|
- spec/example_models/odatademo_product.rb
|
169
171
|
- spec/model/active_model_lint_spec.rb
|
172
|
+
- spec/model/entity_set_identification_spec.rb
|
170
173
|
- spec/model/property_defaults_spec.rb
|
171
174
|
- spec/model/query_interface_spec.rb
|
172
175
|
- spec/model/query_proxy_spec.rb
|
@@ -198,8 +201,10 @@ specification_version: 4
|
|
198
201
|
summary: An ActiveModel mapping layer for the OData gem
|
199
202
|
test_files:
|
200
203
|
- spec/example_models/bare_model.rb
|
204
|
+
- spec/example_models/odatademo_person.rb
|
201
205
|
- spec/example_models/odatademo_product.rb
|
202
206
|
- spec/model/active_model_lint_spec.rb
|
207
|
+
- spec/model/entity_set_identification_spec.rb
|
203
208
|
- spec/model/property_defaults_spec.rb
|
204
209
|
- spec/model/query_interface_spec.rb
|
205
210
|
- spec/model/query_proxy_spec.rb
|
File without changes
|