class Komponent::ComponentPathResolver

Public Instance Methods

resolve(component_name) click to toggle source
# File lib/komponent/component_path_resolver.rb, line 5
def resolve(component_name)
  root_path = component_paths.find do |path|
    path_has_component?(path, component_name)
  end

  if root_path.nil?
    raise ComponentPathResolver::MissingComponentError.new(
      component_name,
      component_paths,
    )
  end

  root_path.join(*component_name)
end

Protected Instance Methods

app_configuration() click to toggle source
# File lib/komponent/component_path_resolver.rb, line 40
def app_configuration
  Rails.application.config
end
component_paths() click to toggle source
# File lib/komponent/component_path_resolver.rb, line 30
def component_paths
  komponent_configuration.component_paths.map do |path|
    Pathname.new(path)
  end
end
komponent_configuration() click to toggle source
# File lib/komponent/component_path_resolver.rb, line 36
def komponent_configuration
  app_configuration.komponent
end
path_has_component?(path, component_name) click to toggle source
# File lib/komponent/component_path_resolver.rb, line 22
def path_has_component?(path, component_name)
  file_name = path.join(*[
    component_name,
    "#{component_name.split("/").join("_")}_component.rb",
  ])
  File.exist?(file_name)
end