-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When initializing a query we need to allow for keys and values to be strings because blacklight automatically turns symbols in params into strings.
- Loading branch information
Showing
8 changed files
with
114 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "primo" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primo | ||
module ParameterValidatable | ||
|
||
# A mixin class designed to allow Validations of params | ||
# To use, include it in your class and then define an array of validators | ||
# that are hashes with a :query and :message keys. | ||
# :query is a method you will pass the params to to run a single validations | ||
# :message is a lmbda that retunrs a string telling the user what went wrong | ||
# - the params will be passed to the message so you can | ||
# reference the params in your error message | ||
# | ||
# EXAMPLE Usage ##################### | ||
# include Primo::ParameterValidatable | ||
# | ||
# def validators | ||
# [{ query: is_my_param_valid?, | ||
# message: lambda { |params| "Param :q needs to be an integer, but you passed a #{params[:q].class}" } | ||
# }] | ||
# def is_my_param_valid?(params) | ||
# params[:count].is_a? Integer | ||
# | ||
#######################################33 | ||
# A mixin class designed to allow Validations of params | ||
# To use, include it in your class and then define an array of validators | ||
# that are hashes with a :query and :message keys. | ||
# :query is a method you will pass the params to to run a single validations | ||
# :message is a lmbda that retunrs a string telling the user what went wrong | ||
# - the params will be passed to the message so you can | ||
# reference the params in your error message | ||
# | ||
# EXAMPLE Usage ##################### | ||
# include Primo::ParameterValidatable | ||
# | ||
# def validators | ||
# [{ query: is_my_param_valid?, | ||
# message: lambda { |params| "Param :q needs to be an integer, but you passed a #{params[:q].class}" } | ||
# }] | ||
# def is_my_param_valid?(params) | ||
# params[:count].is_a? Integer | ||
# | ||
#######################################33 | ||
|
||
|
||
|
||
def validate(params) | ||
validators.each do |validate| | ||
message = validate[:message][params] | ||
if !send(validate[:query], params) | ||
raise error.new(message) | ||
end | ||
end | ||
end | ||
def validate(params) | ||
validators.each do |validate| | ||
message = validate[:message][params] | ||
if !send(validate[:query], params) | ||
raise error.new(message) | ||
end | ||
end | ||
end | ||
|
||
# Use a local error class if the Class has a local error class | ||
# following the convention Primo::ClassName::ClassNameError | ||
# Otherwise use Primo::Pnxs::PnxsError | ||
def error | ||
error_class = Primo::Pnxs::PnxsError | ||
class_name = self.class.to_s.split("::").last | ||
class_error_name = class_name + "Error" | ||
if self.class.const_defined?(class_error_name) | ||
error_class = self.class.const_get(class_error_name) | ||
end | ||
error_class | ||
end | ||
# Use a local error class if the Class has a local error class | ||
# following the convention Primo::ClassName::ClassNameError | ||
# Otherwise use Primo::Pnxs::PnxsError | ||
def error | ||
error_class = Primo::Pnxs::PnxsError | ||
class_name = self.class.to_s.split("::").last | ||
class_error_name = class_name + "Error" | ||
if self.class.const_defined?(class_error_name) | ||
error_class = self.class.const_get(class_error_name) | ||
end | ||
error_class | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters