<commit_before>module Lanes
    module API

        module RequestWrapper
            class << self

                def get(*args)
                    make_handler(*args) do |controller|
                        controller.perform_retrieval
                    end
                end

                def post(*args)
                    make_handler(*args) do |controller|
                        controller.perform_creation
                    end
                end

                def update(*args)
                    make_handler(*args) do |controller|
                        controller.perform_update
                    end
                end

                def delete(*args)
                    make_handler(*args) do |controller|
                        controller.perform_destroy
                    end
                end

                def make_handler(model, controller, parent_attribute)
                    lambda do
                        authentication = Lanes::API::AuthenticationProvider.new(request)
                        authentication.wrap_reply(model, self) do
                            if parent_attribute
                              params[:nested_attribute] = Hash[ parent_attribute,
                                                               params[parent_attribute] ]
                            end
                            wrap_reply(!request.get?) do
                                yield controller.new(model, authentication, params, data)
                            end
                        end
                    end
                end
            end

            def log_request
                Lanes.logger.info "UserID: #{session['user_id']}, Params: #{request.params}"
                Lanes.logger.debug JSON.pretty_generate(data) unless Lanes.env.production? or data.nil?
            end

            def wrap_reply(with_transaction=true)<commit_msg>wrapper method for ensureing logged in user<commit_after>module Lanes
    module API

        module RequestWrapper
            class << self

                def get(*args)
                    make_handler(*args) do |controller|
                        controller.perform_retrieval
                    end
                end

                def post(*args)
                    make_handler(*args) do |controller|
                        controller.perform_creation
                    end
                end

                def update(*args)
                    make_handler(*args) do |controller|
                        controller.perform_update
                    end
                end

                def delete(*args)
                    make_handler(*args) do |controller|
                        controller.perform_destroy
                    end
                end

                def make_handler(model, controller, parent_attribute)
                    lambda do
                        authentication = Lanes::API::AuthenticationProvider.new(request)
                        authentication.wrap_model_access(model, self) do
                            if parent_attribute
                              params[:nested_attribute] = Hash[ parent_attribute,
                                                               params[parent_attribute] ]
                            end
                            wrap_reply(!request.get?) do
                                yield controller.new(model, authentication, params, data)
                            end
                        end
                    end
                end

                def with_authenticated_user
                    lambda do
                        authentication = Lanes::API::AuthenticationProvider.new(request)
                        if authentication.current_user
                            yield authentication.current_user, self
                        else
                            authentication.fail_request
                        end
                    end
                end
            end

            def log_request
                Lanes.logger.info "UserID: #{session['user_id']}, Params: #{request.params}"
                Lanes.logger.debug JSON.pretty_generate(data) unless Lanes.env.production? or data.nil?
            end

            def wrap_reply(with_transaction=true)
{'fraction_non_alphanumeric': 0.05276556352696135, 'fraction_numerical': 0.0, 'mean_word_length': 0.9477242000901307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4206222', 'n_tokens_mistral': 890, 'n_tokens_neox': 804, 'n_words': 193}