Sha256: e236534ba92a674ae3300ac00999509e20a1d34e37145b40cc8c3d5c37eb461f

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require 'quby/questionnaires/repos'
require 'quby/questionnaires'

module Quby
  module Questionnaires
    module Repos
      class BundleDiskRepo < Base
        attr_reader :path

        def initialize(path)
          @path = path
          @questionnaire_cache = {}
        end

        def keys
          Dir[File.join(path, "*.rb")].map do |filename|
            File.basename(filename, '.rb')
          end
        end

        def find(key)
          fail(QuestionnaireNotFound, key) unless exists?(key)
          json = read(key)
          timestamp = Time.zone.parse(read(key)["last_update"])
          Entities::Definition.new(key: key, path: questionnaire_path(key), json: json, timestamp: timestamp)
        end

        def exists?(key)
          questionnaire_path = questionnaire_path(key)
          File.exist?(questionnaire_path)
        end

        def timestamp(key)
          Time.zone.parse(read(key)["last_update"])
        end

        private

        def read(key)
          JSON.parse(File.read(questionnaire_path(key)))
        end

        def questionnaire_path(key)
          File.join(path,key, "quby-frontend-v1.json")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
quby-5.0.0.pre4 lib/quby/questionnaires/repos/bundle_disk_repo.rb
quby-5.0.0.pre3 lib/quby/questionnaires/repos/bundle_disk_repo.rb
quby-5.0.0.pre2 lib/quby/questionnaires/repos/bundle_disk_repo.rb
quby-5.0.0.pre1 lib/quby/questionnaires/repos/bundle_disk_repo.rb