Module: Filterable

Extended by:
ActiveSupport::Concern
Included in:
V0::MessagesController, V0::PrescriptionsController
Defined in:
app/controllers/concerns/filterable.rb

Instance Method Summary collapse

Instance Method Details

#filter_paramsObject (private)



31
32
33
# File 'app/controllers/concerns/filterable.rb', line 31

def filter_params
  params.require(:filter).permit(Prescription.filterable_attributes.merge(Message.filterable_attributes))
end

#filter_queryObject (private)



20
21
22
23
24
25
# File 'app/controllers/concerns/filterable.rb', line 20

def filter_query
  @filter_query ||= begin
    q = URI.parse(request.url).query || ''
    q.split('&').select { |a| a.include?('filter') }
  end
end

#valid_filters?Boolean (private)

Returns:

  • (Boolean)


27
28
29
# File 'app/controllers/concerns/filterable.rb', line 27

def valid_filters?
  filter_query.map { |a| a.gsub('filter', '') }.all? { |s| s =~ /\A\[\[.+\]\[.+\]\]=.+\z/ }
end

#validate_filter_params!Object



10
11
12
13
14
15
16
# File 'app/controllers/concerns/filterable.rb', line 10

def validate_filter_params!
  if params[:filter].present?
    return true if valid_filters?

    raise Common::Exceptions::InvalidFiltersSyntax, filter_query
  end
end