Module: Card::Set::Pattern::All

Included in:
CardMethods
Defined in:
lib/card/set/pattern/all.rb

Overview

pattern-related Card instance methods

Instance Method Summary collapse

Instance Method Details

#concrete_patternsObject



22
23
24
# File 'lib/card/set/pattern/all.rb', line 22

def concrete_patterns
  @concrete_patterns ||= Pattern.concrete.map { |sub| sub.new self }.compact
end

#each_type_assigning_module_keyObject



74
75
76
77
78
79
80
81
# File 'lib/card/set/pattern/all.rb', line 74

def each_type_assigning_module_key
  patterns.each do |p|
    next unless p.assigns_type

    module_key = p.module_key
    yield module_key if module_key
  end
end

#in_set?(set_module) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/card/set/pattern/all.rb', line 62

def in_set? set_module
  patterns.map(&:module_key).include? set_module.shortname
end

#include_module?(set) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/card/set/pattern/all.rb', line 70

def include_module? set
  singleton_class&.include? set
end

#patternsObject

new cards do not



27
28
29
# File 'lib/card/set/pattern/all.rb', line 27

def patterns
  @patterns ||= (new_card? ? concrete_patterns[1..-1] : concrete_patterns)
end

#patterns?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/card/set/pattern/all.rb', line 18

def patterns?
  defined? @patterns
end

#prep_modules_for_cachingObject

Because Card works by including set-specific ruby modules on singleton classes, and singleton classes generally can’t be cached, we can never cache the cards in a completely ready-to-roll form.

However, we can optimize considerably by saving the list of ruby modules in environments where they won’t be changing (eg production) or at least the list of matching set patterns



13
14
15
16
# File 'lib/card/set/pattern/all.rb', line 13

def prep_modules_for_caching
  patterns
  set_modules if Cardio.config.cache_set_module_list
end

#reset_patternsObject



31
32
33
34
35
36
37
38
# File 'lib/card/set/pattern/all.rb', line 31

def reset_patterns
  # Rails.logger.info "resetting patterns: #{name}"
  @patterns = @concrete_patterns = nil
  @template = @virtual = nil
  @set_mods_loaded = @set_modules = @set_names = @rule_lookup_keys = nil
  @compound_only = nil # only applies to set cards
  true
end

#rule_lookup_keysObject



66
67
68
# File 'lib/card/set/pattern/all.rb', line 66

def rule_lookup_keys
  @rule_lookup_keys ||= patterns.map(&:rule_lookup_key).compact
end

#safe_set_keysObject



40
41
42
# File 'lib/card/set/pattern/all.rb', line 40

def safe_set_keys
  patterns.map(&:safe_key).reverse * " "
end

#set_format_modules(klass) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/card/set/pattern/all.rb', line 49

def set_format_modules klass
  @set_format_modules ||= {}
  @set_format_modules[klass] =
    concrete_patterns[0..-2].reverse.map do |pattern|
      pattern.format_module_list klass
    end.flatten.compact
end

#set_modulesObject



44
45
46
47
# File 'lib/card/set/pattern/all.rb', line 44

def set_modules
  @set_modules ||=
    concrete_patterns[0..-2].reverse.map(&:module_list).flatten.compact
end

#set_namesObject



57
58
59
60
# File 'lib/card/set/pattern/all.rb', line 57

def set_names
  @set_names = patterns.map(&:to_s) if @set_names.nil?
  @set_names
end