Class: ClickHouse::Config

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

Constant Summary collapse

DEFAULTS =
{
  adapter: Faraday.default_adapter,
  url: nil,
  scheme: 'http',
  host: 'localhost',
  port: '8123',
  logger: nil,
  database: nil,
  username: nil,
  password: nil,
  timeout: nil,
  open_timeout: nil,
  ssl_verify: false,
  headers: {},
  global_params: {},
  json_parser: ClickHouse::Middleware::ParseJson,
  json_serializer: ClickHouse::Serializer::JsonSerializer,
  oj_dump_options: {
    mode: :compat # to be able to dump improper JSON like {1 => 2}
  },
  oj_load_options: {
    mode: :custom,
    allow_blank: true,
    bigdecimal_as_decimal: false, # dump BigDecimal as a String
    bigdecimal_load: :bigdecimal, # convert all decimal numbers to BigDecimal
  },
  json_load_options: {
    decimal_class: BigDecimal,
  },
  # should be after json load options
  symbolize_keys: false,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:



59
60
61
62
# File 'lib/click_house/config.rb', line 59

def initialize(params = {})
  assign(DEFAULTS.merge(params))
  yield(self) if block_given?
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



38
39
40
# File 'lib/click_house/config.rb', line 38

def adapter
  @adapter
end

#databaseObject

Returns the value of attribute database.



43
44
45
# File 'lib/click_house/config.rb', line 43

def database
  @database
end

#global_paramsObject

Returns the value of attribute global_params.



51
52
53
# File 'lib/click_house/config.rb', line 51

def global_params
  @global_params
end

#headersObject

Returns the value of attribute headers.



50
51
52
# File 'lib/click_house/config.rb', line 50

def headers
  @headers
end

#hostObject

Returns the value of attribute host.



41
42
43
# File 'lib/click_house/config.rb', line 41

def host
  @host
end

#json_load_optionsObject

Returns the value of attribute json_load_options.



53
54
55
# File 'lib/click_house/config.rb', line 53

def json_load_options
  @json_load_options
end

#json_parserObject

response middleware



54
55
56
# File 'lib/click_house/config.rb', line 54

def json_parser
  @json_parser
end

#json_serializerObject

ClickHouse::Serializer::Base


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

def json_serializer
  @json_serializer
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#oj_dump_optionsObject

Returns the value of attribute oj_dump_options.



55
56
57
# File 'lib/click_house/config.rb', line 55

def oj_dump_options
  @oj_dump_options
end

#oj_load_optionsObject

Returns the value of attribute oj_load_options.



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

def oj_load_options
  @oj_load_options
end

#open_timeoutObject

Returns the value of attribute open_timeout.



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

def open_timeout
  @open_timeout
end

#passwordObject

Returns the value of attribute password.



46
47
48
# File 'lib/click_house/config.rb', line 46

def password
  @password
end

#portObject

Returns the value of attribute port.



42
43
44
# File 'lib/click_house/config.rb', line 42

def port
  @port
end

#schemeObject

Returns the value of attribute scheme.



40
41
42
# File 'lib/click_house/config.rb', line 40

def scheme
  @scheme
end

#ssl_verifyObject

Returns the value of attribute ssl_verify.



49
50
51
# File 'lib/click_house/config.rb', line 49

def ssl_verify
  @ssl_verify
end

#symbolize_keysObject

NilClass, Boolean


57
58
59
# File 'lib/click_house/config.rb', line 57

def symbolize_keys
  @symbolize_keys
end

#timeoutObject

Returns the value of attribute timeout.



47
48
49
# File 'lib/click_house/config.rb', line 47

def timeout
  @timeout
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#usernameObject

Returns the value of attribute username.



45
46
47
# File 'lib/click_house/config.rb', line 45

def username
  @username
end

Instance Method Details

#assign(params = {}) ⇒ self

Returns:

  • (self)


65
66
67
68
69
# File 'lib/click_house/config.rb', line 65

def assign(params = {})
  params.each { |k, v| public_send("#{k}=", v) }

  self
end

#auth?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/click_house/config.rb', line 71

def auth?
  !username.nil? || !password.nil?
end

#key(name) ⇒ Object

Parameters:

  • name (Symbol, String)


103
104
105
# File 'lib/click_house/config.rb', line 103

def key(name)
  symbolize_keys ? name.to_sym : name.to_s
end

#logger!Object



75
76
77
# File 'lib/click_house/config.rb', line 75

def logger!
  @logger || null_logger
end

#null_loggerObject



83
84
85
# File 'lib/click_house/config.rb', line 83

def null_logger
  @null_logger ||= Logger.new(IO::NULL)
end

#url!Object



79
80
81
# File 'lib/click_house/config.rb', line 79

def url!
  @url || "#{scheme}://#{host}:#{port}"
end