@@ -457,8 +457,16 @@ def compiler
457
457
# Defaults to `false`.
458
458
459
459
class << self
460
+ # The file path of the component Ruby file.
461
+ #
462
+ # @return [String]
463
+ attr_reader :identifier
464
+
465
+ # @private
466
+ attr_writer :identifier
467
+
460
468
# @private
461
- attr_accessor :source_location , : virtual_path
469
+ attr_accessor :virtual_path
462
470
463
471
# Find sidecar files for the given extensions.
464
472
#
@@ -468,13 +476,13 @@ class << self
468
476
# For example, one might collect sidecar CSS files that need to be compiled.
469
477
# @param extensions [Array<String>] Extensions of which to return matching sidecar files.
470
478
def sidecar_files ( extensions )
471
- return [ ] unless source_location
479
+ return [ ] unless identifier
472
480
473
481
extensions = extensions . join ( "," )
474
482
475
483
# view files in a directory named like the component
476
- directory = File . dirname ( source_location )
477
- filename = File . basename ( source_location , ".rb" )
484
+ directory = File . dirname ( identifier )
485
+ filename = File . basename ( identifier , ".rb" )
478
486
component_name = name . demodulize . underscore
479
487
480
488
# Add support for nested components defined in the same file.
@@ -499,7 +507,7 @@ def sidecar_files(extensions)
499
507
500
508
sidecar_directory_files = Dir [ "#{ directory } /#{ component_name } /#{ filename } .*{#{ extensions } }" ]
501
509
502
- ( sidecar_files - [ source_location ] + sidecar_directory_files + nested_component_files ) . uniq
510
+ ( sidecar_files - [ identifier ] + sidecar_directory_files + nested_component_files ) . uniq
503
511
end
504
512
505
513
# Render a component for each element in a collection ([documentation](/guide/collections)):
@@ -548,11 +556,11 @@ def render_template_for(variant = nil, format = nil)
548
556
# has been re-defined by the consuming application, likely in ApplicationComponent.
549
557
# We use `base_label` method here instead of `label` to avoid cases where the method
550
558
# owner is included in a prefix like `ApplicationComponent.inherited`.
551
- child . source_location = caller_locations ( 1 , 10 ) . reject { |l | l . base_label == "inherited" } [ 0 ] . path
559
+ child . identifier = caller_locations ( 1 , 10 ) . reject { |l | l . base_label == "inherited" } [ 0 ] . path
552
560
553
561
# If Rails application is loaded, removes the first part of the path and the extension.
554
562
if defined? ( Rails ) && Rails . application
555
- child . virtual_path = child . source_location . gsub (
563
+ child . virtual_path = child . identifier . gsub (
556
564
/(.*#{ Regexp . quote ( ViewComponent ::Base . config . view_component_path ) } )|(\. rb)/ , ""
557
565
)
558
566
end
@@ -590,15 +598,6 @@ def compiler
590
598
@__vc_compiler ||= Compiler . new ( self )
591
599
end
592
600
593
- # @private
594
- def identifier
595
- # :nocov:
596
- Kernel . warn ( "WARNING: The #{ self . class } .identifier is undocumented and was meant for internal framework usage only. As it is no longer used by the framework it will be removed in a coming non-breaking ViewComponent release." )
597
-
598
- source_location
599
- # :nocov:
600
- end
601
-
602
601
# Set the parameter name used when rendering elements of a collection ([documentation](/guide/collections)):
603
602
#
604
603
# ```ruby
0 commit comments