acfs 0.31.0.1.b265 → 0.31.0.1.b269
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/acfs/model/attributes/uuid.rb +44 -0
- data/spec/acfs/model/attributes/uuid_spec.rb +63 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWZhM2Q3OWE5NGQxODRjYzdiMTM2ZTI5ZTM5ZDc0NmIxNDg4Mzk0Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGE1MDJhZmM0ZTBlNGRmMzAyYTkwZDM3Y2M5OTM1N2ZhNjBlMmVjNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzVhOGI4MzVjYWFhMWI5OTgyZGQ3NDU2YjViOTA5ZWNlM2UyNDMwZTMwMzkz
|
10
|
+
YTJjNWQ5ODZlMzU2MTJiZWYxYTExYTIzYTQ3MmFiZjA3NTFjZjQ1YzBiMzYy
|
11
|
+
Y2E4ZTdlNTc5ZDRjNDA1NjRmYWRlOTEyMTZlZjA4NjUwYzgyNzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzkzMzFmMzVmYjA4NTc2NDk4OGQ0MzhhOGM4MzU0ZGNiMGZlZDliMmNjZDI1
|
14
|
+
YjZjYTJmMGU2YmFmOTM0NTBiODJmNWMwMzA1YWU3YWY1ZjM5NzMwZmRjMjU3
|
15
|
+
MmNhMmVlZDQyY2VlNzQxZjZjYjk3OGVlNGU0Y2ZiYjA2YWE4ZjQ=
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Acfs::Model::Attributes
|
2
|
+
|
3
|
+
# @api public
|
4
|
+
#
|
5
|
+
# UUID attribute type. Use it in your model as an attribute type:
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# class User
|
9
|
+
# include Acfs::Model
|
10
|
+
# attribute :id, :uuid
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
class UUID < Base
|
14
|
+
|
15
|
+
# @api public
|
16
|
+
#
|
17
|
+
# Check if given object looks like a UUID, eg:
|
18
|
+
# `450b7a40-94ad-11e3-baa8-0800200c9a66`
|
19
|
+
# Valid UUIDs are 16 byte numbers represented as
|
20
|
+
# a hexadecimal string in five sub-groups seperated
|
21
|
+
# by a dash. Each group has to consist of a fixed
|
22
|
+
# number of hexadecimal digits:
|
23
|
+
# | Group | Digits |
|
24
|
+
# | -----:|:------ |
|
25
|
+
# | 1 | 8 |
|
26
|
+
# | 2 | 4 |
|
27
|
+
# | 3 | 4 |
|
28
|
+
# | 4 | 4 |
|
29
|
+
# | 5 | 12 |
|
30
|
+
#
|
31
|
+
# @param [Object] obj Object to cast.
|
32
|
+
# @return [String] Casted object as UUID.
|
33
|
+
#
|
34
|
+
def cast_type(obj)
|
35
|
+
obj = obj.to_s
|
36
|
+
return nil if nil_allowed? and obj == ''
|
37
|
+
raise ArgumentError.new "given String `#{obj}` does not look like a UUID" unless obj =~ /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/i
|
38
|
+
obj
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Lower-case alias for automatic type lookup
|
43
|
+
Uuid = UUID
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Acfs::Model::Attributes::UUID do
|
4
|
+
let(:model) { Class.new.tap { |c| c.send :include, Acfs::Model }}
|
5
|
+
let(:params) { {} }
|
6
|
+
let(:instance) { described_class.new params }
|
7
|
+
subject { instance }
|
8
|
+
|
9
|
+
describe '#cast_type' do
|
10
|
+
let(:param) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
|
11
|
+
let(:action) { instance.cast param }
|
12
|
+
subject { action }
|
13
|
+
|
14
|
+
context 'with String as param' do
|
15
|
+
context 'with valid UUID' do
|
16
|
+
let(:param) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
|
17
|
+
it { should be_a String }
|
18
|
+
it { should eq param }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with invalid UUID' do
|
22
|
+
subject { -> { action } }
|
23
|
+
|
24
|
+
context 'with random non-empty string' do
|
25
|
+
let(:param) { 'invalid string' }
|
26
|
+
it { should raise_error ArgumentError }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with string in UUID format but containing invalid characters' do
|
30
|
+
let(:param) { 'xxxxxxxx-yyyy-11e3-baa8-0800200c9a66' }
|
31
|
+
it { should raise_error ArgumentError }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with empty string' do
|
35
|
+
let(:param) { '' }
|
36
|
+
|
37
|
+
context 'with allow_nil option' do
|
38
|
+
let(:params) { {allow_nil: true} }
|
39
|
+
subject { action }
|
40
|
+
it { should eq nil }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'without allow_nil option' do
|
44
|
+
let(:params) { {allow_nil: false} }
|
45
|
+
it { should raise_error ArgumentError }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with non-String as param' do
|
52
|
+
subject { -> { action } }
|
53
|
+
|
54
|
+
invalid_params = { fixnum: 1, float: 3.2, symbol: :invalid, boolean: true }
|
55
|
+
invalid_params.each do |klass, incorrect_param|
|
56
|
+
context "with #{klass.to_s} as param" do
|
57
|
+
let(:param) { incorrect_param }
|
58
|
+
it { should raise_error ArgumentError }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.31.0.1.
|
4
|
+
version: 0.31.0.1.b269
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/acfs/model/attributes/integer.rb
|
144
144
|
- lib/acfs/model/attributes/list.rb
|
145
145
|
- lib/acfs/model/attributes/string.rb
|
146
|
+
- lib/acfs/model/attributes/uuid.rb
|
146
147
|
- lib/acfs/model/dirty.rb
|
147
148
|
- lib/acfs/model/initialization.rb
|
148
149
|
- lib/acfs/model/loadable.rb
|
@@ -176,6 +177,7 @@ files:
|
|
176
177
|
- spec/acfs/model/attributes/date_time_spec.rb
|
177
178
|
- spec/acfs/model/attributes/float_spec.rb
|
178
179
|
- spec/acfs/model/attributes/list_spec.rb
|
180
|
+
- spec/acfs/model/attributes/uuid_spec.rb
|
179
181
|
- spec/acfs/model/attributes_spec.rb
|
180
182
|
- spec/acfs/model/dirty_spec.rb
|
181
183
|
- spec/acfs/model/initialization_spec.rb
|
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
218
|
version: 1.3.1
|
217
219
|
requirements: []
|
218
220
|
rubyforge_project:
|
219
|
-
rubygems_version: 2.2.
|
221
|
+
rubygems_version: 2.2.2
|
220
222
|
signing_key:
|
221
223
|
specification_version: 4
|
222
224
|
summary: An abstract API base client for service oriented application.
|
@@ -228,6 +230,7 @@ test_files:
|
|
228
230
|
- spec/acfs/model/attributes/date_time_spec.rb
|
229
231
|
- spec/acfs/model/attributes/float_spec.rb
|
230
232
|
- spec/acfs/model/attributes/list_spec.rb
|
233
|
+
- spec/acfs/model/attributes/uuid_spec.rb
|
231
234
|
- spec/acfs/model/attributes_spec.rb
|
232
235
|
- spec/acfs/model/dirty_spec.rb
|
233
236
|
- spec/acfs/model/initialization_spec.rb
|