Sha256: 7498bd7f3d218dbdfa97c5d26a4b4b7a7a4891a58f8b951714a02d3ad14d057d

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'miu/version'

module Miu
  autoload :CLI, 'miu/cli'
  autoload :Command, 'miu/command'
  autoload :Server, 'miu/server'
  autoload :Message, 'miu/message'
  autoload :Socket, 'miu/socket'
  autoload :Publisher, 'miu/publisher'
  autoload :Subscriber, 'miu/subscriber'

  class << self
    def root
      @root ||= find_root 'Gemfile'
    end

    def default_port
      22200
    end

    def default_god_port
      default_port
    end

    def default_pub_port
      default_port + 1
    end

    def default_sub_port
      default_port + 2
    end

    def default_god_config
      'config/miu.god'
    end

    def find_root(flag, base = nil)
      require 'pathname'
      path = base || Dir.pwd
      while path && File.directory?(path) && !File.exist?("#{path}/#{flag}")
        parent = File.dirname path
        path = path != parent && parent
      end
      raise 'Could not find root path' unless path
      Pathname.new File.realpath(path)
    end

    def plugins
      @plugins ||= {}
    end

    def register(name, plugin, options = {}, &block)
      Miu.plugins[name] = plugin
      if block
        usage = options[:usage] || "#{name} [COMMAND]"
        desc = options[:desc] || plugin.to_s
        command = Miu::Command.new name, plugin, &block
        Miu::CLI.register command, name, usage, desc
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
miu-0.0.6 lib/miu.rb
miu-0.0.5 lib/miu.rb