class ApiBlueprint::Runner
Public Instance Methods
method_missing(name, *args, &block)
click to toggle source
# File lib/api-blueprint/runner.rb, line 27 def method_missing(name, *args, &block) if stored_method = registry[name].presence run stored_method[:blueprint].call(*args), stored_method[:cache] else raise NoMethodError, "#{name} is not defined in the ApiBlueprint::Runner registry" end end
register(name, blueprint, cache_options = {})
click to toggle source
# File lib/api-blueprint/runner.rb, line 23 def register(name, blueprint, cache_options = {}) registry[name] = { blueprint: blueprint, cache: cache_options } end
run(item, cache_options = {})
click to toggle source
# File lib/api-blueprint/runner.rb, line 9 def run(item, cache_options = {}) if item.is_a?(Blueprint) run_blueprint item, cache_options elsif item.is_a?(Collection) run_collection item, cache_options else raise ArgumentError, "expected a blueprint or blueprint collection, got #{item.class}" end end
runner_options()
click to toggle source
# File lib/api-blueprint/runner.rb, line 19 def runner_options { headers: headers, cache: cache } end
Private Instance Methods
run_blueprint(blueprint, cache_options)
click to toggle source
# File lib/api-blueprint/runner.rb, line 37 def run_blueprint(blueprint, cache_options) request_options = blueprint.all_request_options(runner_options) if cache.present? cache_key = cache.generate_cache_key blueprint.creates, request_options return cache.read cache_key if cache.exist? cache_key end blueprint.run(runner_options, self).tap do |result| if cache.present? cache_key = cache.generate_cache_key blueprint.creates, request_options cache.write cache_key, result, cache_options end end end
run_collection(collection, cache_options)
click to toggle source
# File lib/api-blueprint/runner.rb, line 53 def run_collection(collection, cache_options) args = {} collection.blueprints.each do |name, blueprint| args[name] = run_blueprint blueprint, cache_options end collection.create args end