Class: Reaction::TypeBuilder
- Inherits:
-
Object
- Object
- Reaction::TypeBuilder
- Defined in:
- lib/reaction/type_builder.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #build(action) ⇒ Object
- #class_for_type(type) ⇒ Object
- #class_for_type!(type) ⇒ Object
-
#initialize(type = RawType, options = {}) ⇒ TypeBuilder
constructor
A new instance of TypeBuilder.
Constructor Details
#initialize(type = RawType, options = {}) ⇒ TypeBuilder
Returns a new instance of TypeBuilder.
6 7 8 9 |
# File 'lib/reaction/type_builder.rb', line 6 def initialize(type = RawType, = {}) @type = class_for_type!(type) @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/reaction/type_builder.rb', line 4 def @options end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/reaction/type_builder.rb', line 3 def type @type end |
Instance Method Details
#build(action) ⇒ Object
11 12 13 |
# File 'lib/reaction/type_builder.rb', line 11 def build(action) type.new(action, ) end |
#class_for_type(type) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/reaction/type_builder.rb', line 15 def class_for_type(type) return type if type.is_a?(Class) name = type.to_s.split('_').map(&:capitalize).join Module.const_get("#{name}Type") rescue NameError nil end |
#class_for_type!(type) ⇒ Object
23 24 25 |
# File 'lib/reaction/type_builder.rb', line 23 def class_for_type!(type) class_for_type(type) or raise ArgumentError.new("Unknown type: #{type}") end |