Class: Cardio::Mod::Loader::SetTemplate
Overview
Instance Method Summary
collapse
#build, #simple_load?, #to_s
Constructor Details
#initialize(modules, content_path, strategy) ⇒ SetTemplate
Returns a new instance of SetTemplate.
6
7
8
9
|
# File 'card/lib/cardio/mod/loader/set_template.rb', line 6
def initialize modules, content_path, strategy
super
@modules.pop if helper_module?
end
|
Instance Method Details
26
27
28
29
30
31
32
33
34
35
|
# File 'card/lib/cardio/mod/loader/set_template.rb', line 26
def add_explicit_format_modules
@content.gsub!(/^ *format +:?(\w+)? *do *$/) do
format_name = Regexp.last_match(1)
format_name = format_name.blank? ? nil : format_name.to_sym
"module #{module_name format_name}; " \
"module_parent.send :register_set_format, "\
"#{format_class format_name}, self; "\
"extend Card::Set::AbstractFormat"
end
end
|
41
42
43
44
45
|
# File 'card/lib/cardio/mod/loader/set_template.rb', line 41
def format_class format_name
klass = ["Card::Format"]
klass << module_name(format_name) if format_name
klass.join "::"
end
|
#helper_module? ⇒ Boolean
47
48
49
50
51
52
53
|
# File 'card/lib/cardio/mod/loader/set_template.rb', line 47
def helper_module?
if @is_helper_module.nil?
@is_helper_module = @content =~ /\A#!\s?not? set module/
else
@is_helper_module
end
end
|
#module_name(format_name) ⇒ Object
37
38
39
|
# File 'card/lib/cardio/mod/loader/set_template.rb', line 37
def module_name format_name
Card::Format.format_class_name format_name
end
|
correct line number for error messages
56
57
58
|
# File 'card/lib/cardio/mod/loader/set_template.rb', line 56
def offset
-5
end
|
#processed_content ⇒ Object
21
22
23
24
|
# File 'card/lib/cardio/mod/loader/set_template.rb', line 21
def processed_content
add_explicit_format_modules if @strategy.
super
end
|
11
12
13
14
15
16
17
18
19
|
# File 'card/lib/cardio/mod/loader/set_template.rb', line 11
def to_const
return Object if simple_load?
@modules.inject(pattern_class) do |const, name_part|
const.const_get_or_set name_part do
Module.new
end
end
end
|