Class: CalendarAssistant::CLI::CommandService

Inherits:
Object
  • Object
show all
Defined in:
lib/calendar_assistant/cli/command_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, options: {}) ⇒ CommandService

Returns a new instance of CommandService.



6
7
8
9
10
11
12
13
# File 'lib/calendar_assistant/cli/command_service.rb', line 6

def initialize(context:, options: {})
  @options = options.dup
  @options[CalendarAssistant::Config::Keys::Options::CONTEXT] ||= context.to_s

  @config = CalendarAssistant::CLI::Config.new(options: @options)
  @authorizer = {}
  @out = CalendarAssistant::CLI::Printer.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/calendar_assistant/cli/command_service.rb', line 4

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/calendar_assistant/cli/command_service.rb', line 4

def options
  @options
end

#outObject (readonly)

Returns the value of attribute out.



4
5
6
# File 'lib/calendar_assistant/cli/command_service.rb', line 4

def out
  @out
end

Instance Method Details

#authorizer(profile_name: config.profile_name, token_store: config.token_store) ⇒ Object



22
23
24
# File 'lib/calendar_assistant/cli/command_service.rb', line 22

def authorizer(profile_name: config.profile_name, token_store: config.token_store)
  @authorizer[profile_name] ||= Authorizer.new(profile_name, token_store)
end

#calendar_assistant(datespec) ⇒ Object



15
16
17
18
19
20
# File 'lib/calendar_assistant/cli/command_service.rb', line 15

def calendar_assistant(datespec)
  ca = CalendarAssistant.new(config, service: service)
  ca.in_env do
    yield(ca, CalendarAssistant::CLI::Helpers.parse_datespec(datespec), out)
  end
end

#serviceObject



26
27
28
29
30
31
32
33
34
# File 'lib/calendar_assistant/cli/command_service.rb', line 26

def service
  @service ||= begin
    if filename = config.setting(Config::Keys::Options::LOCAL_STORE)
      CalendarAssistant::LocalService.new(file: filename)
    else
      authorizer.service
    end
  end
end