Module: MSFL::Sinatra::Helpers

Defined in:
lib/msfl/sinatra.rb

Instance Method Summary collapse

Instance Method Details

#msfl_filter(params = nil) ⇒ Object

This method returns the valid MSFL filter. If the valid filter has already been extracted from the parameters it is returned, otherwise if the optional params argument is specified it will be sent to MSFL::Sinatra.validate and if the validation is successful the valid filter is returned. If the valid filter still cannot be determined then the method raises an ArgumentError.

Parameters:

  • params (Hash) (defaults to: nil)

    optionally pass in the Sinatra request parameters - this is intended to be used when no previously successful call to msfl_valid? has been made, so that when you just need the filter you can skip writing msfl_valid?(params) in your code.

Returns:

  • (Object)

    the Ruby-ified and validated MSFL filter

Raises:

  • (ArgumentError)


76
77
78
79
80
81
82
83
84
# File 'lib/msfl/sinatra.rb', line 76

def msfl_filter(params = nil)
  filter = Sinatra.valid_filter
  if filter.nil?
    Sinatra.validate params
    filter = Sinatra.valid_filter
  end
  raise ArgumentError, "A valid filter could not be located in msfl_filter." if filter.nil?
  filter
end

#msfl_valid?(params) ⇒ Bool

This method extracts the dataset name and filter from the Sinatra params. It also performs semantic validation of the filter relative to the dataset.

The method also has the side effect, when the filter is valid or setting the valid_filter singleton class instance variable valid_filter to the Ruby-ified parsed filter.

Parameters:

  • params (Hash)

    this should be the params variable from the request context

Returns:

  • (Bool)

    returns true if the filter is valid, false otherwise.



63
64
65
# File 'lib/msfl/sinatra.rb', line 63

def msfl_valid?(params)
  Sinatra.validate params
end