odata 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +0 -2
- data/lib/odata/model.rb +3 -0
- data/lib/odata/properties.rb +10 -0
- data/lib/odata/properties/binary.rb +38 -0
- data/lib/odata/properties/boolean.rb +30 -0
- data/lib/odata/properties/date_time.rb +39 -0
- data/lib/odata/properties/date_time_offset.rb +36 -0
- data/lib/odata/properties/decimal.rb +39 -0
- data/lib/odata/properties/float.rb +56 -0
- data/lib/odata/properties/guid.rb +9 -0
- data/lib/odata/properties/integer.rb +104 -0
- data/lib/odata/properties/string.rb +9 -0
- data/lib/odata/properties/time.rb +34 -0
- data/lib/odata/property.rb +73 -0
- data/lib/odata/service.rb +27 -14
- data/lib/odata/version.rb +1 -1
- data/spec/odata/properties/binary_spec.rb +48 -0
- data/spec/odata/properties/boolean_spec.rb +62 -0
- data/spec/odata/properties/date_time_offset_spec.rb +16 -0
- data/spec/odata/properties/date_time_spec.rb +21 -0
- data/spec/odata/properties/decimal_spec.rb +21 -0
- data/spec/odata/properties/float_spec.rb +43 -0
- data/spec/odata/properties/guid_spec.rb +15 -0
- data/spec/odata/properties/integer_spec.rb +58 -0
- data/spec/odata/properties/string_spec.rb +13 -0
- data/spec/odata/properties/time_spec.rb +15 -0
- data/spec/odata/property_spec.rb +58 -0
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f93b8a7046cdffd27d35aa5bd2e2ca565adb8e6
|
4
|
+
data.tar.gz: e0e75126d52b80bef3bffc5b8a0a76d934631807
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 547f5aa48bc1b31c67ccd009dbf7b43ad32b6dbd6c4a38fdd3a0cc8c55ce97608779adc048bb44cb0d52064d70452a4e25f2471e873e7f12556911ed3fe8ef48
|
7
|
+
data.tar.gz: b77801487b5f05c0982a04ebffa103b47434eba6a6adce9a578166e4e69a3992b91e9f4c021b9cccf80f62ef7b16b013dd0a5cda66bbbb974c1b63d5d45d7dda
|
data/.rspec
CHANGED
data/lib/odata/model.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'odata/properties/binary'
|
2
|
+
require 'odata/properties/boolean'
|
3
|
+
require 'odata/properties/date_time'
|
4
|
+
require 'odata/properties/date_time_offset'
|
5
|
+
require 'odata/properties/decimal'
|
6
|
+
require 'odata/properties/float'
|
7
|
+
require 'odata/properties/guid'
|
8
|
+
require 'odata/properties/integer'
|
9
|
+
require 'odata/properties/string'
|
10
|
+
require 'odata/properties/time'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module OData
|
2
|
+
module Properties
|
3
|
+
class Binary < OData::Property
|
4
|
+
def value
|
5
|
+
if @value.nil? && allows_nil?
|
6
|
+
nil
|
7
|
+
else
|
8
|
+
@value.to_i
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value=(new_value)
|
13
|
+
validate(new_value)
|
14
|
+
@value = parse_value(new_value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
'Edm.Binary'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse_value(value)
|
24
|
+
if value == 0 || value == '0' || value == false
|
25
|
+
'0'
|
26
|
+
else
|
27
|
+
'1'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate(value)
|
32
|
+
unless [0,1,'0','1',true,false].include?(value)
|
33
|
+
raise ArgumentError, 'Value is outside accepted range: 0 or 1'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module OData
|
2
|
+
module Properties
|
3
|
+
class Boolean < OData::Property
|
4
|
+
def value
|
5
|
+
if @value.nil? && allows_nil?
|
6
|
+
nil
|
7
|
+
else
|
8
|
+
(@value == 'true' || @value == '1')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value=(new_value)
|
13
|
+
validate(new_value)
|
14
|
+
@value = new_value.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
'Edm.Boolean'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate(value)
|
24
|
+
unless [0,1,'0','1','true','false',true,false].include?(value)
|
25
|
+
raise ArgumentError, 'Value is outside accepted range: true or false'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module OData
|
2
|
+
module Properties
|
3
|
+
class DateTime < OData::Property
|
4
|
+
def value
|
5
|
+
if @value.nil? && allow_nil?
|
6
|
+
nil
|
7
|
+
else
|
8
|
+
::DateTime.strptime(@value, '%Y-%m-%dT%H:%M:%S.%L')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value=(new_value)
|
13
|
+
validate(new_value)
|
14
|
+
@value = parse_value(new_value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
'Edm.DateTime'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate(value)
|
24
|
+
begin
|
25
|
+
return if value.is_a?(::DateTime)
|
26
|
+
::DateTime.strptime(value, '%Y-%m-%dT%H:%M:%S.%L')
|
27
|
+
rescue => e
|
28
|
+
raise ArgumentError, 'Value is not a date time format that can be parsed'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_value(value)
|
33
|
+
parsed_value = value
|
34
|
+
parsed_value = ::DateTime.parse(value) unless value.is_a?(::DateTime)
|
35
|
+
parsed_value.strftime('%Y-%m-%dT%H:%M:%S.%L')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module OData
|
2
|
+
module Properties
|
3
|
+
class DateTimeOffset < OData::Property
|
4
|
+
def value
|
5
|
+
if @value.nil? && allow_nil?
|
6
|
+
nil
|
7
|
+
else
|
8
|
+
::DateTime.strptime(@value, '%Y-%m-%dT%H:%M:%S.%LZ%:z')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value=(new_value)
|
13
|
+
validate(new_value)
|
14
|
+
@value = parse_value(new_value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
'Edm.DateTimeOffset'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate(value)
|
24
|
+
unless value.is_a?(::DateTime)
|
25
|
+
raise ArgumentError, 'Value is not a date time format that can be parsed'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_value(value)
|
30
|
+
parsed_value = value
|
31
|
+
parsed_value = ::DateTime.parse(value) unless value.is_a?(::DateTime)
|
32
|
+
parsed_value.strftime('%Y-%m-%dT%H:%M:%S.%LZ%:z')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module OData
|
2
|
+
module Properties
|
3
|
+
class Decimal < OData::Property
|
4
|
+
def value
|
5
|
+
if @value.nil? && allows_nil?
|
6
|
+
nil
|
7
|
+
else
|
8
|
+
BigDecimal(@value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value=(new_value)
|
13
|
+
validate(BigDecimal(new_value))
|
14
|
+
@value = new_value.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
'Edm.Decimal'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate(value)
|
24
|
+
if (value > max_value || value < min_value) &&
|
25
|
+
(value.exponent > 29 || value.exponent < -29)
|
26
|
+
raise ::ArgumentError, "Value is outside accepted range: #{min_value} to #{max_value}, or has more than 29 significant digits"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def min_value
|
31
|
+
@min ||= -(7.9 * (10**28))
|
32
|
+
end
|
33
|
+
|
34
|
+
def max_value
|
35
|
+
@max ||= (7.9 * (10**28))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module OData
|
2
|
+
module Properties
|
3
|
+
class Float < OData::Property
|
4
|
+
def value
|
5
|
+
if @value.nil? && allows_nil?
|
6
|
+
nil
|
7
|
+
else
|
8
|
+
@value.to_f
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value=(new_value)
|
13
|
+
validate(new_value.to_f)
|
14
|
+
@value = new_value.to_f.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
'Edm.Double'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate(value)
|
24
|
+
if value > max_value || value < min_value
|
25
|
+
raise ::ArgumentError, "Value is outside accepted range: #{min_value} to #{max_value}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def min_value
|
30
|
+
@min ||= -(1.7 * (10**308))
|
31
|
+
end
|
32
|
+
|
33
|
+
def max_value
|
34
|
+
@max ||= (1.7 * (10**308))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Double < OData::Properties::Float; end
|
39
|
+
|
40
|
+
class Single < OData::Properties::Float
|
41
|
+
def type
|
42
|
+
'Edm.Single'
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def min_value
|
48
|
+
@min ||= -(3.4 * (10**38))
|
49
|
+
end
|
50
|
+
|
51
|
+
def max_value
|
52
|
+
@max ||= (3.4 * (10**38))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module OData
|
2
|
+
module Properties
|
3
|
+
class Integer < OData::Property
|
4
|
+
def value
|
5
|
+
if @value.nil? && allows_nil?
|
6
|
+
nil
|
7
|
+
else
|
8
|
+
@value.to_i
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value=(new_value)
|
13
|
+
validate(new_value.to_i)
|
14
|
+
@value = new_value.to_i.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
'Edm.Int64'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate(value)
|
24
|
+
if value > max_value || value < min_value
|
25
|
+
raise ::ArgumentError, "Value is outside accepted range: #{min_value} to #{max_value}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def min_value
|
30
|
+
@min ||= -(2**63)
|
31
|
+
end
|
32
|
+
|
33
|
+
def max_value
|
34
|
+
@max ||= (2**63)-1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Int16 < Integer
|
39
|
+
def type
|
40
|
+
'Edm.Int16'
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def min_value
|
46
|
+
@min ||= -(2**15)
|
47
|
+
end
|
48
|
+
|
49
|
+
def max_value
|
50
|
+
@max ||= (2**15)-1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Int32 < Integer
|
55
|
+
def type
|
56
|
+
'Edm.Int32'
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def min_value
|
62
|
+
@min ||= -(2**15)
|
63
|
+
end
|
64
|
+
|
65
|
+
def max_value
|
66
|
+
@max ||= (2**15)-1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Int64 < Integer; end
|
71
|
+
|
72
|
+
class Byte < Integer
|
73
|
+
def type
|
74
|
+
'Edm.Byte'
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def min_value
|
80
|
+
0
|
81
|
+
end
|
82
|
+
|
83
|
+
def max_value
|
84
|
+
@max ||= (2**8)-1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class SByte < Integer
|
89
|
+
def type
|
90
|
+
'Edm.SByte'
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def min_value
|
96
|
+
@min ||= -(2**7)
|
97
|
+
end
|
98
|
+
|
99
|
+
def max_value
|
100
|
+
@max ||= (2**7)-1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module OData
|
2
|
+
module Properties
|
3
|
+
class Time < OData::Property
|
4
|
+
def value
|
5
|
+
if @value.nil? && allow_nil?
|
6
|
+
nil
|
7
|
+
else
|
8
|
+
::Time.strptime(@value, '%H:%M:%S%:z')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value=(new_value)
|
13
|
+
validate(new_value)
|
14
|
+
@value = parse_value(new_value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
'Edm.Time'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate(value)
|
24
|
+
unless value.is_a?(::Time)
|
25
|
+
raise ArgumentError, 'Value is not a time object'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_value(value)
|
30
|
+
value.strftime('%H:%M:%S%:z')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module OData
|
2
|
+
class Property
|
3
|
+
attr_reader :name
|
4
|
+
attr_accessor :value
|
5
|
+
|
6
|
+
def initialize(name, value, options = {})
|
7
|
+
@name = name.to_s
|
8
|
+
@value = value.nil? ? nil : value.to_s
|
9
|
+
@options = default_options.merge(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
raise NotImplementedError
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(other)
|
17
|
+
self.value == other.value
|
18
|
+
end
|
19
|
+
|
20
|
+
def allows_nil?
|
21
|
+
@allows_nil ||= options[:allows_nil]
|
22
|
+
end
|
23
|
+
|
24
|
+
def max_length
|
25
|
+
raise NotImplementedError
|
26
|
+
end
|
27
|
+
|
28
|
+
def fixed_length
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
|
32
|
+
def precision
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
|
36
|
+
def scale
|
37
|
+
raise NotImplementedError
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_unicode?
|
41
|
+
raise NotImplementedError
|
42
|
+
end
|
43
|
+
|
44
|
+
def collation
|
45
|
+
raise NotImplementedError
|
46
|
+
end
|
47
|
+
|
48
|
+
def srid
|
49
|
+
raise NotImplementedError
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_value
|
53
|
+
raise NotImplementedError
|
54
|
+
end
|
55
|
+
|
56
|
+
def concurrency_mode
|
57
|
+
@concurrecy_mode ||= options[:concurrency_mode]
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def default_options
|
63
|
+
{
|
64
|
+
allows_nil: true,
|
65
|
+
concurrency_mode: :none
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def options
|
70
|
+
@options
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/odata/service.rb
CHANGED
@@ -5,13 +5,18 @@ module OData
|
|
5
5
|
# The OData Service's URL
|
6
6
|
attr_reader :service_url
|
7
7
|
|
8
|
+
# Options to pass around
|
9
|
+
attr_reader :options
|
10
|
+
|
8
11
|
# Opens the service based on the requested URL and adds the service to
|
9
12
|
# {OData::Registry}
|
10
13
|
#
|
11
14
|
# @param service_url [String] the URL to the desired OData service
|
15
|
+
# @param options [Hash] options to pass to the service
|
12
16
|
# @return [OData::Service] an instance of the service
|
13
|
-
def initialize(service_url)
|
17
|
+
def initialize(service_url, options = {})
|
14
18
|
@service_url = service_url
|
19
|
+
@options = default_options.merge(options)
|
15
20
|
OData::ServiceRegistry.add(self)
|
16
21
|
self
|
17
22
|
end
|
@@ -20,9 +25,10 @@ module OData
|
|
20
25
|
# {OData::Registry}
|
21
26
|
#
|
22
27
|
# @param service_url [String] the URL to the desired OData service
|
28
|
+
# @param options [Hash] options to pass to the service
|
23
29
|
# @return [OData::Service] an instance of the service
|
24
|
-
def self.open(service_url)
|
25
|
-
Service.new(service_url)
|
30
|
+
def self.open(service_url, options = {})
|
31
|
+
Service.new(service_url, options)
|
26
32
|
end
|
27
33
|
|
28
34
|
# Returns a list of entities exposed by the service
|
@@ -53,7 +59,9 @@ module OData
|
|
53
59
|
def get(model, criteria = {})
|
54
60
|
request = ::Typhoeus::Request.new(
|
55
61
|
build_request_url(model, criteria),
|
56
|
-
|
62
|
+
options[:typhoeus].merge({
|
63
|
+
method: :get
|
64
|
+
})
|
57
65
|
)
|
58
66
|
request.run
|
59
67
|
response = request.response
|
@@ -63,11 +71,19 @@ module OData
|
|
63
71
|
|
64
72
|
private
|
65
73
|
|
74
|
+
def default_options
|
75
|
+
{
|
76
|
+
typhoeus: {}
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
66
80
|
def metadata
|
67
81
|
@metadata ||= lambda {
|
68
82
|
request = ::Typhoeus::Request.new(
|
69
83
|
"#{service_url}/$metadata",
|
70
|
-
|
84
|
+
options[:typhoeus].merge({
|
85
|
+
method: :get
|
86
|
+
})
|
71
87
|
)
|
72
88
|
request.run
|
73
89
|
response = request.response
|
@@ -84,15 +100,12 @@ module OData
|
|
84
100
|
def parse_model_from_feed(model, entry)
|
85
101
|
attributes = {}
|
86
102
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
value: entry.xpath('//summary').first.content,
|
94
|
-
type: entry.xpath('//summary').first.attributes['type'].value
|
95
|
-
}
|
103
|
+
%w{title summary}.each do |attribute_name|
|
104
|
+
attributes[attribute_name.to_sym] = {
|
105
|
+
value: entry.xpath("//#{attribute_name}").first.content,
|
106
|
+
type: entry.xpath("//#{attribute_name}").first.attributes['type'].value
|
107
|
+
}
|
108
|
+
end
|
96
109
|
|
97
110
|
entry.xpath('//content/properties/*').each do |property|
|
98
111
|
if property.attributes['null']
|
data/lib/odata/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::Binary do
|
4
|
+
let(:subject) { OData::Properties::Binary.new('On', '1') }
|
5
|
+
|
6
|
+
it { expect(subject.type).to eq('Edm.Binary') }
|
7
|
+
it { expect(subject.value).to eq(1) }
|
8
|
+
|
9
|
+
it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
|
10
|
+
|
11
|
+
describe 'setting to 0' do
|
12
|
+
it { expect(lambda {
|
13
|
+
subject.value = 0
|
14
|
+
subject.value
|
15
|
+
}.call).to eq(0) }
|
16
|
+
|
17
|
+
it { expect(lambda {
|
18
|
+
subject.value = false
|
19
|
+
subject.value
|
20
|
+
}.call).to eq(0) }
|
21
|
+
|
22
|
+
it { expect(lambda {
|
23
|
+
subject.value = '0'
|
24
|
+
subject.value
|
25
|
+
}.call).to eq(0) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'setting to 1' do
|
29
|
+
let(:subject) { OData::Properties::Binary.new('On', '0') }
|
30
|
+
|
31
|
+
it { expect(subject.value).to eq(0) }
|
32
|
+
|
33
|
+
it { expect(lambda {
|
34
|
+
subject.value = 1
|
35
|
+
subject.value
|
36
|
+
}.call).to eq(1) }
|
37
|
+
|
38
|
+
it { expect(lambda {
|
39
|
+
subject.value = true
|
40
|
+
subject.value
|
41
|
+
}.call).to eq(1) }
|
42
|
+
|
43
|
+
it { expect(lambda {
|
44
|
+
subject.value = '1'
|
45
|
+
subject.value
|
46
|
+
}.call).to eq(1) }
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::Boolean do
|
4
|
+
let(:truthy1) { OData::Properties::Boolean.new('Truthy', 'true') }
|
5
|
+
let(:truthy2) { OData::Properties::Boolean.new('Truthy', '1') }
|
6
|
+
let(:falsey1) { OData::Properties::Boolean.new('Falsey', 'false') }
|
7
|
+
let(:falsey2) { OData::Properties::Boolean.new('Falsey', '0') }
|
8
|
+
let(:nily) { OData::Properties::Boolean.new('Nily', nil) }
|
9
|
+
|
10
|
+
it { expect(truthy1.type).to eq('Edm.Boolean') }
|
11
|
+
it { expect(truthy1.value).to eq(true) }
|
12
|
+
it { expect(truthy2.value).to eq(true) }
|
13
|
+
|
14
|
+
it { expect(falsey1.value).to eq(false) }
|
15
|
+
it { expect(falsey2.value).to eq(false) }
|
16
|
+
|
17
|
+
it { expect(nily.value).to eq(nil) }
|
18
|
+
|
19
|
+
it { expect {truthy1.value = 'bad'}.to raise_error(ArgumentError) }
|
20
|
+
|
21
|
+
describe 'setting to false' do
|
22
|
+
let(:subject) { OData::Properties::Boolean.new('Truthy', 'true') }
|
23
|
+
|
24
|
+
it { expect(subject.value).to eq(true) }
|
25
|
+
|
26
|
+
it { expect(lambda {
|
27
|
+
subject.value = false
|
28
|
+
subject.value
|
29
|
+
}.call).to eq(false) }
|
30
|
+
|
31
|
+
it { expect(lambda {
|
32
|
+
subject.value = 'false'
|
33
|
+
subject.value
|
34
|
+
}.call).to eq(false) }
|
35
|
+
|
36
|
+
it { expect(lambda {
|
37
|
+
subject.value = '0'
|
38
|
+
subject.value
|
39
|
+
}.call).to eq(false) }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'setting to true' do
|
43
|
+
let(:subject) { OData::Properties::Boolean.new('Falsey', 'false') }
|
44
|
+
|
45
|
+
it { expect(subject.value).to eq(false) }
|
46
|
+
|
47
|
+
it { expect(lambda {
|
48
|
+
subject.value = true
|
49
|
+
subject.value
|
50
|
+
}.call).to eq(true) }
|
51
|
+
|
52
|
+
it { expect(lambda {
|
53
|
+
subject.value = 'true'
|
54
|
+
subject.value
|
55
|
+
}.call).to eq(true) }
|
56
|
+
|
57
|
+
it { expect(lambda {
|
58
|
+
subject.value = '1'
|
59
|
+
subject.value
|
60
|
+
}.call).to eq(true) }
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::DateTimeOffset do
|
4
|
+
let(:subject) { OData::Properties::DateTimeOffset.new('DateTime', '2000-01-01T16:00:00.000Z-09:00') }
|
5
|
+
let(:new_datetime) { DateTime.strptime('2004-05-01T14:32:00.000Z+02:00', '%Y-%m-%dT%H:%M:%S.%LZ%:z') }
|
6
|
+
|
7
|
+
it { expect(subject.type).to eq('Edm.DateTimeOffset') }
|
8
|
+
it { expect(subject.value).to eq(DateTime.strptime('2000-01-01T16:00:00.000Z-09:00', '%Y-%m-%dT%H:%M:%S.%LZ%:z')) }
|
9
|
+
|
10
|
+
it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
|
11
|
+
|
12
|
+
it { expect(lambda {
|
13
|
+
subject.value = new_datetime
|
14
|
+
subject.value
|
15
|
+
}.call).to eq(new_datetime) }
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::DateTime do
|
4
|
+
let(:subject) { OData::Properties::DateTime.new('DateTime', '2000-01-01T16:00:00.000') }
|
5
|
+
let(:new_datetime) { DateTime.strptime('2004-05-01T14:32:00.000', '%Y-%m-%dT%H:%M:%S.%L') }
|
6
|
+
|
7
|
+
it { expect(subject.type).to eq('Edm.DateTime') }
|
8
|
+
it { expect(subject.value).to eq(DateTime.parse('2000-01-01T16:00:00.000')) }
|
9
|
+
|
10
|
+
it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
|
11
|
+
|
12
|
+
it { expect(lambda {
|
13
|
+
subject.value = '2004-05-01T14:32:00.000'
|
14
|
+
subject.value
|
15
|
+
}.call).to eq(new_datetime) }
|
16
|
+
|
17
|
+
it { expect(lambda {
|
18
|
+
subject.value = new_datetime
|
19
|
+
subject.value
|
20
|
+
}.call).to eq(new_datetime) }
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::Decimal do
|
4
|
+
let(:subject) { OData::Properties::Decimal.new('Decimal', '678.90325') }
|
5
|
+
|
6
|
+
it { expect(subject.type).to eq('Edm.Decimal') }
|
7
|
+
it { expect(subject.value).to eq(BigDecimal('678.90325')) }
|
8
|
+
|
9
|
+
it { expect { subject.value = BigDecimal((7.9 * (10**28)) + 1) }.to raise_error(ArgumentError) }
|
10
|
+
it { expect { subject.value = BigDecimal((-7.9 * (10**28)) - 1) }.to raise_error(ArgumentError) }
|
11
|
+
|
12
|
+
it { expect(lambda {
|
13
|
+
subject.value = '19.89043256'
|
14
|
+
subject.value
|
15
|
+
}.call).to eq(BigDecimal('19.89043256')) }
|
16
|
+
|
17
|
+
it { expect(lambda {
|
18
|
+
subject.value = BigDecimal('19.89043256')
|
19
|
+
subject.value
|
20
|
+
}.call).to eq(BigDecimal('19.89043256')) }
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::Float do
|
4
|
+
describe 'double precision' do
|
5
|
+
let(:subject) { OData::Properties::Double.new('Float', '678.90325') }
|
6
|
+
|
7
|
+
it { expect(subject.type).to eq('Edm.Double') }
|
8
|
+
it { expect(subject.value).to eq(678.90325) }
|
9
|
+
|
10
|
+
it { expect { subject.value = (1.7 * (10**308) * 2) }.to raise_error(ArgumentError) }
|
11
|
+
it { expect { subject.value = (-1.7 * (10**308) * 2) }.to raise_error(ArgumentError) }
|
12
|
+
|
13
|
+
it { expect(lambda {
|
14
|
+
subject.value = '19.89043256'
|
15
|
+
subject.value
|
16
|
+
}.call).to eq(19.89043256) }
|
17
|
+
|
18
|
+
it { expect(lambda {
|
19
|
+
subject.value = 19.89043256
|
20
|
+
subject.value
|
21
|
+
}.call).to eq(19.89043256) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'single precision' do
|
25
|
+
let(:subject) { OData::Properties::Single.new('Float', '678.90325') }
|
26
|
+
|
27
|
+
it { expect(subject.type).to eq('Edm.Single') }
|
28
|
+
it { expect(subject.value).to eq(678.90325) }
|
29
|
+
|
30
|
+
it { expect { subject.value = (3.4 * (10**38) * 2) }.to raise_error(ArgumentError) }
|
31
|
+
it { expect { subject.value = (-3.4 * (10**38) * 2) }.to raise_error(ArgumentError) }
|
32
|
+
|
33
|
+
it { expect(lambda {
|
34
|
+
subject.value = '19.89043256'
|
35
|
+
subject.value
|
36
|
+
}.call).to eq(19.89043256) }
|
37
|
+
|
38
|
+
it { expect(lambda {
|
39
|
+
subject.value = 19.89043256
|
40
|
+
subject.value
|
41
|
+
}.call).to eq(19.89043256) }
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::Guid do
|
4
|
+
let(:guid) { SecureRandom.uuid }
|
5
|
+
let(:guid2) { SecureRandom.uuid }
|
6
|
+
let(:subject) { OData::Properties::Guid.new('Stringy', guid) }
|
7
|
+
|
8
|
+
it { expect(subject.type).to eq('Edm.Guid') }
|
9
|
+
it { expect(subject.value).to eq(guid)}
|
10
|
+
|
11
|
+
it { expect(lambda {
|
12
|
+
subject.value = guid2
|
13
|
+
subject.value
|
14
|
+
}.call).to eq(guid2) }
|
15
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::Integer do
|
4
|
+
let(:subject) { OData::Properties::Integer.new('Integer', '32') }
|
5
|
+
let(:subject16) { OData::Properties::Int16.new('Int16', '32') }
|
6
|
+
let(:subject32) { OData::Properties::Int32.new('Int32', '32') }
|
7
|
+
let(:subject64) { OData::Properties::Int64.new('Int64', '32') }
|
8
|
+
let(:subjectbyte) { OData::Properties::Byte.new('Byte', '32') }
|
9
|
+
let(:subjectsbyte) { OData::Properties::SByte.new('SByte', '32') }
|
10
|
+
|
11
|
+
it { expect(subject.type).to eq('Edm.Int64') }
|
12
|
+
it { expect(subject.value).to eq(32) }
|
13
|
+
it { expect {subject.value = (2**63)}.to raise_error(ArgumentError) }
|
14
|
+
it { expect {subject.value = (-(2**63) - 1)}.to raise_error(ArgumentError) }
|
15
|
+
|
16
|
+
it { expect(subject16.type).to eq('Edm.Int16') }
|
17
|
+
it { expect(subject16.value).to eq(32) }
|
18
|
+
it { expect {subject16.value = (2**15)}.to raise_error(ArgumentError) }
|
19
|
+
it { expect {subject16.value = (-(2**15) - 1)}.to raise_error(ArgumentError) }
|
20
|
+
|
21
|
+
it { expect(subject32.type).to eq('Edm.Int32') }
|
22
|
+
it { expect(subject32.value).to eq(32) }
|
23
|
+
it { expect {subject32.value = (2**31)}.to raise_error(ArgumentError) }
|
24
|
+
it { expect {subject32.value = (-(2**31) - 1)}.to raise_error(ArgumentError) }
|
25
|
+
|
26
|
+
it { expect(subject64.type).to eq('Edm.Int64') }
|
27
|
+
it { expect(subject64.value).to eq(32) }
|
28
|
+
it { expect {subject64.value = (2**63)}.to raise_error(ArgumentError) }
|
29
|
+
it { expect {subject64.value = (-(2**63) - 1)}.to raise_error(ArgumentError) }
|
30
|
+
|
31
|
+
it { expect(subjectbyte.type).to eq('Edm.Byte') }
|
32
|
+
it { expect(subjectbyte.value).to eq(32) }
|
33
|
+
it { expect {subjectbyte.value = 2**8}.to raise_error(ArgumentError) }
|
34
|
+
it { expect {subjectbyte.value = -1}.to raise_error(ArgumentError) }
|
35
|
+
|
36
|
+
it { expect(subjectsbyte.type).to eq('Edm.SByte') }
|
37
|
+
it { expect(subjectsbyte.value).to eq(32) }
|
38
|
+
it { expect {subjectsbyte.value = (2**7)}.to raise_error(ArgumentError) }
|
39
|
+
it { expect {subjectsbyte.value = (-(2**7) - 1)}.to raise_error(ArgumentError) }
|
40
|
+
|
41
|
+
describe '#value=' do
|
42
|
+
before(:example) do
|
43
|
+
subject.value = 128
|
44
|
+
subject16.value = 128
|
45
|
+
subject32.value = 128
|
46
|
+
subject64.value = 128
|
47
|
+
subjectbyte.value = 12
|
48
|
+
subjectsbyte.value = 12
|
49
|
+
end
|
50
|
+
|
51
|
+
it { expect(subject.value).to eq(128) }
|
52
|
+
it { expect(subject16.value).to eq(128) }
|
53
|
+
it { expect(subject32.value).to eq(128) }
|
54
|
+
it { expect(subject64.value).to eq(128) }
|
55
|
+
it { expect(subjectbyte.value).to eq(12) }
|
56
|
+
it { expect(subjectsbyte.value).to eq(12) }
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::String do
|
4
|
+
let(:subject) { OData::Properties::String.new('Stringy', 'This is an example') }
|
5
|
+
|
6
|
+
it { expect(subject.type).to eq('Edm.String') }
|
7
|
+
it { expect(subject.value).to eq('This is an example')}
|
8
|
+
|
9
|
+
it { expect(lambda {
|
10
|
+
subject.value = 'Another example'
|
11
|
+
subject.value
|
12
|
+
}.call).to eq('Another example') }
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Properties::Time do
|
4
|
+
let(:subject) { OData::Properties::Time.new('Timely', '21:00:00-08:00') }
|
5
|
+
|
6
|
+
it { expect(subject.type).to eq('Edm.Time') }
|
7
|
+
it { expect(subject.value).to eq(Time.strptime('21:00:00-08:00', '%H:%M:%S%:z')) }
|
8
|
+
|
9
|
+
it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
|
10
|
+
|
11
|
+
it { expect(lambda {
|
12
|
+
subject.value = Time.strptime('13:22:12+04:00', '%H:%M:%S%:z')
|
13
|
+
subject.value
|
14
|
+
}.call).to eq(Time.strptime('13:22:12+04:00', '%H:%M:%S%:z'))}
|
15
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Property do
|
4
|
+
let(:subject) { OData::Property.new('PropertyName', '1') }
|
5
|
+
let(:good_comparison) { OData::Property.new('GoodComparison', '1') }
|
6
|
+
let(:bad_comparison) { OData::Property.new('BadComparison', '2') }
|
7
|
+
|
8
|
+
it { expect(subject).to respond_to(:name) }
|
9
|
+
it { expect(subject.name).to eq('PropertyName') }
|
10
|
+
|
11
|
+
it { expect(subject).to respond_to(:value) }
|
12
|
+
it { expect(subject.value).to eq('1') }
|
13
|
+
|
14
|
+
it { expect(subject).to respond_to(:type) }
|
15
|
+
it { expect(lambda {subject.type}).to raise_error(NotImplementedError) }
|
16
|
+
|
17
|
+
it { expect(subject).to respond_to(:allows_nil?) }
|
18
|
+
it { expect(subject.allows_nil?).to eq(true) }
|
19
|
+
|
20
|
+
it { expect(subject).to respond_to(:max_length) }
|
21
|
+
it { expect(lambda {subject.max_length}).to raise_error(NotImplementedError) }
|
22
|
+
#it { expect(subject.max_length).to eq(nil) }
|
23
|
+
|
24
|
+
it { expect(subject).to respond_to(:fixed_length) }
|
25
|
+
it { expect(lambda {subject.fixed_length}).to raise_error(NotImplementedError) }
|
26
|
+
#it { expect(subject.fixed_length).to eq(nil) }
|
27
|
+
|
28
|
+
it { expect(subject).to respond_to(:precision) }
|
29
|
+
it { expect(lambda {subject.precision}).to raise_error(NotImplementedError) }
|
30
|
+
#it { expect(subject.precision).to eq(nil) }
|
31
|
+
|
32
|
+
it { expect(subject).to respond_to(:scale) }
|
33
|
+
it { expect(lambda {subject.scale}).to raise_error(NotImplementedError) }
|
34
|
+
#it { expect(subject.scale).to eq(nil) }
|
35
|
+
|
36
|
+
it { expect(subject).to respond_to(:is_unicode?) }
|
37
|
+
it { expect(lambda {subject.is_unicode?}).to raise_error(NotImplementedError) }
|
38
|
+
#it { expect(subject.is_unicode?).to eq(true) }
|
39
|
+
|
40
|
+
it { expect(subject).to respond_to(:collation) }
|
41
|
+
it { expect(lambda {subject.collation}).to raise_error(NotImplementedError) }
|
42
|
+
#it { expect(subject.collation).to eq(nil) }
|
43
|
+
|
44
|
+
it { expect(subject).to respond_to(:srid) }
|
45
|
+
it { expect(lambda {subject.srid}).to raise_error(NotImplementedError) }
|
46
|
+
#it { expect(subject.srid).to eq(0) }
|
47
|
+
|
48
|
+
it { expect(subject).to respond_to(:default_value) }
|
49
|
+
it { expect(lambda {subject.default_value}).to raise_error(NotImplementedError) }
|
50
|
+
#it { expect(subject.default_value).to eq(nil) }
|
51
|
+
|
52
|
+
it { expect(subject).to respond_to(:concurrency_mode) }
|
53
|
+
it { expect(subject.concurrency_mode).to eq(:none) }
|
54
|
+
|
55
|
+
it { expect(subject).to respond_to(:==) }
|
56
|
+
it { expect(subject == good_comparison).to eq(true) }
|
57
|
+
it { expect(subject == bad_comparison).to eq(false) }
|
58
|
+
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.0.
|
4
|
+
version: 0.0.8
|
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-06-
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -153,6 +153,18 @@ files:
|
|
153
153
|
- Rakefile
|
154
154
|
- lib/odata.rb
|
155
155
|
- lib/odata/model.rb
|
156
|
+
- lib/odata/properties.rb
|
157
|
+
- lib/odata/properties/binary.rb
|
158
|
+
- lib/odata/properties/boolean.rb
|
159
|
+
- lib/odata/properties/date_time.rb
|
160
|
+
- lib/odata/properties/date_time_offset.rb
|
161
|
+
- lib/odata/properties/decimal.rb
|
162
|
+
- lib/odata/properties/float.rb
|
163
|
+
- lib/odata/properties/guid.rb
|
164
|
+
- lib/odata/properties/integer.rb
|
165
|
+
- lib/odata/properties/string.rb
|
166
|
+
- lib/odata/properties/time.rb
|
167
|
+
- lib/odata/property.rb
|
156
168
|
- lib/odata/railtie.rb
|
157
169
|
- lib/odata/service.rb
|
158
170
|
- lib/odata/service_registry.rb
|
@@ -163,6 +175,17 @@ files:
|
|
163
175
|
- spec/fixtures/sample_service/product_0.xml
|
164
176
|
- spec/fixtures/sample_service/products.xml
|
165
177
|
- spec/odata/model_spec.rb
|
178
|
+
- spec/odata/properties/binary_spec.rb
|
179
|
+
- spec/odata/properties/boolean_spec.rb
|
180
|
+
- spec/odata/properties/date_time_offset_spec.rb
|
181
|
+
- spec/odata/properties/date_time_spec.rb
|
182
|
+
- spec/odata/properties/decimal_spec.rb
|
183
|
+
- spec/odata/properties/float_spec.rb
|
184
|
+
- spec/odata/properties/guid_spec.rb
|
185
|
+
- spec/odata/properties/integer_spec.rb
|
186
|
+
- spec/odata/properties/string_spec.rb
|
187
|
+
- spec/odata/properties/time_spec.rb
|
188
|
+
- spec/odata/property_spec.rb
|
166
189
|
- spec/odata/service_registry_spec.rb
|
167
190
|
- spec/odata/service_spec.rb
|
168
191
|
- spec/spec_helper.rb
|
@@ -196,6 +219,17 @@ test_files:
|
|
196
219
|
- spec/fixtures/sample_service/product_0.xml
|
197
220
|
- spec/fixtures/sample_service/products.xml
|
198
221
|
- spec/odata/model_spec.rb
|
222
|
+
- spec/odata/properties/binary_spec.rb
|
223
|
+
- spec/odata/properties/boolean_spec.rb
|
224
|
+
- spec/odata/properties/date_time_offset_spec.rb
|
225
|
+
- spec/odata/properties/date_time_spec.rb
|
226
|
+
- spec/odata/properties/decimal_spec.rb
|
227
|
+
- spec/odata/properties/float_spec.rb
|
228
|
+
- spec/odata/properties/guid_spec.rb
|
229
|
+
- spec/odata/properties/integer_spec.rb
|
230
|
+
- spec/odata/properties/string_spec.rb
|
231
|
+
- spec/odata/properties/time_spec.rb
|
232
|
+
- spec/odata/property_spec.rb
|
199
233
|
- spec/odata/service_registry_spec.rb
|
200
234
|
- spec/odata/service_spec.rb
|
201
235
|
- spec/spec_helper.rb
|