Class: ActionComponent::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/action_component/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.



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

def initialize(view, 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)



55
56
57
58
59
60
61
# File 'lib/action_component/base.rb', line 55

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

Class Method Details

.define_tags(*element_names) ⇒ Object



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

def self.define_tags(*element_names)
  element_names.each do |element_name|
    define_method(element_name) do |*args, &block|
      element(element_name, *args, &block)
    end

    private element_name
  end
end

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



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

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

Instance Method Details

#loadObject



46
47
# File 'lib/action_component/base.rb', line 46

def load
end

#viewObject



49
50
51
# File 'lib/action_component/base.rb', line 49

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