module MSFL::Sinatra
Attributes
Public Class Methods
Extracts the dataset name from the Sinatra
params. It then returns a new instance of the specified dataset.
@param params [Hash] the Sinatra
request params @return [MSFL::Datasets::Base, Nil] a new instance of the specified dataset, if it can be found, otherwise nil
# File lib/msfl/sinatra.rb, line 27 def dataset_from(params) dataset_name = params[:dataset].to_sym unless params[:dataset].nil? dataset_name ||= nil Datasets::Base.dataset_from dataset_name end
Extracts the filter clause from a Sinatra
request params hash and parsers the filter
@param params [Hash] the Sinatra
request params @return [Object] the Ruby-ified MSFL
filter
# File lib/msfl/sinatra.rb, line 16 def parse_filter_from(params) filter = params[:filter] || params["filter"] filter = filter.to_json if filter.is_a?(Hash) #normally it's a string MSFL::Parsers::JSON.parse filter end
Sinatra
specific registration hook
# File lib/msfl/sinatra.rb, line 88 def self.registered(app) app.helpers Helpers if app.respond_to?(:helpers) end
Validate the MSFL
filter in the Sinatra
request’s params hash
@param params [Hash] the Sinatra
request params @return [Bool]
# File lib/msfl/sinatra.rb, line 45 def validate(params) validator = validator_from params parsed_filter = parse_filter_from params result = validator.validate parsed_filter @valid_filter = parsed_filter if result result end
Creates a semantic validator instance that is ready to validate the dataset
@param params [Hash] the Sinatra
request params @return [MSFL::Validators::Semantic] a validator instance ready to validate filters for the dataset
# File lib/msfl/sinatra.rb, line 37 def validator_from(params) MSFL::Validators::Semantic.new dataset_from(params) end