<commit_before>require 'yaml'
require 'erb'
require 'inflecto'
require 'asynchronic'
require 'hash_ext'
require 'consty'
require 'multi_require'
require 'rasti-form'

module Rasti
  class App

    extend MultiRequire

    require_relative 'app/interaction'
    require_relative_pattern 'app/*'

    class << self

      extend Forwardable

      def_delegators :facade, :interactions,
                              :synchronic_interactions,
                              :asynchronic_interactions,
                              :permissions, 
                              :valid_permission?

      attr_reader :facade

      private

      def expose(namespace)
        @facade = Facade.new namespace

        facade.interactions.each do |name, specification|
          if specification.synchronic?
            define_method name do |params={}|
              call name, specification.permission, params
            end
          end

          define_method "enqueue_#{name}" do |params={}|
            enqueue name, specification.permission, params
          end
        end
      end

    end

    def initialize(container, context={})
      @container = container
      @context = context
    end

    private

    attr_reader :container, :context

    def policy
      @policy ||= (container[:policy_class] || Policy).new container, context
    end

    def call(name, permission, params={})
      form = self.class.facade.build_form name, params
      authorize! permission, form
      self.class.facade.call name, container, context, form
    end

    def enqueue(name, permission, params={})
      queue = params.delete(:queue)
      
      form = self.class.facade.build_form name, params
      authorize! permission, form
      self.class.facade.enqueue name, context, form, queue
    end

    def authorize!(permission, form)
      policy.authorize! permission, form
    end

  end
end<commit_msg>Add hook after interactions called<commit_after>require 'yaml'
require 'erb'
require 'inflecto'
require 'asynchronic'
require 'hash_ext'
require 'consty'
require 'multi_require'
require 'rasti-form'

module Rasti
  class App

    extend MultiRequire

    require_relative 'app/interaction'
    require_relative_pattern 'app/*'

    class << self

      extend Forwardable

      def_delegators :facade, :interactions,
                              :synchronic_interactions,
                              :asynchronic_interactions,
                              :permissions, 
                              :valid_permission?

      attr_reader :facade

      private

      def expose(namespace)
        @facade = Facade.new namespace

        facade.interactions.each do |name, specification|
          if specification.synchronic?
            define_method name do |params={}|
              call name, specification.permission, params
            end
          end

          define_method "enqueue_#{name}" do |params={}|
            enqueue name, specification.permission, params
          end
        end
      end

    end

    def initialize(container, context={})
      @container = container
      @context = context
    end

    private

    attr_reader :container, :context

    def policy
      @policy ||= (container[:policy_class] || Policy).new container, context
    end

    def call(name, permission, params={})
      form = self.class.facade.build_form name, params
      authorize! permission, form
      self.class.facade.call name, container, context, form
      
      after_call name, form.attributes
    end

    def enqueue(name, permission, params={})
      queue = params.delete(:queue)
      
      form = self.class.facade.build_form name, params
      authorize! permission, form
      self.class.facade.enqueue name, context, form, queue

      after_call name, form.attributes
    end

    def authorize!(permission, form)
      policy.authorize! permission, form
    end

    def after_call(name, params)
    end

  end
end
{'fraction_non_alphanumeric': 0.07894073139974779, 'fraction_numerical': 0.0, 'mean_word_length': 2.1526232114467407, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4464309', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1042, 'n_words': 289}