Class: ViewComponent::ScopedStyles::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/view_component/scoped_styles/railtie.rb

Class Method Summary collapse

Class Method Details

.component_pathObject



24
25
26
27
28
29
30
# File 'lib/view_component/scoped_styles/railtie.rb', line 24

def component_path
  Rails.root.join(
    ViewComponent::ScopedStyles.configuration.components_path,
    "**",
    "*.rb"
  )
end

.load_and_register_componentsObject



32
33
34
35
36
# File 'lib/view_component/scoped_styles/railtie.rb', line 32

def load_and_register_components
  Dir[component_path].each { require_dependency _1 }

  register_components
end

.register_componentsObject



38
39
40
41
42
43
# File 'lib/view_component/scoped_styles/railtie.rb', line 38

def register_components
  ObjectSpace
    .each_object(Class)
    .select { _1.ancestors.include?(ViewComponent::ScopedStyles) }
    .each(&:register_styles)
end