class Quby::Questionnaires::Repos::BundleDiskRepo
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/quby/questionnaires/repos/bundle_disk_repo.rb, line 12 def initialize(path) @path = path @questionnaire_cache = {} end
Public Instance Methods
exists?(key)
click to toggle source
# File lib/quby/questionnaires/repos/bundle_disk_repo.rb, line 30 def exists?(key) questionnaire_path = questionnaire_path(key) File.exist?(questionnaire_path) end
find(key)
click to toggle source
# File lib/quby/questionnaires/repos/bundle_disk_repo.rb, line 23 def find(key) fail(QuestionnaireNotFound, key) unless exists?(key) json = read(key) timestamp = Time.zone.parse(json["last_update"]) Entities::Definition.new(key: key, path: questionnaire_path(key), json: json, timestamp: timestamp) end
keys()
click to toggle source
# File lib/quby/questionnaires/repos/bundle_disk_repo.rb, line 17 def keys Dir[File.join(path, "*.rb")].map do |filename| File.basename(filename, '.rb') end end
timestamp(key)
click to toggle source
# File lib/quby/questionnaires/repos/bundle_disk_repo.rb, line 35 def timestamp(key) Time.zone.parse(read(key)["last_update"]) end
Private Instance Methods
questionnaire_path(key)
click to toggle source
# File lib/quby/questionnaires/repos/bundle_disk_repo.rb, line 45 def questionnaire_path(key) File.join(path,key, "quby-frontend-v1.json") end
read(key)
click to toggle source
# File lib/quby/questionnaires/repos/bundle_disk_repo.rb, line 41 def read(key) JSON.parse(File.read(questionnaire_path(key))) end