Module: GovFakeNotify

Defined in:
lib/gov_fake_notify/config.rb,
lib/gov_fake_notify.rb,
lib/gov_fake_notify/store.rb,
lib/gov_fake_notify/version.rb,
lib/gov_fake_notify/cli/root.rb,
lib/gov_fake_notify/root_app.rb,
lib/gov_fake_notify/files_app.rb,
lib/gov_fake_notify/control_app.rb,
lib/gov_fake_notify/templates_app.rb,
lib/gov_fake_notify/current_service.rb,
lib/gov_fake_notify/attachment_store.rb,
lib/gov_fake_notify/notifications_app.rb,
lib/gov_fake_notify/commands/fetch_file_command.rb,
lib/gov_fake_notify/commands/send_email_command.rb,
lib/gov_fake_notify/commands/create_template_command.rb,
lib/gov_fake_notify/commands/fetch_templates_command.rb,
lib/gov_fake_notify/commands/fetch_message_status_command.rb,
lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb

Overview

GovFakeNotify module

Defined Under Namespace

Modules: Cli, CurrentService Classes: AttachmentStore, Config, ControlApp, CreateTemplateCommand, Error, FetchAllMessagesStatusCommand, FetchFileCommand, FetchMessageStatusCommand, FetchTemplatesCommand, FilesApp, NotificationsApp, RootApp, SendEmailCommand, Store, TemplatesApp

Constant Summary collapse

VERSION =
'2.0.0'

Class Method Summary collapse

Class Method Details

.configObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/gov_fake_notify.rb', line 11

def self.config
  Config.instance.tap do |instance|
    if block_given?
      yield instance
      configure_mail
      configure_templates
      configure_api_keys
    end
  end
end

.configure_api_keys(store: Store.instance) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gov_fake_notify.rb', line 43

def self.configure_api_keys(store: Store.instance)
  config.include_api_keys.each do |k|
    api_key = k.transform_keys(&:to_s)
    next if store.transaction { store.root?("apikey-#{api_key['key']}") }

    store.transaction do
      key = api_key.dup
      secret_token = key['key']
      key['service_id'] = secret_token[-73..-38]
      key['secret_token'] = secret_token[-36..-1]
      store["apikey-#{api_key['key']}"] = key
    end
  end
end

.configure_mailObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gov_fake_notify.rb', line 22

def self.configure_mail
  our_config = config
  Mail.defaults do
    case our_config.delivery_method.to_s
    when 'smtp'
      delivery_method :smtp, address: our_config.smtp_address, port: our_config.smtp_port
    when 'test'
      delivery_method :test
    end
  end
end

.configure_templates(store: Store.instance) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/gov_fake_notify.rb', line 34

def self.configure_templates(store: Store.instance)
  config.include_templates.each do |t|
    template = t.transform_keys(&:to_s)
    next if store.transaction { store.root?("template-#{template['id']}") }

    store.transaction { store["template-#{template['id']}"] = template.dup }
  end
end

.initObject



58
59
60
61
62
63
64
65
# File 'lib/gov_fake_notify.rb', line 58

def self.init
  Config.instance # Pre load
  FileUtils.mkdir_p GovFakeNotify.config.attachments_path
  FileUtils.mkdir_p File.dirname(GovFakeNotify.config.database_file)
  GovFakeNotify.configure_mail
  GovFakeNotify.configure_templates
  GovFakeNotify.configure_api_keys
end

.reset!Object



67
68
69
# File 'lib/gov_fake_notify.rb', line 67

def self.reset!
  Store.clear_messages!
end