Class: ViewComponent::Compiler
- Inherits:
-
Object
- Object
- ViewComponent::Compiler
- Defined in:
- lib/view_component/compiler.rb
Instance Method Summary collapse
- #compile(raise_errors: false, force: false) ⇒ Object
- #compiled? ⇒ Boolean
-
#initialize(component) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(component) ⇒ Compiler
Returns a new instance of Compiler.
13 14 15 16 |
# File 'lib/view_component/compiler.rb', line 13 def initialize(component) @component = component @lock = Mutex.new end |
Instance Method Details
#compile(raise_errors: false, force: false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/view_component/compiler.rb', line 22 def compile(raise_errors: false, force: false) return if compiled? && !force return if @component == ViewComponent::Base @lock.synchronize do # this check is duplicated so that concurrent compile calls can still # early exit return if compiled? && !force gather_templates if self.class.development_mode && @templates.any?(&:requires_compiled_superclass?) @component.superclass.compile(raise_errors: raise_errors) end if template_errors.present? raise TemplateError.new(template_errors) if raise_errors # this return is load bearing, and prevents the component from being considered "compiled?" return false end if raise_errors @component.validate_initialization_parameters! @component.validate_collection_parameter! end define_render_template_for @component.register_default_slots @component.build_i18n_backend CompileCache.register(@component) end end |
#compiled? ⇒ Boolean
18 19 20 |
# File 'lib/view_component/compiler.rb', line 18 def compiled? CompileCache.compiled?(@component) end |