Class: Screengem::Factories::QuestionFactory

Inherits:
BasicObject
Includes:
Singleton
Defined in:
lib/screengem/factories/question_factory.rb

Overview

Knows how to create a Question from a question name.

Defined Under Namespace

Classes: QuestionError

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(question_name, *args) ⇒ Object

rubocop:disable Style/MethodMissingSuper



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/screengem/factories/question_factory.rb', line 9

def method_missing(question_name, *args) # rubocop:disable Style/MethodMissingSuper
  question_class_name = "#{question_name}_question".camelize
  question_class = "#{question_scope}::#{question_class_name}".constantize

  question_class.new(*args)
rescue => e
  QuestionError.new("    Unable to create question: '\#{question_class_name}'.\n      Details: \#{e.message}\n  MSG\nend\n")

Instance Method Details

#respond_to_missing?(_question_name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/screengem/factories/question_factory.rb', line 21

def respond_to_missing?(_question_name, *)
  true
end