Class: ApiBlueprint::Runner

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/api-blueprint/runner.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



27
28
29
30
31
32
33
# 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

Instance Method Details

#register(name, blueprint, cache_options = {}) ⇒ Object



23
24
25
# 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 = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# 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_optionsObject



19
20
21
# File 'lib/api-blueprint/runner.rb', line 19

def runner_options
  { headers: headers, cache: cache }
end