Class: McBlocky::Context

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/mcblocky/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

#after, #at, #chest, #cleanup, #dispenser, #dropper, #fill, #furnace, #helper, #initial, #repeat, #setblock, to_json, to_nbt, #trapped_chest

Instance Attribute Details

#serverObject

Returns the value of attribute server.



5
6
7
# File 'lib/mcblocky/context.rb', line 5

def server
  @server
end

Class Method Details

.run_block(&block) ⇒ Object



21
22
23
24
25
# File 'lib/mcblocky/context.rb', line 21

def self.run_block(&block)
  ctx = Context.new
  ctx.instance_exec &block
  return ctx
end

.run_file(file, dir = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mcblocky/context.rb', line 7

def self.run_file(file, dir=nil)
  dir = File.dirname(file) unless dir
  Dir.chdir dir do
    begin
      ctx = Context.new
      f = open(file)
      ctx.instance_eval(f.read, file)
      return ctx
    ensure
      f.close if f
    end
  end
end

Instance Method Details

#areasObject



47
48
49
# File 'lib/mcblocky/context.rb', line 47

def areas
  @areas ||= []
end

#blocksObject



39
40
41
# File 'lib/mcblocky/context.rb', line 39

def blocks
  @blocks ||= {}
end

#chainsObject



35
36
37
# File 'lib/mcblocky/context.rb', line 35

def chains
  @chains ||= []
end

#contextObject



51
52
53
# File 'lib/mcblocky/context.rb', line 51

def context
  self
end

#helpersObject



27
28
29
# File 'lib/mcblocky/context.rb', line 27

def helpers
  @helpers ||= []
end

#rectsObject



43
44
45
# File 'lib/mcblocky/context.rb', line 43

def rects
  @rects ||= {}
end

#require(file) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mcblocky/context.rb', line 55

def require(file)
  if file.start_with? './'
    file = "#{file.sub('./','')}.rb" unless file.end_with? '.rb'
    required_files << file
    begin
      f = open(file)
      instance_eval(f.read, file)
      true
    ensure
      f.close if f
    end
  else
    Kernel.require(file)
  end
end

#require_relative(file) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/mcblocky/context.rb', line 71

def require_relative(file)
  path = File.dirname caller[0].split('.rb')[0]
  file = "#{file}.rb" unless file.end_with? '.rb'
  file = File.expand_path(file, path)
  required_files << file
  begin
    f = open(file)
    instance_eval(f.read, file)
    true
  ensure
    f.close if f
  end
end

#required_filesObject



31
32
33
# File 'lib/mcblocky/context.rb', line 31

def required_files
  @required_files ||= Set.new
end