Commit 0f134a87285c112e2f6160a0ab7bec33e848f4b8

Authored by Spencer Alan
1 parent 1b737064
Exists in master

• add model to handle sql counts

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