Sha256: e9ee86b269f57a868529040404b43e84a0c0ff533f83d937fc869c5ed7e394c3

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'pleiades/core/constants'
require 'pleiades/core/config'
require 'pleiades/core/command/nest_blocks'
require 'pleiades/core/command/event_proccessor'

module Pleiades
  module Command
    class Router
      prepend Pleiades::Command::NestBlocks
      prepend Pleiades::Command::EventProccessor

      class << self
        attr_accessor :path
        attr_reader :event

        def find_route(event)
          @event = event
          @path = nil

          load Pleiades::Constants::File::ROUTER

          Router.path_found? ? Router.path : 'base_command'
        end

        def route(&block)
          new.instance_eval(&block) if block_given?
        end

        def path_found?
          @path ? true : false
        end
      end

      def initialize(options = nil)
        @event = Router.event
        @options = options || default_options
      end

      private

      def normalize_path(scope = nil, action = nil)
        dirs = []

        dirs << @options[:scope] if @options[:scope].any?
        dirs << scope if scope
        dirs << (action || @options[:action])

        dirs.join('/')
      end

      def talk_type(*callable_types, &block)
        instance_eval(&block) if callable_type?(callable_types)
      end

      def callable_type?(types)
        types.map(&:to_s).include?(@event.source.type)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pleiades-0.1.1 lib/pleiades/core/command/router.rb