Module: Zonebie

Defined in:
lib/zonebie.rb,
lib/zonebie/version.rb,
lib/zonebie/backends/tzinfo.rb,
lib/zonebie/backends/active_support.rb

Defined Under Namespace

Modules: Backends

Constant Summary collapse

VERSION =
'0.6.1'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.quietObject

Returns the value of attribute quiet.



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

def quiet
  @quiet
end

Class Method Details

.add_backend(backend) ⇒ Object



36
37
38
39
# File 'lib/zonebie.rb', line 36

def add_backend(backend)
  @backends ||= {}
  @backends[backend.name] = backend
end

.backendObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/zonebie.rb', line 7

def backend
  unless @backend
    @backend = \
      if @backends[:activesupport].usable?
        @backends[:activesupport]
      else
        @backends.values.detect(&:usable?)
      end
  end

  @backend
end

.backend=(backend) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zonebie.rb', line 20

def backend=(backend)
  @backend = \
    case backend
    when Symbol
      @backends[backend]
    else
      backend
    end

  if !backend.nil? && @backend.nil?
    fail ArgumentError, "Unsupported backend: #{backend}"
  end

  @backend
end

.random_timezoneObject



48
49
50
# File 'lib/zonebie.rb', line 48

def random_timezone
  backend.zones.sample
end

.set_random_timezoneObject



41
42
43
44
45
46
# File 'lib/zonebie.rb', line 41

def set_random_timezone
  zone = ENV['ZONEBIE_TZ'] || random_timezone

  $stdout.puts("[Zonebie] Setting timezone: ZONEBIE_TZ=\"#{zone}\"") unless quiet
  backend.zone = zone
end