Class: Quby::Questionnaires::Repos::DiskRepo
- Defined in:
- lib/quby/questionnaires/repos/disk_repo.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #exists?(key) ⇒ Boolean
- #find(key) ⇒ Object
-
#initialize(path) ⇒ DiskRepo
constructor
A new instance of DiskRepo.
- #keys ⇒ Object
- #timestamp(key) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(path) ⇒ DiskRepo
Returns a new instance of DiskRepo.
12 13 14 15 |
# File 'lib/quby/questionnaires/repos/disk_repo.rb', line 12 def initialize(path) @path = path @questionnaire_cache = {} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/quby/questionnaires/repos/disk_repo.rb', line 10 def path @path end |
Instance Method Details
#exists?(key) ⇒ Boolean
31 32 33 34 |
# File 'lib/quby/questionnaires/repos/disk_repo.rb', line 31 def exists?(key) questionnaire_path = questionnaire_path(key) File.exist?(questionnaire_path) end |
#find(key) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/quby/questionnaires/repos/disk_repo.rb', line 23 def find(key) fail(QuestionnaireNotFound, key) unless exists?(key) path = questionnaire_path(key) definition = File.read(path) = (key) entity(key, definition, , path) end |
#keys ⇒ Object
17 18 19 20 21 |
# File 'lib/quby/questionnaires/repos/disk_repo.rb', line 17 def keys Dir[File.join(path, "*.rb")].map do |filename| File.basename(filename, '.rb') end end |
#timestamp(key) ⇒ Object
36 37 38 |
# File 'lib/quby/questionnaires/repos/disk_repo.rb', line 36 def (key) Time.at(File.mtime(questionnaire_path(key)).to_i) end |