Module: Roda::RodaPlugins::Components::ClassMethods

Defined in:
lib/roda/plugins/components.rb

Instance Method Summary collapse

Instance Method Details

#component(name, events = [], &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/roda/plugins/components.rb', line 36

def component(name, events = [], &block)
  name                       = name.to_s
  cache[:components][name]   = block
  cache[:events][name]     ||= {}

  events.each do |event|
    if event.is_a? String
      event_array = cache[:events][name][event] ||= []
      event_array << { component: name, call: event }
    elsif event.is_a? Hash
      for_component = event[:for].to_s
      response_to   = event[:respond_to].to_s
      call_with     = event[:with]

      event_array = cache[:events][for_component || name][response_to] ||= []
      event_array << { component: name, call: call_with || response_to }
    end
  end
end

#componentsObject



28
29
30
# File 'lib/roda/plugins/components.rb', line 28

def components
  cache[:components].keys
end

#components_optsObject



24
25
26
# File 'lib/roda/plugins/components.rb', line 24

def components_opts
  opts[:components]
end

#inherited(subclass) ⇒ Object



19
20
21
22
# File 'lib/roda/plugins/components.rb', line 19

def inherited(subclass)
  super
  opts.merge! subclass.opts[:components]
end

#load_component(name) ⇒ Object



32
33
34
# File 'lib/roda/plugins/components.rb', line 32

def load_component name
  cache[:components][name]
end

#load_setup_component(name) ⇒ Object



56
57
58
# File 'lib/roda/plugins/components.rb', line 56

def load_setup_component name
  cache[:components]["_setup_#{name}"]
end

#setup_component(name, &block) ⇒ Object



60
61
62
# File 'lib/roda/plugins/components.rb', line 60

def setup_component(name, &block)
  cache[:components]["_setup_#{name}"] = block
end