Class: Coppertone::ClassBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/coppertone/class_builder.rb

Overview

Utility class for building class instances out of a set of registered types (e.g. mechanisms, modifiers)

Instance Method Summary collapse

Instance Method Details

#build(type, attributes) ⇒ Object



13
14
15
16
17
18
# File 'lib/coppertone/class_builder.rb', line 13

def build(type, attributes)
  return nil unless type
  klass = map[type]
  return nil unless klass
  klass.create(attributes)
end

#mapObject



5
6
7
# File 'lib/coppertone/class_builder.rb', line 5

def map
  @map ||= {}
end

#register(type, klass) ⇒ Object



9
10
11
# File 'lib/coppertone/class_builder.rb', line 9

def register(type, klass)
  map[type] = klass
end