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, #area, #at, #chain, #chest, #cleanup, #dispenser, #dropper, #fill, #furnace, #helper, #initial, #repeat, #setblock, to_json, to_nbt, #trapped_chest

Instance Attribute Details

#last_areaObject

Returns the value of attribute last_area.



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

def last_area
  @last_area
end

#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



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

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

.run_file(file, dir = nil) ⇒ Object



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

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

#blocksObject



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

def blocks
  @blocks ||= {}
end

#chainsObject



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

def chains
  @chains ||= []
end

#contextObject



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

def context
  self
end

#helpersObject



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

def helpers
  @helpers ||= []
end

#named_chainsObject



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

def named_chains
  @named_chains ||= {}
end

#rectsObject



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

def rects
  @rects ||= {}
end

#require(file) ⇒ Object



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

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



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

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



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

def required_files
  @required_files ||= Set.new
end