Class: Rbexy::ComponentProviders::ViewComponentProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/rbexy/component_providers/view_component_provider.rb

Instance Method Summary collapse

Instance Method Details

#find(name) ⇒ Object



13
14
15
16
17
18
# File 'lib/rbexy/component_providers/view_component_provider.rb', line 13

def find(name)
  ActiveSupport::Inflector.constantize("#{name}Component")
rescue NameError => e
  raise e unless e.message =~ /wrong constant name/ || e.message =~ /uninitialized constant/
  nil
end

#match?(name) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/rbexy/component_providers/view_component_provider.rb', line 4

def match?(name)
  name =~ /^[A-Z]/ && find(name) != nil
end

#render(context, name, **attrs, &block) ⇒ Object



8
9
10
11
# File 'lib/rbexy/component_providers/view_component_provider.rb', line 8

def render(context, name, **attrs, &block)
  props = attrs.transform_keys { |k| ActiveSupport::Inflector.underscore(k.to_s).to_sym }
  find(name).new(**props).render_in(context, &block)
end