Module: Faalis::Generators::Concerns::AllowQueryOn

Included in:
DashboardScaffold
Defined in:
lib/faalis/generators/concerns/allow_query_on.rb

Overview

This module adds allow_query_on key to json file which is an array of field name which you want to whitelist for query.

Instance Method Summary (collapse)

Instance Method Details

- (Object) allowed_fields (private)



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/faalis/generators/concerns/allow_query_on.rb', line 10

def allowed_fields
  if allowed_fields_provided?
    unless resource_data['allow_query_on'].is_a? Array
      fail Exception.new 'value of `allow_query_on` key should be an Array. '
    end
    # :#{something} is a trick to convert the field name to sym on
    # controller
    fields = resource_data['allow_query_on'].collect { |f| ":#{f}" }
    fields.join(' ,')
  else
    []
  end
end

- (Boolean) allowed_fields_provided? (private)

Check for any allowed fields in json

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/faalis/generators/concerns/allow_query_on.rb', line 25

def allowed_fields_provided?
  if resource_data.include? 'allow_query_on'
    return true unless resource_data['allow_query_on'].nil?
  end
  false
end