Class: ToQuickform::ElementFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/to_quickform/element_factory.rb

Overview

ElementFactory

Class Method Summary collapse

Class Method Details

.create_instance(type, options) ⇒ Object

Passes configuration options to instantiated class



23
24
25
26
# File 'lib/to_quickform/element_factory.rb', line 23

def self.create_instance(type, options)
  constant = ToQuickform::Element.const_get ActiveSupport::Inflector.camelize(type)
  constant.new options
end

.new(element) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
# File 'lib/to_quickform/element_factory.rb', line 17

def self.new(element)
  return create_instance(element["type"], element) if element
  raise ArgumentError, 'must provide element to be instantiated'
end