Class: GSquire::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/gsquire/application.rb

Overview

This is the entry-point class for GSquire. Clients should use it to implement applications that use GSquire.

As of now it is only a simple container used to setup logging and the database directory.

Since GSquire supports multiple accounts by default, this class simply wraps an Accounts instance that is available through the accounts instance attribute.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Application

Returns a new instance of Application.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :path (String) — default: "~/.gsquire"

    Where to store GSquire database

  • :log (Logger, String, Symbol) — default: nil

    Enables logging. Pass a configured Logger object to be used directly; or a String to change the filename and use the default level (must be absolute path); or a Symbol to change log level and use the default filename. If not present (nil), logging is disabled.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gsquire/application.rb', line 24

def initialize(opts = {})
  @options = {
    :path => File.join(ENV['HOME'], '.gsquire')
  }.merge(opts)

  begin
    FileUtils.mkdir_p options[:path]
  rescue
    abort "Error creating GSquire database directory: #{$!}"
  end

  @accounts = Accounts.new :path => options[:path], :logger => logger
end

Instance Attribute Details

#accountsObject (readonly)

GSquire::Accounts instance that holds all authorized Google accounts in the GSquire database stored at options[:path].



18
19
20
# File 'lib/gsquire/application.rb', line 18

def accounts
  @accounts
end

#optionsObject (readonly)

Parsed options.



20
21
22
# File 'lib/gsquire/application.rb', line 20

def options
  @options
end