Module: MSFL::Sinatra
- Defined in:
- lib/msfl/sinatra.rb
Defined Under Namespace
Modules: Helpers
Class Attribute Summary collapse
-
.valid_filter ⇒ Object
Returns the value of attribute valid_filter.
Class Method Summary collapse
-
.dataset_from(params) ⇒ MSFL::Datasets::Base, Nil
Extracts the dataset name from the Sinatra params.
-
.parse_filter_from(params) ⇒ Object
Extracts the filter clause from a Sinatra request params hash and parsers the filter.
-
.registered(app) ⇒ Object
Sinatra specific registration hook.
-
.validate(params) ⇒ Bool
Validate the MSFL filter in the Sinatra request’s params hash.
-
.validator_from(params) ⇒ MSFL::Validators::Semantic
Creates a semantic validator instance that is ready to validate the dataset.
Class Attribute Details
.valid_filter ⇒ Object
Returns the value of attribute valid_filter.
6 7 8 |
# File 'lib/msfl/sinatra.rb', line 6 def valid_filter @valid_filter end |
Class Method Details
.dataset_from(params) ⇒ MSFL::Datasets::Base, Nil
Extracts the dataset name from the Sinatra params. It then returns a new instance of the specified dataset.
27 28 29 30 31 |
# 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) ⇒ Object
Extracts the filter clause from a Sinatra request params hash and parsers the filter
16 17 18 19 20 |
# 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) ⇒ Object
Sinatra specific registration hook
88 89 90 |
# File 'lib/msfl/sinatra.rb', line 88 def self.registered(app) app.helpers Helpers if app.respond_to?(:helpers) end |
.validate(params) ⇒ Bool
Validate the MSFL filter in the Sinatra request’s params hash
45 46 47 48 49 50 51 |
# 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) ⇒ MSFL::Validators::Semantic
Creates a semantic validator instance that is ready to validate the dataset
37 38 39 |
# File 'lib/msfl/sinatra.rb', line 37 def validator_from(params) MSFL::Validators::Semantic.new dataset_from(params) end |