class Cardio::Mod::Loader::SetTemplate
Template for set modules
Public Class Methods
new(modules, content_path, strategy)
click to toggle source
Calls superclass method
# File lib/cardio/mod/loader/set_template.rb, line 6 def initialize modules, content_path, strategy super @modules.pop if helper_module? end
Public Instance Methods
add_explicit_format_modules()
click to toggle source
# File 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
format_class(format_name)
click to toggle source
# File 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?()
click to toggle source
# File 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)
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 37 def module_name format_name Card::Format.format_class_name format_name end
offset()
click to toggle source
correct line number for error messages
# File lib/cardio/mod/loader/set_template.rb, line 56 def offset -5 end
processed_content()
click to toggle source
Calls superclass method
# File lib/cardio/mod/loader/set_template.rb, line 21 def processed_content add_explicit_format_modules if @strategy.clean_comments? super end
to_const()
click to toggle source
# File 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
Private Instance Methods
auto_comment()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 80 def auto_comment "# Set: #{label_body(*@modules)}\n#" end
capture_last_module()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 112 def capture_last_module module_chain @last_module = @module_chain.pop end
label_body(*anchors)
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 84 def label_body *anchors if @pattern == "Abstract" "Abstract (#{@modules.join ', '})" else pattern_label(*anchors) end end
location_method()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 121 def location_method %(def self.source_location; "#{@content_path}"; end) end
module_chain()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 66 def module_chain @module_chain ||= ["class Card", "module Set", "class #{@pattern.camelize}"] + submodule_chain end
pattern_anchor(*anchors, anchor_count)
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 100 def pattern_anchor *anchors, anchor_count if anchor_count.zero? "" else anchors[0..anchor_count].join(Card::Name.joint) end end
pattern_class()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 108 def pattern_class @pattern_class ||= Card::Set.const_get_or_set(@pattern.camelize) { Class.new } end
pattern_label(*anchors)
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 92 def pattern_label *anchors anchor_count = pattern_class.anchor_parts_count label = pattern_class.label(pattern_anchor(*anchors, anchor_count)) remainder = anchors[anchor_count..-1] label += " (#{remainder.join ', '})" if remainder.any? label end
postamble()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 125 def postamble "end;" * (@modules.size + 3) end
preamble_bits()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 71 def preamble_bits capture_last_module [module_chain.join("; "), module_comment, @last_module, set_extension, location_method].compact end
set_extension()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 117 def set_extension "extend Card::Set" unless helper_module? end
submodule_chain()
click to toggle source
# File lib/cardio/mod/loader/set_template.rb, line 62 def submodule_chain @modules.map { |m| "module #{m};" } end