Class: TimeDoctor::Config

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Returns a new instance of Config.



44
45
46
# File 'lib/timedoctor/config.rb', line 44

def initialize(options)
  @config = OpenStruct.new(options)
end

Class Method Details

.[](key) ⇒ Object



31
32
33
# File 'lib/timedoctor/config.rb', line 31

def [](key)
  config[key]
end

.[]=(key, value) ⇒ Object



35
36
37
# File 'lib/timedoctor/config.rb', line 35

def []=(key, value)
  config[key] = value
end

.configObject



27
28
29
# File 'lib/timedoctor/config.rb', line 27

def config
  @config || configure
end

.configure(options = {}, &blk) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/timedoctor/config.rb', line 6

def configure(options = {}, &blk)
  @config = OpenStruct.new(options)

  config[:on_token_authorize] ||= lambda do |_data, _conf|
  end

  config[:on_token_authorize_error] ||= lambda do |data, _conf|
    raise UnauthorizedError, data
  end

  config[:on_token_refresh] ||= lambda do |_data, _conf|
  end

  config[:on_token_refresh_error] ||= lambda do |data, _conf|
    raise UnauthorizedError, data
  end

  instance_exec(config, &blk) if block_given?
  config
end

.inspectObject



39
40
41
# File 'lib/timedoctor/config.rb', line 39

def inspect
  config.to_h
end

Instance Method Details

#[](key) ⇒ Object



52
53
54
# File 'lib/timedoctor/config.rb', line 52

def [](key)
  config[key] || Config[key]
end

#[]=(key, value) ⇒ Object



56
57
58
# File 'lib/timedoctor/config.rb', line 56

def []=(key, value)
  config[key] = value
end

#configObject



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

def config
  @config ||= OpenStruct.new
end

#inspectObject



60
61
62
63
64
65
# File 'lib/timedoctor/config.rb', line 60

def inspect
  {
    local: @config.to_h,
    global: Config.inspect
  }
end