Class: Dry::View::ScopeBuilder Private

Inherits:
Object
  • Object
show all
Extended by:
Core::Cache
Defined in:
lib/dry/view/scope_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Builds scope objects via matching classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace: nil, render_env: nil) ⇒ ScopeBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ScopeBuilder



29
30
31
32
# File 'lib/dry/view/scope_builder.rb', line 29

def initialize(namespace: nil, render_env: nil)
  @namespace = namespace
  @render_env = render_env
end

Instance Attribute Details

#namespaceObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The view’s configured ‘scope_namespace`



19
20
21
# File 'lib/dry/view/scope_builder.rb', line 19

def namespace
  @namespace
end

#render_envRenderEnvironment (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



24
25
26
# File 'lib/dry/view/scope_builder.rb', line 24

def render_env
  @render_env
end

Instance Method Details

#call(name = nil, locals) ⇒ Dry::View::Scope

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new scope using a class matching the name

Parameters:

  • name (Symbol, Class) (defaults to: nil)

    scope name

  • locals (Hash<Symbol, Object>)

    locals hash

Returns:



49
50
51
52
53
54
55
# File 'lib/dry/view/scope_builder.rb', line 49

def call(name = nil, locals) # rubocop:disable Style/OptionalArguments
  scope_class(name).new(
    name: name,
    locals: locals,
    render_env: render_env
  )
end

#for_render_env(render_env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
38
39
# File 'lib/dry/view/scope_builder.rb', line 35

def for_render_env(render_env)
  return self if render_env == self.render_env

  self.class.new(namespace: namespace, render_env: render_env)
end