Class: Talkable::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/talkable/configuration.rb

Defined Under Namespace

Classes: UnknownOptionError

Constant Summary collapse

DEFAULT_SERVER =
'https://www.talkable.com'.freeze
DEFAULT_TIMEOUT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



16
17
18
# File 'lib/talkable/configuration.rb', line 16

def initialize
  apply(default_configuration)
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/talkable/configuration.rb', line 7

def api_key
  @api_key
end

#js_integration_libraryObject

Returns the value of attribute js_integration_library.



11
12
13
# File 'lib/talkable/configuration.rb', line 11

def js_integration_library
  @js_integration_library
end

#open_timeoutObject

Returns the value of attribute open_timeout.



10
11
12
# File 'lib/talkable/configuration.rb', line 10

def open_timeout
  @open_timeout
end

#read_timeoutObject

Returns the value of attribute read_timeout.



9
10
11
# File 'lib/talkable/configuration.rb', line 9

def read_timeout
  @read_timeout
end

#serverObject

Returns the value of attribute server.



8
9
10
# File 'lib/talkable/configuration.rb', line 8

def server
  @server
end

#site_slugObject

Returns the value of attribute site_slug.



6
7
8
# File 'lib/talkable/configuration.rb', line 6

def site_slug
  @site_slug
end

Instance Method Details

#apply(config) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/talkable/configuration.rb', line 20

def apply(config)
  config.each do |key, value|
    if respond_to?("#{key}=")
      public_send("#{key}=", value)
    else
      raise UnknownOptionError.new("There is no `#{key}` option")
    end
  end
end

#resetObject



34
35
36
# File 'lib/talkable/configuration.rb', line 34

def reset
  apply(default_configuration)
end

#timeout=(sec) ⇒ Object



38
39
40
# File 'lib/talkable/configuration.rb', line 38

def timeout=(sec)
  apply(read_timeout: sec, open_timeout: sec)
end