Module: Card::Set::Loader

Included in:
Card::Set
Defined in:
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



64
65
66
67
68
69
# File 'lib/card/set/loader.rb', line 64

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



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

def clean_empty_modules
  clean_empty_module_from_hash modules[:nonbase]
  modules[:nonbase_format].values.each 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 '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



46
47
48
49
50
51
52
53
54
55
# File 'lib/card/set/loader.rb', line 46

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

  Card.add_set_modules modules[:base]
  modules[:base_format].each do |format_class, modules_list|
    format_class.add_set_modules modules_list
  end
  modules[:base].clear
  modules[:base_format].clear
end

#register_set(set_module) ⇒ Object

make the set available for use



21
22
23
24
25
26
27
28
29
30
31
# File '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
    # made ready for dynamic loading via #include_set_modules
    modules[set_type][set_module.shortname] ||= []
    modules[set_type][set_module.shortname] << set_module
  end
end