scim_count.rb
645 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module ScimRails
class ScimCount
include ActiveModel::Model
attr_accessor \
:limit,
:offset,
:start_index,
:total
def limit
return 100 if @limit.blank?
validate_numericality(@limit)
input = @limit.to_i
raise if input < 1
input
end
def start_index
return 1 if @start_index.blank?
validate_numericality(@start_index)
input = @start_index.to_i
return 1 if input < 1
input
end
def offset
start_index - 1
end
private
def validate_numericality(input)
raise unless input.match?(/\A\d+\z/)
end
end
end