module MSFL::Sinatra

Attributes

valid_filter[RW]

Public Class Methods

dataset_from(params) click to toggle source

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
parse_filter_from(params) click to toggle source

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
registered(app) click to toggle source

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(params) click to toggle source

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
validator_from(params) click to toggle source

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