Class: Phlex::Rails::Template::Configurator
- Inherits:
-
Object
- Object
- Phlex::Rails::Template::Configurator
- Defined in:
- lib/phlex/rails/template.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #assign_variables ⇒ Object
- #build(component_class) ⇒ Object
- #component_class ⇒ Object
- #create_component(component_class) ⇒ Object
-
#initialize(view_context) ⇒ Configurator
constructor
A new instance of Configurator.
Constructor Details
#initialize(view_context) ⇒ Configurator
Returns a new instance of Configurator.
17 18 19 |
# File 'lib/phlex/rails/template.rb', line 17 def initialize(view_context) @view_context = view_context end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
15 16 17 |
# File 'lib/phlex/rails/template.rb', line 15 def component @component end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
15 16 17 |
# File 'lib/phlex/rails/template.rb', line 15 def view_context @view_context end |
Instance Method Details
#assign_variables ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/phlex/rails/template.rb', line 29 def assign_variables assigns = view_context.respond_to?(:view_assigns) ? view_context.view_assigns : view_context.assigns assigns.each do |key, value| ivar = :"@#{key}" if component.instance_variable_defined?(ivar) raise ArgumentError, "Refusing to overwrite #{ivar} on #{component.class}. " \ "It was already set by the component before assigns were applied." end component.instance_variable_set(ivar, value) end end |
#build(component_class) ⇒ Object
42 43 44 45 46 |
# File 'lib/phlex/rails/template.rb', line 42 def build(component_class) @component = component_class.new assign_variables component end |
#component_class ⇒ Object
21 22 23 |
# File 'lib/phlex/rails/template.rb', line 21 def component_class ::Views::Base end |
#create_component(component_class) ⇒ Object
25 26 27 |
# File 'lib/phlex/rails/template.rb', line 25 def create_component(component_class) component_class.new end |