Class: Quby::Questionnaires::Repos::BundleDiskRepo

Inherits:
Base
  • Object
show all
Defined in:
lib/quby/questionnaires/repos/bundle_disk_repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#all, #create!, #update!

Constructor Details

#initialize(path) ⇒ BundleDiskRepo

Returns a new instance of BundleDiskRepo.



12
13
14
15
# File 'lib/quby/questionnaires/repos/bundle_disk_repo.rb', line 12

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/quby/questionnaires/repos/bundle_disk_repo.rb', line 10

def path
  @path
end

Instance Method Details

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# 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) ⇒ Object



23
24
25
26
27
28
# 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

#keysObject



17
18
19
20
21
# 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) ⇒ Object



35
36
37
# File 'lib/quby/questionnaires/repos/bundle_disk_repo.rb', line 35

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