From 0f134a87285c112e2f6160a0ab7bec33e848f4b8 Mon Sep 17 00:00:00 2001 From: Spencer Alan Date: Wed, 5 Dec 2018 15:10:53 -0500 Subject: [PATCH] • add model to handle sql counts --- app/models/scim_rails/scim_count.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+), 0 deletions(-) create mode 100644 app/models/scim_rails/scim_count.rb diff --git a/app/models/scim_rails/scim_count.rb b/app/models/scim_rails/scim_count.rb new file mode 100644 index 0000000..f8c9175 --- /dev/null +++ b/app/models/scim_rails/scim_count.rb @@ -0,0 +1,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 -- libgit2 0.21.0