Sha256: 1570b3914366deef44b7343a9aca413126144e60a40b5a5e226e90c357587a28

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

require 'miu/version'
require 'miu/logger'
require 'miu/errors'

module Miu
  autoload :CLI, 'miu/cli'
  autoload :Utility, 'miu/utility'

  autoload :Socket, 'miu/sockets'
  autoload :PubSocket, 'miu/sockets'
  autoload :SubSocket, 'miu/sockets'
  autoload :XPubSocket, 'miu/sockets'
  autoload :XSubSocket, 'miu/sockets'

  autoload :Server, 'miu/server'
  autoload :Packet, 'miu/packet'
  autoload :Writable, 'miu/writable'
  autoload :Readable, 'miu/readable'
  autoload :Publisher, 'miu/publisher'
  autoload :Subscriber, 'miu/subscriber'
  autoload :Proxy, 'miu/proxy'
  autoload :Forwarder, 'miu/forwarder'

  autoload :Command, 'miu/command'
  autoload :Node, 'miu/node'
  autoload :Nodes, 'miu/nodes'
  autoload :Resources, 'miu/resources'
  autoload :Messages, 'miu/messages'

  class << self
    def root
      require 'pathname'
      Pathname.new(ENV['MIU_ROOT'] || Dir.pwd)
    end

    def default_port
      Integer(ENV['MIU_DEFAULT_PORT']) rescue  22200
    end

    def default_pub_port
      default_port + 0
    end

    def default_sub_port
      default_port + 1
    end

    def default_god_port
      default_port + 3
    end

    def default_god_config
      'config/miu.god'
    end

    def context
      require 'ffi-rzmq'
      @context ||= ZMQ::Context.new
    end

    def nodes
      @nodes ||= {}
    end

    def load_nodes
      gems.each do |spec|
        @current_spec = spec
        require spec.name
      end
    end

    def register(name, node, options = {}, &block)
      node.spec = @current_spec
      Miu.nodes[name] = node
      usage = options[:usage] || "#{name} [COMMAND]"
      desc = node.description
      command = Miu::Command.new name, node, &block
      Miu::CLI.register command, name, usage, desc
      command
    end

    def gems
      @gems ||= find_gems
    end

    def find_gems
      Gem::Specification.find_all.select { |spec| spec.name =~ /^miu-/ }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
miu-0.2.3 lib/miu.rb
miu-0.2.2 lib/miu.rb
miu-0.2.1 lib/miu.rb