Class: Polyspec::RunnerFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/polyspec/runner_factory.rb

Constant Summary collapse

PROJECT_TYPE_MATCHERS =
{
  DjangoProjectRunner => ->(project_files) { project_files.any? {|f| next if File.extname(f) == '.pyc'; File.read(f).match(/django/i) } },
  GolangProjectRunner => ->(project_files) { project_files.any? {|f| File.extname(f) == '.go' } },
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path) ⇒ RunnerFactory

Returns a new instance of RunnerFactory.



6
7
8
# File 'lib/polyspec/runner_factory.rb', line 6

def initialize(project_path)
  @project_path = project_path
end

Instance Attribute Details

#project_pathObject (readonly)

Returns the value of attribute project_path.



5
6
7
# File 'lib/polyspec/runner_factory.rb', line 5

def project_path
  @project_path
end

Instance Method Details

#getObject



15
16
17
18
# File 'lib/polyspec/runner_factory.rb', line 15

def get
  project_files = Find.find(project_path).select {|f| File.file?(f) }
  PROJECT_TYPE_MATCHERS.find {|runner, matcher| matcher.call(project_files) }.first
end