Class: ActionComponent::Base

Inherits:
Object
  • Object
show all
Includes:
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

Constructor Details

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

Returns a new instance of Base.



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

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)



40
41
42
43
44
45
46
# File 'lib/action_component/base.rb', line 40

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



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

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

Instance Method Details

#loadObject



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

def load
end

#viewObject



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

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