Class: Frails::Component::Abstract

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Callbacks
Defined in:
lib/frails/component/abstract.rb

Direct Known Subclasses

Base, React

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, path, options) ⇒ Abstract

Returns a new instance of Abstract.



8
9
10
11
12
13
14
# File 'lib/frails/component/abstract.rb', line 8

def initialize(view, path, options)
  @view = view
  @path = path
  @options = options

  expand_instance_vars
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

rubocop:disable Lint/ShadowedException, Style/MissingRespondToMissing



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/frails/component/abstract.rb', line 27

def method_missing(method, *args, &block)
  super
rescue NoMethodError, NameError => e
  # the error is not mine, so just releases it as is.
  raise e if e.name != method

  begin
    @view.send method, *args, &block
  rescue NoMethodError => e
    raise e if e.name != method

    raise NoMethodError.new("undefined method `#{method}' for either #{self} or #{@view}",
                            method)
  rescue NameError => e
    raise e if e.name != method

    raise NameError.new("undefined local variable `#{method}' for either #{self} or #{@view}",
                        method)
  end
end

Class Method Details

.after_render(*methods, &block) ⇒ Object



21
22
23
# File 'lib/frails/component/abstract.rb', line 21

def after_render(*methods, &block)
  set_callback :render, :after, *methods, &block
end

.before_render(*methods, &block) ⇒ Object



17
18
19
# File 'lib/frails/component/abstract.rb', line 17

def before_render(*methods, &block)
  set_callback :render, :before, *methods, &block
end