Module: Miu

Defined in:
lib/miu.rb,
lib/miu/cli.rb,
lib/miu/dsl.rb,
lib/miu/node.rb,
lib/miu/nodes.rb,
lib/miu/proxy.rb,
lib/miu/errors.rb,
lib/miu/logger.rb,
lib/miu/packet.rb,
lib/miu/server.rb,
lib/miu/command.rb,
lib/miu/sockets.rb,
lib/miu/utility.rb,
lib/miu/version.rb,
lib/miu/cli_base.rb,
lib/miu/messages.rb,
lib/miu/readable.rb,
lib/miu/writable.rb,
lib/miu/forwarder.rb,
lib/miu/publisher.rb,
lib/miu/resources.rb,
lib/miu/subscriber.rb,
lib/miu/messages/base.rb,
lib/miu/messages/text.rb,
lib/miu/messages/enter.rb,
lib/miu/messages/leave.rb,
lib/miu/resources/base.rb,
lib/miu/resources/room.rb,
lib/miu/resources/user.rb,
lib/miu/messages/unknown.rb,
lib/miu/resources/content.rb,
lib/miu/resources/network.rb,
lib/miu/resources/text_content.rb,
lib/miu/resources/enter_content.rb,
lib/miu/resources/leave_content.rb

Defined Under Namespace

Modules: Logger, Messages, Node, Nodes, Publisher, Readable, ReadableSocket, Resources, Subscriber, Utility, Writable, WritableSocket Classes: CLI, CLIBase, Command, DealerSocket, Error, Forwarder, InvalidTypeError, MessageLoadError, Packet, PacketLoadError, Proxy, PubSocket, PullSocket, PushSocket, RepSocket, ReqSocket, RouterSocket, Server, Socket, SubSocket, WrappedError, XPubSocket, XSubSocket

Constant Summary collapse

VERSION =
'0.2.3'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_loggerObject

Returns the value of attribute default_logger.



33
34
35
# File 'lib/miu/logger.rb', line 33

def default_logger
  @default_logger
end

.loggerObject

Returns the value of attribute logger.



34
35
36
# File 'lib/miu/logger.rb', line 34

def logger
  @logger
end

Class Method Details

.contextObject



56
57
58
59
# File 'lib/miu.rb', line 56

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

.default_god_configObject



52
53
54
# File 'lib/miu.rb', line 52

def default_god_config
  'config/miu.god'
end

.default_god_portObject



48
49
50
# File 'lib/miu.rb', line 48

def default_god_port
  default_port + 3
end

.default_portObject



36
37
38
# File 'lib/miu.rb', line 36

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

.default_pub_portObject



40
41
42
# File 'lib/miu.rb', line 40

def default_pub_port
  default_port + 0
end

.default_sub_portObject



44
45
46
# File 'lib/miu.rb', line 44

def default_sub_port
  default_port + 1
end

.dump_cli_options(options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/miu/dsl.rb', line 8

def dump_cli_options(options)
  options.map do |k, v|
    v = case v
        when Array
          v.map { |x| "'#{x}'" }.join(' ')
        else
          v.to_s
        end
    "#{k}=#{v}"
  end.join(' ')
end

.find_gemsObject



86
87
88
# File 'lib/miu.rb', line 86

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

.gemsObject



82
83
84
# File 'lib/miu.rb', line 82

def gems
  @gems ||= find_gems
end

.load_nodesObject



65
66
67
68
69
70
# File 'lib/miu.rb', line 65

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

.nodesObject



61
62
63
# File 'lib/miu.rb', line 61

def nodes
  @nodes ||= {}
end

.register(name, node, options = {}, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/miu.rb', line 72

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

.rootObject



31
32
33
34
# File 'lib/miu.rb', line 31

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

.watch(name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/miu/dsl.rb', line 20

def watch(name)
  God.watch do |w|
    w.dir = Miu.root
    w.log = Miu.root.join("log/#{name}.log").to_s
    w.name = name
    w.group = 'all'

    yield w if block_given?

    [:start, :stop, :restart].each do |action|
      value = w.public_send action
      if value.is_a?(Array)
        options = Miu::Utility.extract_options! value
        value << dump_cli_options(options)
        w.public_send "#{action}=", value.join(' ')
      end
    end
  end
end