Class: Cardio::Mod::LoadStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/cardio/mod/load_strategy.rb,
lib/cardio/mod/load_strategy/eval.rb,
lib/cardio/mod/load_strategy/tmp_files.rb,
lib/cardio/mod/load_strategy/set_tmp_files.rb,
lib/cardio/mod/load_strategy/pattern_tmp_files.rb

Overview

The main way to enhance cards’ appearance and behavior is through the card set DSL.

The default mechanism for loading DSL code is live evaluation, or Eval. Eval is fast and efficient and preferred for a wide range of scenarios, including production and live debugging. But Eval is problematic for generating both test coverage reports with Simplecov and documentation sites with YARD.

For those two reasons, we make it possible to load the DSL code by generating fully explicit ruby modules in tmp files.

Shared code for the three different load strategies: Eval, TmpFiles and BindingMagic

Direct Known Subclasses

BindingMagic, Eval, TmpFiles

Defined Under Namespace

Classes: Eval, PatternTmpFiles, SetTmpFiles, TmpFiles

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loader) ⇒ LoadStrategy

Returns a new instance of LoadStrategy.



39
40
41
42
# File 'lib/cardio/mod/load_strategy.rb', line 39

def initialize loader
  LoadStrategy.current = self.class
  @loader = loader
end

Class Attribute Details

.currentObject

Returns the value of attribute current.



16
17
18
# File 'lib/cardio/mod/load_strategy.rb', line 16

def current
  @current
end

.tmp_filesObject

Returns the value of attribute tmp_files.



16
17
18
# File 'lib/cardio/mod/load_strategy.rb', line 16

def tmp_files
  @tmp_files
end

Instance Attribute Details

#loaderObject (readonly)

Returns the value of attribute loader.



35
36
37
# File 'lib/cardio/mod/load_strategy.rb', line 35

def loader
  @loader
end

Class Method Details

.class_for_set(strategy) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/cardio/mod/load_strategy.rb', line 18

def class_for_set strategy
  case strategy
  when :tmp_files then SetTmpFiles
  when :binding_magic then SetBindingMagic
  else Eval
  end
end

.class_for_set_pattern(strategy) ⇒ Object



26
27
28
# File 'lib/cardio/mod/load_strategy.rb', line 26

def class_for_set_pattern strategy
  strategy == :tmp_files ? PatternTmpFiles : Eval
end

.tmp_files?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cardio/mod/load_strategy.rb', line 30

def tmp_files?
  Cardio.config.load_strategy == :tmp_files
end

Instance Method Details

#clean_comments?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/cardio/mod/load_strategy.rb', line 44

def clean_comments?
  false
end