class Cedar::ComponentWarden

A ComponentWarden is responsible for locating potential components given a snake_case representation of that component.

If a component exists, the warden is also responsible for calling the correct instantiation method, depending if the component is a collection or not

Public Class Methods

new(component, string) click to toggle source
# File lib/cedar/component_warden.rb, line 11
def initialize(component, string)
  @component = component
  @raw_input = string

  @collection = @raw_input.end_with? "_collection"
  @input = @raw_input.to_s.chomp("_collection")
end

Public Instance Methods

collection?() click to toggle source
# File lib/cedar/component_warden.rb, line 19
def collection?
  @collection
end
component_class() click to toggle source
# File lib/cedar/component_warden.rb, line 27
def component_class
  @component_class ||= @component.class.find_component(component_name)
end
component_name() click to toggle source
# File lib/cedar/component_warden.rb, line 23
def component_name
  "#{@input}_component".camelize
end
exists?() click to toggle source
# File lib/cedar/component_warden.rb, line 31
def exists?
  component_class.present?
end
new(*args, &block) click to toggle source
# File lib/cedar/component_warden.rb, line 35
def new(*args, &block)
  return nil unless exists?

  if collection?
    component_class.with_collection(*args, &block)
  else
    component_class.new(*args, &block)
  end
end