Class: Card::Mod::ModuleTemplate
- Inherits:
-
Object
- Object
- Card::Mod::ModuleTemplate
- 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. SetModule and PatternTemplate inherit from it and adapt the template to their needs.
Direct Known Subclasses
Loader::SetLoader::Template, Loader::SetPatternLoader::Template
Instance Method Summary collapse
-
#build ⇒ Object
Evaluates the module in the top level namespace.
-
#initialize(modules, content_path) ⇒ ModuleTemplate
constructor
A new instance of ModuleTemplate.
-
#simple_load? ⇒ Boolean
Just run the code of the source.
-
#to_s ⇒ String
The ruby code to build the modal.
Constructor Details
#initialize(modules, content_path) ⇒ ModuleTemplate
Returns a new instance of ModuleTemplate.
8 9 10 11 12 13 14 |
# File 'lib/card/mod/module_template.rb', line 8 def initialize modules, content_path modules = Array.wrap modules @pattern = modules.shift @modules = modules @content = ::File.read content_path @content_path = content_path end |
Instance Method Details
#build ⇒ Object
Evaluates the module in the top level namespace.
17 18 19 |
# File 'lib/card/mod/module_template.rb', line 17 def build eval to_s, TOPLEVEL_BINDING, @content_path, offset end |
#simple_load? ⇒ Boolean
Just run the code of the source. Don't use the path to the file as module hierarchy.
29 30 31 |
# File 'lib/card/mod/module_template.rb', line 29 def simple_load? @content =~ /\A#!\s?simple load/ end |
#to_s ⇒ String
Returns the ruby code to build the modal.
22 23 24 25 |
# File 'lib/card/mod/module_template.rb', line 22 def to_s return content_with_source_comment if simple_load? wrap_with_module_def end |