Skip to content

Commit

Permalink
Refs #36892 - improve regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Nov 20, 2023
1 parent c679c47 commit 5d4f94f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/controllers/api/v2/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class BaseController < Api::BaseController
layout 'api/v2/layouts/index_layout', :only => :index

helper_method :root_node_name, :metadata_total, :metadata_subtotal, :metadata_search,
:metadata_order, :metadata_by, :metadata_page, :metadata_per_page, :index_node_permissions
:metadata_order, :metadata_by, :metadata_page, :metadata_per_page, :index_node_permissions,
:to_json_line
def root_node_name
@root_node_name ||= if Rabl.configuration.use_controller_name_as_json_root
controller_name.split('/').last
Expand All @@ -65,6 +66,12 @@ def index_node_permissions
}
end

def to_json_line(object)
# Remove the characters '{' from the beginning and '}' from the end of the string
# The {1}'s are to only remove one character from each end.
object.to_json.gsub(/\A{{1}|}{1}\z/,'')
end

def metadata_total
@total ||= resource_scope.try(:size).to_i
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v2/layouts/index_layout.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"per_page": <%= metadata_per_page.to_json %>,
"search": <%= metadata_search.to_json.html_safe %>,
<% if params.has_key?(:include_permissions) %>
<%= index_node_permissions.to_json.gsub(/[{}]/,'').html_safe %>,
<%= to_json_line(index_node_permissions).html_safe %>,
<% end %>
"sort": {
"by": <%= metadata_by.to_json.html_safe %>,
Expand Down

0 comments on commit 5d4f94f

Please sign in to comment.