Class: Quby::Questionnaires::API
- Inherits:
-
Object
- Object
- Quby::Questionnaires::API
- Defined in:
- lib/quby/questionnaires/api.rb
Instance Method Summary collapse
- #all ⇒ Object
- #exists?(questionnaire_key) ⇒ Boolean
- #find(key) ⇒ Object
-
#initialize(questionnaire_repo:) ⇒ API
constructor
A new instance of API.
- #validate(key, sourcecode) ⇒ Object
Constructor Details
#initialize(questionnaire_repo:) ⇒ API
Returns a new instance of API.
6 7 8 9 |
# File 'lib/quby/questionnaires/api.rb', line 6 def initialize(questionnaire_repo:) @repo = questionnaire_repo @cache = {} end |
Instance Method Details
#all ⇒ Object
28 29 30 |
# File 'lib/quby/questionnaires/api.rb', line 28 def all @repo.keys.map { |key| find(key) } end |
#exists?(questionnaire_key) ⇒ Boolean
24 25 26 |
# File 'lib/quby/questionnaires/api.rb', line 24 def exists?(questionnaire_key) @repo.exists? questionnaire_key end |
#find(key) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/quby/questionnaires/api.rb', line 11 def find(key) if fresh?(key) # print "HIT:#{key} " return @cache[key][:questionnaire] # else # print "MISS:#{key} " end definition = @repo.find key @cache[key] = {questionnaire: build_from_definition(definition), timestamp: definition.} @cache[key][:questionnaire] end |
#validate(key, sourcecode) ⇒ Object
32 33 34 35 36 |
# File 'lib/quby/questionnaires/api.rb', line 32 def validate(key, sourcecode) definition = Entities::Definition.new(key: key, sourcecode: sourcecode, path: "validating '#{key}'") definition.valid? definition end |