File: unleash.rb

package info (click to toggle)
ruby-unleash 3.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 252 kB
  • sloc: ruby: 1,098; makefile: 10; sh: 4
file content (40 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'unleash/version'
require 'unleash/configuration'
require 'unleash/strategy/base'
require 'unleash/context'
require 'unleash/client'
require 'logger'

Gem.find_files('unleash/strategy/**/*.rb').each{ |path| require path unless path.end_with? '_spec.rb' }

module Unleash
  TIME_RESOLUTION = 3

  STRATEGIES = Unleash::Strategy.constants
    .select{ |c| Unleash::Strategy.const_get(c).is_a? Class }
    .reject{ |c| ['NotImplemented', 'Base'].include?(c.to_s) }
    .map do |c|
      lowered_c = c.to_s
      lowered_c[0] = lowered_c[0].downcase
      [lowered_c.to_sym, Object.const_get("Unleash::Strategy::#{c}").new]
    end
    .to_h

  class << self
    attr_accessor :configuration, :toggle_fetcher, :toggles, :toggle_metrics, :reporter, :logger
  end

  def self.initialize
    self.toggles = []
    self.toggle_metrics = {}
  end

  # Support for configuration via yield:
  def self.configure
    self.configuration ||= Unleash::Configuration.new
    yield(configuration)

    self.configuration.validate!
    self.configuration.refresh_backup_file!
  end
end