Sha256: 1a76a1c08c40cd225fdace31f2a108bf77c73232edc1ce2cff9e4f08cc561d95

Contents?: true

Size: 847 Bytes

Versions: 5

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

require 'mail'
require 'erb'
require 'tilt'
require 'gov_fake_notify/store'

module GovFakeNotify
  # A service used to fetch all templates
  class FetchTemplatesCommand
    attr_reader :errors

    def self.call(params, **kwargs)
      new(params, **kwargs).call
    end

    def initialize(params, store: Store.instance)
      @params = params
      @store = store
      @errors = []
      @results = []
    end

    def call
      @results = store.transaction { store.roots.select { |k| k =~ /^template-/ } }.map do |key|
        store.transaction { store.fetch(key).slice('id', 'name', 'subject') }
      end
      self
    end

    def success?
      errors.empty?
    end

    def to_json
      JSON.pretty_generate(templates: results)
    end

    private

    attr_reader :params, :store, :results
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gov_fake_notify-2.0.0 lib/gov_fake_notify/commands/fetch_templates_command.rb
gov_fake_notify-1.2.0 lib/gov_fake_notify/commands/fetch_templates_command.rb
gov_fake_notify-1.1.3 lib/gov_fake_notify/commands/fetch_templates_command.rb
gov_fake_notify-1.1.2 lib/gov_fake_notify/commands/fetch_templates_command.rb
gov_fake_notify-1.1.1 lib/gov_fake_notify/commands/fetch_templates_command.rb