Module: Alchemist::ServerHandler

Defined in:
lib/alchemist-server/server_handler.rb

Defined Under Namespace

Modules: Methods

Class Method Summary collapse

Class Method Details

.new(world_file) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/alchemist-server/server_handler.rb', line 3

def self.new(world_file)
  puts "Loading history...."
  history = Alchemist::Server.load_history world_file

  Module.new do
    include Methods

    @world_file = world_file
    @history = history
    @connections = []

    class <<self
      attr_reader :world_file
      attr_accessor :history
      attr_accessor :connections
    end

    def self.included(mod)
      mod.instance_variable_set :@state, self
      def mod.state; @state; end
    end

    def world_file
      self.class.state.world_file
    end

    def history
      self.class.state.history
    end

    def history=(h)
      self.class.state.history = h
    end

    def connections
      self.class.state.connections
    end
  end
end