Class: ActionComponent::Base

Inherits:
Object
  • Object
show all
Includes:
Callbacks, Constraints, Elements
Defined in:
lib/action_component/base.rb

Constant Summary

Constants included from Elements

Elements::ELEMENTS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

prepended

Constructor Details

#initialize(view, opts = {}) ⇒ Base

Returns a new instance of Base.



22
23
24
25
26
27
28
29
30
# File 'lib/action_component/base.rb', line 22

def initialize(view, opts = {})
  check_constraints!(opts)

  opts.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  @_view = view
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



45
46
47
48
49
50
51
# File 'lib/action_component/base.rb', line 45

def method_missing(method, *args, &block)
  if @_view.respond_to?(method)
    @_view.send(method, *args, &block)
  else
    super
  end
end

Class Method Details

.render(view, opts = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/action_component/base.rb', line 15

def self.render(view, opts = {})
  component = new(view, opts)
  component.load
  component.render_view
  nil
end

Instance Method Details

#loadObject



32
33
# File 'lib/action_component/base.rb', line 32

def load
end

#render_viewObject



39
40
41
# File 'lib/action_component/base.rb', line 39

def render_view
  view
end

#viewObject



35
36
37
# File 'lib/action_component/base.rb', line 35

def view
  raise ActionComponent::ViewMissingError, "#{self.class.name} must define a view method to be a valid component"
end