Class: SQLiteSweep::Config

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

Overview

Immutable configuration for a sweep run. Built from CLI flags and passed to every component.

Uses Data.define for a frozen value object — once created, a Config cannot be modified.

Examples:

config = Config.new(
  query: "SELECT count(*) FROM users",
  source: "cat uris.txt",
  action: :sum,
  concurrency: 16
)
config.action     # => :sum
config.concurrency # => 16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, source:, action: :sum, concurrency: 8, max_ssh: 50, live: $stderr.tty?, batch_size: 4, ssh_timeout: 10, query_timeout: 30) ⇒ Config

Returns a new instance of Config.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sqlitesweep/config.rb', line 29

def initialize(
  query:,
  source:,
  action: :sum,
  concurrency: 8,
  max_ssh: 50,
  live: $stderr.tty?,
  batch_size: 4,
  ssh_timeout: 10,
  query_timeout: 30
)
  action = action.to_sym
  action = :average if action == :avg
  unless %i[sum average list].include?(action)
    raise ConfigError, "Unknown action: #{action}. Must be sum, average/avg, or list"
  end
  super(
    query: query,
    action: action,
    source: source,
    concurrency: concurrency,
    max_ssh: max_ssh,
    live: live,
    batch_size: batch_size,
    ssh_timeout: ssh_timeout,
    query_timeout: query_timeout
  )
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def action
  @action
end

#batch_sizeObject (readonly)

Returns the value of attribute batch_size

Returns:

  • (Object)

    the current value of batch_size



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def batch_size
  @batch_size
end

#concurrencyObject (readonly)

Returns the value of attribute concurrency

Returns:

  • (Object)

    the current value of concurrency



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def concurrency
  @concurrency
end

#liveObject (readonly)

Returns the value of attribute live

Returns:

  • (Object)

    the current value of live



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def live
  @live
end

#max_sshObject (readonly)

Returns the value of attribute max_ssh

Returns:

  • (Object)

    the current value of max_ssh



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def max_ssh
  @max_ssh
end

#queryObject (readonly)

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def query
  @query
end

#query_timeoutObject (readonly)

Returns the value of attribute query_timeout

Returns:

  • (Object)

    the current value of query_timeout



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def query_timeout
  @query_timeout
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def source
  @source
end

#ssh_timeoutObject (readonly)

Returns the value of attribute ssh_timeout

Returns:

  • (Object)

    the current value of ssh_timeout



18
19
20
# File 'lib/sqlitesweep/config.rb', line 18

def ssh_timeout
  @ssh_timeout
end