Class: SpreadsheetAgent::Db
- Inherits:
-
Object
- Object
- SpreadsheetAgent::Db
- 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
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
This holds the hash that is constructed from the YAML :config_file.
-
#config_file ⇒ Object
readonly
Passing this attribute to the constructor will override the location of config/agent.conf.yml.
-
#db ⇒ Object
readonly
This holds the GoogleDrive::Spreadsheet object that can be used to query information from the google spreadsheet using its API.
-
#session ⇒ Object
readonly
This holds the GoogleDrive object instantiated with the guser and gpass in the :config.
Instance Method Summary collapse
-
#build_db ⇒ Object
This is for internal use by SpreadsheetAgent classes that extend SpreadsheetAgent::Db.
Instance Attribute Details
#config ⇒ Object (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_file ⇒ Object (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 |
#db ⇒ Object (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 |
#session ⇒ Object (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_db ⇒ Object
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.login(@config['guser'], @config['gpass']) @db = @session.spreadsheet_by_title(@config['spreadsheet_name']) end |