Class: EasyAdmin::Layouts::LayoutContext::CleanRoom

Inherits:
BasicObject
Defined in:
lib/easy_admin/layouts/layout_context.rb

Overview

Clean room for safe evaluation

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ CleanRoom

Returns a new instance of CleanRoom.



121
122
123
# File 'lib/easy_admin/layouts/layout_context.rb', line 121

def initialize(context)
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Allow safe navigation and HTML helpers



171
172
173
174
175
176
177
178
179
180
# File 'lib/easy_admin/layouts/layout_context.rb', line 171

def method_missing(method, *args, &block)
  if [:record, :current_user, :resource_class].include?(method)
    @context.public_send(method)
  elsif @context.view_context && @context.view_context.respond_to?(method)
    # Allow HTML helper methods from view context
    @context.view_context.send(method, *args, &block)
  else
    ::Kernel.raise ::NoMethodError, "undefined method `#{method}' in layout context"
  end
end

Instance Method Details

#can?(action, subject = nil) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/easy_admin/layouts/layout_context.rb', line 145

def can?(action, subject = nil)
  @context.can?(action, subject)
end

#current_userObject



129
130
131
# File 'lib/easy_admin/layouts/layout_context.rb', line 129

def current_user
  @context.current_user
end

#formObject



141
142
143
# File 'lib/easy_admin/layouts/layout_context.rb', line 141

def form
  @context.form
end

#form_builderObject



137
138
139
# File 'lib/easy_admin/layouts/layout_context.rb', line 137

def form_builder
  @context.form_builder
end

#form_context?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/easy_admin/layouts/layout_context.rb', line 149

def form_context?
  @context.form_context?
end

#get(key) ⇒ Object



157
158
159
# File 'lib/easy_admin/layouts/layout_context.rb', line 157

def get(key)
  @context.get(key)
end

#has?(key) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/easy_admin/layouts/layout_context.rb', line 161

def has?(key)
  @context.has?(key)
end

#recordObject



125
126
127
# File 'lib/easy_admin/layouts/layout_context.rb', line 125

def record
  @context.record
end

#render(component) ⇒ Object

Allow render method for components



166
167
168
# File 'lib/easy_admin/layouts/layout_context.rb', line 166

def render(component)
  component
end

#resource_classObject



133
134
135
# File 'lib/easy_admin/layouts/layout_context.rb', line 133

def resource_class
  @context.resource_class
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


182
183
184
185
# File 'lib/easy_admin/layouts/layout_context.rb', line 182

def respond_to_missing?(method, include_private = false)
  [:record, :current_user, :resource_class, :form_builder, :form, :can?, :form_context?, :show_context?, :get, :has?, :render].include?(method) ||
  (@context.view_context && @context.view_context.respond_to?(method))
end

#show_context?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/easy_admin/layouts/layout_context.rb', line 153

def show_context?
  @context.show_context?
end