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.5.0"

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



34
35
36
37
# File 'lib/zonebie.rb', line 34

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

.backendObject



7
8
9
10
11
12
13
14
15
16
17
# 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



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

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

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

  @backend
end

.random_timezoneObject



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

def random_timezone
  zones = backend.zones
  zones[rand(zones.length)]
end

.set_random_timezoneObject



39
40
41
42
43
44
# File 'lib/zonebie.rb', line 39

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

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