Sha256: 5571fbd765a0758823cde598a26a93742fde1d23f1112bf002ed933d1869b459

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require 'attractor/version'
require 'attractor/gem_names'
require 'attractor/duration_parser'
require 'attractor/calculators/base_calculator'
require 'attractor/detectors/base_detector'
require 'attractor/reporters/base_reporter'
require 'attractor/suggester'
require 'attractor/watcher'

Dir[File.join(__dir__, 'attractor', 'reporters', '*.rb')].each do |file|
  next if file.start_with?('base')

  require file
end

module Attractor
  class Error < StandardError; end

  @registry_entries = {}

  def register(registry_entry)
    @registry_entries[registry_entry.type] = registry_entry
  end

  def calculators_for_type(type, **options)
    registry_entry_for_type = @registry_entries[type]

    return { type => registry_entry_for_type.calculator_class.new(**options) } if type

    
    Hash[@registry_entries.map do |type, entry|
      [type, entry.calculator_class.new(**options)] if entry.detector_class.new.detect
    end.compact]
  end

  module_function :calculators_for_type
  module_function :register
end

Attractor::GemNames.new.to_a.each do |gem_name|
  require "attractor/#{gem_name}"
end

Version data entries

6 entries across 5 versions & 1 rubygems

Version Path
attractor-2.1.0 lib/attractor.rb~
attractor-2.0.5 lib/attractor.rb
attractor-2.0.5 lib/attractor.rb~
attractor-2.0.4 lib/attractor.rb
attractor-2.0.3 lib/attractor.rb
attractor-2.0.2 lib/attractor.rb