Module: Ditty::Components::Base::ClassMethods

Included in:
Ditty
Defined in:
lib/ditty.rb

Instance Method Summary collapse

Instance Method Details

#component(component, *args, &block) ⇒ Object

Load a new component into the current class. A component can be a module which is used directly, or a symbol represented a registered component which will be required and then used. Returns nil.

Component.component ComponentModule
Component.component :csrf

Raises:



147
148
149
150
151
152
153
154
155
156
# File 'lib/ditty.rb', line 147

def component(component, *args, &block)
  raise ComponentError, 'Cannot add a component to a frozen Component class' if frozen?

  component = Components.load_component(component) if component.is_a?(Symbol)
  include(component::InstanceMethods) if defined?(component::InstanceMethods)
  extend(component::ClassMethods) if defined?(component::ClassMethods)

  component.configure(self, *args, &block) if component.respond_to?(:configure)
  nil
end