Class: Ilex::ComponentWarden
- Inherits:
-
Object
- Object
- Ilex::ComponentWarden
- Defined in:
- lib/ilex/component_warden.rb
Overview
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
Instance Method Summary collapse
- #collection? ⇒ Boolean
- #component_class ⇒ Object
- #component_name ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(component, string) ⇒ ComponentWarden
constructor
A new instance of ComponentWarden.
- #nested? ⇒ Boolean
- #new(*args, &block) ⇒ Object
Constructor Details
#initialize(component, string) ⇒ ComponentWarden
Returns a new instance of ComponentWarden.
11 12 13 14 15 16 17 18 19 |
# File 'lib/ilex/component_warden.rb', line 11 def initialize(component, string) @component = component @input = string.to_s @collection = @input.end_with? "_collection" @nested = @input.include? "__" process_input!(@input) end |
Instance Method Details
#collection? ⇒ Boolean
21 22 23 |
# File 'lib/ilex/component_warden.rb', line 21 def collection? @collection end |
#component_class ⇒ Object
33 34 35 |
# File 'lib/ilex/component_warden.rb', line 33 def component_class @component_class ||= @component.class.find_component(component_name, @base_module) end |
#component_name ⇒ Object
29 30 31 |
# File 'lib/ilex/component_warden.rb', line 29 def component_name "#{@input}_component".camelize end |
#exists? ⇒ Boolean
37 38 39 |
# File 'lib/ilex/component_warden.rb', line 37 def exists? component_class.present? end |
#nested? ⇒ Boolean
25 26 27 |
# File 'lib/ilex/component_warden.rb', line 25 def nested? @nested end |
#new(*args, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/ilex/component_warden.rb', line 41 def new(*args, &block) return nil unless exists? if collection? component_class.with_collection(*args) else component_class.new(*args) end end |