Class: Binpacker::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/binpacker/config.rb

Constant Summary collapse

DEFAULTS =
{
  "test_runner" => "rspec",
  "workers" => "auto",
  "test_granularity" => "file",
  "timing_file" => "binpacker.timings",
  "test_pattern" => "spec/**/*_spec.rb",
  "test_exclude" => [],
  "scheduler" => {
    "strategy" => "static",
    "steal_enabled" => false,
    "algorithm" => "lpt"
  }
}.freeze
CI_ENV_VARS =
%w[CI GITHUB_ACTIONS GITLAB_CI JENKINS_HOME].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile: nil, config_path: nil) ⇒ Config

Returns a new instance of Config.



26
27
28
29
30
31
# File 'lib/binpacker/config.rb', line 26

def initialize(profile: nil, config_path: nil)
  @config_path = config_path || find_config
  @raw = load_config
  @profile = resolve_profile(profile)
  @merged = build_profile(@profile)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/binpacker/config.rb', line 33

def method_missing(name, *)
  key = name.to_s
  if @merged.key?(key)
    @merged[key]
  else
    super
  end
end

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



8
9
10
# File 'lib/binpacker/config.rb', line 8

def profile
  @profile
end

Instance Method Details

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/binpacker/config.rb', line 42

def respond_to_missing?(name, *)
  @merged.key?(name.to_s) || super
end

#schedulerObject



46
47
48
# File 'lib/binpacker/config.rb', line 46

def scheduler
  @merged["scheduler"]
end

#worker_countObject



50
51
52
53
54
# File 'lib/binpacker/config.rb', line 50

def worker_count
  workers = @merged["workers"]
  return Etc.nprocessors if workers == "auto"
  Integer(workers)
end