Class: SpreadsheetAgent::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheet_agent/db.rb

Overview

SpreadsheetAgent::Db is a class that is meant to be extended by SpreadsheetAgent classes. It stores shared code to instantiate and provide access to a GoogleDrive object and GoogleDrive::Spreadsheet object for use by the extending classes to access their Google Spreadsheets

Direct Known Subclasses

Agent, Runner

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

This holds the hash that is constructed from the YAML :config_file. It cannot be changed after the object is constructed



24
25
26
# File 'lib/spreadsheet_agent/db.rb', line 24

def config
  @config
end

#config_fileObject (readonly)

Passing this attribute to the constructor will override the location of config/agent.conf.yml. If passed, it must be a path to a file which matches the template in config/agent.conf.yml. The default is to load ../config/agent.config.yaml relative to the directory containing the calling script $0. This cannot be changed after the object is constructed



30
31
32
# File 'lib/spreadsheet_agent/db.rb', line 30

def config_file
  @config_file
end

#dbObject (readonly)

This holds the GoogleDrive::Spreadsheet object that can be used to query information from the google spreadsheet using its API. It cannot be changed after the object is constructed



16
17
18
# File 'lib/spreadsheet_agent/db.rb', line 16

def db
  @db
end

#sessionObject (readonly)

This holds the GoogleDrive object instantiated with the guser and gpass in the :config. It cannot be changed after the object is constructed



20
21
22
# File 'lib/spreadsheet_agent/db.rb', line 20

def session
  @session
end

Instance Method Details

#build_dbObject

This is for internal use by SpreadsheetAgent classes that extend SpreadsheetAgent::Db



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

def build_db
  build_config()
  unless @config['key_fields'].keys.select { |k| @config['key_fields'][k]['required'] }.count > 0
    raise SpreadsheetAgentError, "Your configuration must have at least one required key_fields key"
  end
  @session = GoogleDrive.(@config['guser'], @config['gpass'])
  @db = @session.spreadsheet_by_title(@config['spreadsheet_name'])
end