Module: Card::Set::Loader

Included in:
Card::Set
Defined in:
card/lib/card/set/loader.rb

Overview

  1. Definition: interpret each set file, creating/defining set and set_format modules
  2. Organization: have base classes include modules associated with the ‘all’ set, and clean up the other modules

Instance Method Summary collapse

Instance Method Details

#clean_empty_module_from_hash(hash) ⇒ Object



58
59
60
61
62
63
# File 'card/lib/card/set/loader.rb', line 58

def clean_empty_module_from_hash hash
  hash.each do |mod_name, modlist|
    modlist.delete_if { |x| x.instance_methods.empty? }
    hash.delete mod_name if modlist.empty?
  end
end

#clean_empty_modulesObject



51
52
53
54
55
56
# File 'card/lib/card/set/loader.rb', line 51

def clean_empty_modules
  clean_empty_module_from_hash modules[:nonbase]
  modules[:nonbase_format].each_value do |hash|
    clean_empty_module_from_hash hash
  end
end

#extended(mod) ⇒ Object

each set file calls extend Card::Set when loaded



16
17
18
# File 'card/lib/card/set/loader.rb', line 16

def extended mod
  register_set mod
end

#process_base_modulesObject

‘base modules’ are modules that are always included on the Card or Format class ‘nonbase modules’ are included dynamically on singleton_classes



42
43
44
45
46
47
48
49
# File 'card/lib/card/set/loader.rb', line 42

def process_base_modules
  base_modules = modules[:base]
  return unless base_modules.present?

  Card.add_set_modules base_modules
  process_base_format_modules modules[:base_format]
  base_modules.clear
end

#register_set(set_module) ⇒ Object

make the set available for use



21
22
23
24
25
26
27
28
29
# File 'card/lib/card/set/loader.rb', line 21

def register_set set_module
  if set_module.all_set?
    # automatically included in Card class
    modules[:base] << set_module
  else
    set_type = set_module.abstract_set? ? :abstract : :nonbase
    register_set_of_type set_module, set_type
  end
end