Class: Crosstest::Psychic::ScriptFactory

Inherits:
FactoryManager show all
Includes:
Core::Logger
Defined in:
lib/crosstest/psychic/script_factory.rb

Constant Summary collapse

TASK_PRIORITY =
5

Constants inherited from FactoryManager

FactoryManager::BUILT_IN_DIR

Instance Attribute Summary collapse

Attributes inherited from FactoryManager

#factories

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FactoryManager

#active_factories, autoload_factories!, clear, factory_classes, register_factory

Constructor Details

#initialize(psychic, opts) ⇒ ScriptFactory

Returns a new instance of ScriptFactory


32
33
34
35
36
# File 'lib/crosstest/psychic/script_factory.rb', line 32

def initialize(psychic, opts)
  @psychic = psychic
  @opts = opts
  @logger = opts[:logger] || new_logger
end

Instance Attribute Details

#priorityObject (readonly)

Returns the value of attribute priority


8
9
10
# File 'lib/crosstest/psychic/script_factory.rb', line 8

def priority
  @priority
end

#psychicObject (readonly)

Returns the value of attribute psychic


8
9
10
# File 'lib/crosstest/psychic/script_factory.rb', line 8

def psychic
  @psychic
end

#run_patternsObject (readonly)

Returns the value of attribute run_patterns


8
9
10
# File 'lib/crosstest/psychic/script_factory.rb', line 8

def run_patterns
  @run_patterns
end

Class Method Details

.priority_for_script(script) ⇒ Object


23
24
25
26
27
28
29
# File 'lib/crosstest/psychic/script_factory.rb', line 23

def priority_for_script(script)
  script_path = Pathname(script)
  run_patterns.each do | pattern, priority |
    return priority if script_path.fnmatch(pattern, File::FNM_CASEFOLD)
  end
  nil
end

.register_script_factoryObject


11
12
13
# File 'lib/crosstest/psychic/script_factory.rb', line 11

def register_script_factory
  Crosstest::Psychic::ScriptFactoryManager.register_factory(self)
end

.run_patternsObject


15
16
17
# File 'lib/crosstest/psychic/script_factory.rb', line 15

def run_patterns
  @run_patterns ||= {}
end

.runs(ext, priority = 5) ⇒ Object


19
20
21
# File 'lib/crosstest/psychic/script_factory.rb', line 19

def runs(ext, priority = 5)
  run_patterns[ext] = priority
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/crosstest/psychic/script_factory.rb', line 38

def active?
  true
end

#command_for_script(_script) ⇒ Object


61
62
63
# File 'lib/crosstest/psychic/script_factory.rb', line 61

def command_for_script(_script)
  fail NotImplementedError, 'This should be implemented by subclasses'
end

#cwdObject


42
43
44
# File 'lib/crosstest/psychic/script_factory.rb', line 42

def cwd
  psychic.cwd
end

#known_script?(script) ⇒ Boolean

Returns:

  • (Boolean)

53
54
55
# File 'lib/crosstest/psychic/script_factory.rb', line 53

def known_script?(script)
  known_scripts.include? Pathname(script)
end

#known_scriptsObject


46
47
48
49
50
51
# File 'lib/crosstest/psychic/script_factory.rb', line 46

def known_scripts
  cwd_path = Pathname(cwd)
  self.class.run_patterns.flat_map do | pattern, _priority |
    Dir[cwd_path.join(pattern)]
  end
end

#priority_for_script(script) ⇒ Object


57
58
59
# File 'lib/crosstest/psychic/script_factory.rb', line 57

def priority_for_script(script)
  self.class.priority_for_script(script)
end