Module: Reaction::HasTypes::ClassMethods

Defined in:
lib/reaction/has_types.rb

Instance Method Summary collapse

Instance Method Details

#class_for_type(type) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/reaction/has_types.rb', line 18

def class_for_type(type)
  return type if type.is_a?(Class)
  name = type.to_s.split('_').map(&:capitalize).join
  const_get("#{name}Type")
rescue NameError
  nil
end

#set_type(name, type) ⇒ Object



12
13
14
15
16
# File 'lib/reaction/has_types.rb', line 12

def set_type(name, type)
  type ||= Type
  klass = class_for_type(type)
  types[name.to_sym] = klass.new(name)
end

#typesObject



8
9
10
# File 'lib/reaction/has_types.rb', line 8

def types
  @types ||= {}
end