Sha256: de584608b029005275a132d852796b386da094ddbaabd5619eace4c8fe843a63

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

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={})
      authorize! permission, params
      self.class.facade.call name, container, context, params
    end

    def enqueue(name, permission, params={})
      authorize! permission, params
      self.class.facade.enqueue name, context, params
    end

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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rasti-app-0.0.7 lib/rasti/app.rb
rasti-app-0.0.6 lib/rasti/app.rb
rasti-app-0.0.5 lib/rasti/app.rb