Class: LinkedRails::ParamsParser
- Inherits:
-
Object
- Object
- LinkedRails::ParamsParser
- Defined in:
- lib/linked_rails/params_parser.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#user_context ⇒ Object
readonly
Returns the value of attribute user_context.
Instance Method Summary collapse
- #before_params ⇒ Object
- #collection_params ⇒ Object
- #collection_view_params ⇒ Object
-
#filter_params ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(params) ⇒ ParamsParser
constructor
A new instance of ParamsParser.
- #sorting_params ⇒ Object
Constructor Details
#initialize(params) ⇒ ParamsParser
Returns a new instance of ParamsParser.
7 8 9 10 |
# File 'lib/linked_rails/params_parser.rb', line 7 def initialize(params) @user_context = params[:user_context] @params = params.is_a?(Hash) ? ActionController::Parameters.new(params) : params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/linked_rails/params_parser.rb', line 5 def params @params end |
#user_context ⇒ Object (readonly)
Returns the value of attribute user_context.
5 6 7 |
# File 'lib/linked_rails/params_parser.rb', line 5 def user_context @user_context end |
Instance Method Details
#before_params ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/linked_rails/params_parser.rb', line 12 def before_params return @before_params if instance_variable_defined?(:@before_params) values = permit_params(before: [])[:before] return @before_params = nil if values.blank? @before_params = values.map do |f| key, value = f.split('=') {key: RDF::URI(CGI.unescape(key)), value: value} end end |
#collection_params ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/linked_rails/params_parser.rb', line 24 def collection_params return @collection_params if instance_variable_defined?(:@collection_params) values = permit_params(:display, :page_size, :title, :type) filter = filter_params values[:filter] = filter if filter sort = sorting_params values[:sort] = sort if sort values[:user_context] = user_context if user_context @collection_params = values end |
#collection_view_params ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/linked_rails/params_parser.rb', line 40 def collection_view_params return @collection_view_params if instance_variable_defined?(:@collection_view_params) values = permit_params(:page) before = before_params values[:before] = before if before @collection_view_params = values end |
#filter_params ⇒ Object
rubocop:disable Metrics/AbcSize
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/linked_rails/params_parser.rb', line 51 def filter_params # rubocop:disable Metrics/AbcSize return @filter_params if instance_variable_defined?(:@filter_params) values = permit_params(filter: [])[:filter] || permit_params(filter: {})[:filter] return @filter_params = values if values.is_a?(Hash) return @filter_params = {} if values.blank? @filter_params = values.each_with_object({}) do |f, hash| values = f.split('=') key = RDF::URI(CGI.unescape(values.first)) hash[key] ||= [] hash[key] << CGI.unescape(values.second) end end |
#sorting_params ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/linked_rails/params_parser.rb', line 66 def sorting_params return @sorting_params if instance_variable_defined?(:@sorting_params) values = permit_params(sort: [])[:sort] return @sorting_params = nil if values.blank? @sorting_params = values.map do |f| parse_filter_value(f) end end |