Class: JsonApiFilter::FilterAttributes
- Inherits:
-
Object
- Object
- JsonApiFilter::FilterAttributes
- Defined in:
- lib/json_api_filter/filter_attributes.rb
Instance Attribute Summary collapse
-
#allowed_filters ⇒ Object
readonly
Returns the value of attribute allowed_filters.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(allowed_filters, params) ⇒ FilterAttributes
constructor
A new instance of FilterAttributes.
-
#nested_allowed_filter ⇒ Array<Symbol>
Keys of nested allowed filters only one level of nesting supported.
- #process ⇒ ActiveSupport::HashWithIndifferentAccess, Hash
Constructor Details
#initialize(allowed_filters, params) ⇒ FilterAttributes
Returns a new instance of FilterAttributes.
8 9 10 11 |
# File 'lib/json_api_filter/filter_attributes.rb', line 8 def initialize(allowed_filters, params) @allowed_filters = allowed_filters @params = params end |
Instance Attribute Details
#allowed_filters ⇒ Object (readonly)
Returns the value of attribute allowed_filters.
3 4 5 |
# File 'lib/json_api_filter/filter_attributes.rb', line 3 def allowed_filters @allowed_filters end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/json_api_filter/filter_attributes.rb', line 3 def params @params end |
Instance Method Details
#nested_allowed_filter ⇒ Array<Symbol>
Keys of nested allowed filters only one level of nesting supported
31 32 33 |
# File 'lib/json_api_filter/filter_attributes.rb', line 31 def nested_allowed_filter allowed_filters.select{|f| f.class == Hash}.map(&:keys).flatten end |
#process ⇒ ActiveSupport::HashWithIndifferentAccess, Hash
14 15 16 17 18 19 20 21 |
# File 'lib/json_api_filter/filter_attributes.rb', line 14 def process params.select do |k,v| allowed_filters.include?(k.to_sym) || allowed_filters.include?(k.to_s) || nested_allowed_filter.include?(k.to_sym) || nested_allowed_filter.include?(k.to_s) end end |