Class: Card::Mod::Loader::SetLoader::Template

Inherits:
ModuleTemplate show all
Defined in:
lib/card/mod/loader/set_loader.rb

Instance Method Summary collapse

Methods inherited from ModuleTemplate

#build, #simple_load?, #to_s

Constructor Details

#initialize(modules, content_path) ⇒ Template

Returns a new instance of Template.



28
29
30
31
# File 'lib/card/mod/loader/set_loader.rb', line 28

def initialize modules, content_path
  super
  @modules.pop if helper_module?
end

Instance Method Details

#helper_module?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/card/mod/loader/set_loader.rb', line 45

def helper_module?
  if @is_helper_module.nil?
    @is_helper_module = @content =~ /\A#!\s?not? set module/
  else
    @is_helper_module
  end
end

#offsetObject

correct line number for error messages



54
55
56
57
58
59
# File 'lib/card/mod/loader/set_loader.rb', line 54

def offset
  # One line for the module chain and one line for the source_location method
  # The template changes so rarely that doesn't seem worth it to count
  # it during runtime
  helper_module? ? -4 : -5
end

#to_constObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/card/mod/loader/set_loader.rb', line 33

def to_const
  return Object if simple_load?

  pattern_klass = Card::Set.const_get_or_set(@pattern.camelize) { Class.new }

  @modules.inject(pattern_klass) do |const, name_part|
    const.const_get_or_set name_part do
      Module.new
    end
  end
end