Class: Turbotlib

Inherits:
Object
  • Object
show all
Extended by:
ScraperWiki
Defined in:
lib/turbotlib.rb,
lib/turbotlib/ftp.rb,
lib/turbotlib/client.rb,
lib/turbotlib/logger.rb,
lib/turbotlib/processor.rb

Defined Under Namespace

Classes: Client, FTP, FTPDelegator, Logger, Processor

Class Method Summary collapse

Class Method Details

.data_dirString

Returns the path to the data directory.

Returns:

  • (String)

    the path to the data directory



26
27
28
# File 'lib/turbotlib.rb', line 26

def data_dir
  path_to('data')
end

.get_var(key) ⇒ Object

Returns the value of a variable.

Parameters:

  • a (String)

    variable name

Returns:

  • the value of the variable



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

def get_var(key)
  get_vars[key]
end

.in_production?Boolean

Returns whether the environment is production.

Returns:

  • (Boolean)

    whether the environment is production



72
73
74
# File 'lib/turbotlib.rb', line 72

def in_production?
  !!ENV['MORPH_URL']
end

.log(message) ⇒ Object

Logs a message to STDERR.

Parameters:

  • message (String)

    a log message



19
20
21
# File 'lib/turbotlib.rb', line 19

def log(message)
  $stderr.puts message
end

.save_var(key, val) ⇒ Object

Saves and returns the value of a variable.

Parameters:

  • a (String)

    variable name

  • val

    the value of the variable

Returns:

  • the value of the variable



46
47
48
49
50
51
# File 'lib/turbotlib.rb', line 46

def save_var(key, val)
  vars = get_vars
  vars[key] = val
  save_vars(vars)
  val
end

.sources_dirString

Returns the path to the sources directory.

Returns:

  • (String)

    the path to the sources directory



33
34
35
36
37
38
39
# File 'lib/turbotlib.rb', line 33

def sources_dir
  if in_production? && !is_admin?
    raise 'Only admins are permitted to write to `sources_dir`'
  else
    path_to('sources')
  end
end

.sqlite_magic_connectionSqliteMagic::Connection

Override default in ScraperWiki gem.

Returns:

  • (SqliteMagic::Connection)

    a SQLite connection



64
65
66
67
# File 'lib/turbotlib.rb', line 64

def sqlite_magic_connection
  db = "#{data_dir}/data.sqlite"
  @sqlite_magic_connection ||= SqliteMagic::Connection.new(db)
end