Class: Card::Mod::ModuleTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/card/mod/module_template.rb

Overview

ModuleTemplate is an abstract class to build ruby modules out of deckos dsl for sets and set patterns. SetLoader::Template and SetPatternLoader::Template inherit from it and adapt the template to their needs.

Instance Method Summary collapse

Constructor Details

#initialize(modules, content_path, strategy) ⇒ ModuleTemplate

Returns a new instance of ModuleTemplate.



8
9
10
11
12
13
14
15
# File 'lib/card/mod/module_template.rb', line 8

def initialize modules, content_path, strategy
  modules = Array.wrap modules
  @pattern = modules.shift
  @modules = modules
  @content = ::File.read content_path
  @content_path = content_path
  @strategy = strategy
end

Instance Method Details

#buildObject

Evaluates the module in the top level namespace.



18
19
20
# File 'lib/card/mod/module_template.rb', line 18

def build
  eval to_s, TOPLEVEL_BINDING, @content_path, offset
end

#processed_contentObject



31
32
33
34
# File 'lib/card/mod/module_template.rb', line 31

def processed_content
  capture_module_comment if @strategy.clean_comments?
  module_content
end

#simple_load?Boolean

Just run the code of the source. Don't use the path to the file as module hierarchy.

Returns:

  • (Boolean)


38
39
40
# File 'lib/card/mod/module_template.rb', line 38

def simple_load?
  @content =~ /\A#!\s?simple load/
end

#to_sString

Returns the ruby code to build the modal.

Returns:

  • (String)

    the ruby code to build the modal



23
24
25
26
27
28
29
# File 'lib/card/mod/module_template.rb', line 23

def to_s
  if simple_load?
    @content
  else
    processed_content
  end
end