Class: Frails::Component::Base

Inherits:
Abstract
  • Object
show all
Defined in:
lib/frails/component/base.rb

Constant Summary collapse

PRIVATE_METHODS =
%i[render method_missing locals to_partial_path].freeze

Instance Method Summary collapse

Methods inherited from Abstract

after_render, before_render, #method_missing

Constructor Details

#initialize(view, path, options) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/frails/component/base.rb', line 6

def initialize(view, path, options)
  super

  @locals = @options.fetch(:locals, @options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Frails::Component::Abstract

Instance Method Details

#localsObject



12
13
14
15
16
17
18
# File 'lib/frails/component/base.rb', line 12

def locals
  hash = {}
  public_methods(false).each do |method|
    hash[method] = send(method) unless PRIVATE_METHODS.include?(method)
  end
  hash.merge @locals
end

#to_partial_pathObject



20
21
22
# File 'lib/frails/component/base.rb', line 20

def to_partial_path
  "#{@path}/index"
end