Module: PassionView::Delegatable

Extended by:
ActiveSupport::Concern
Defined in:
lib/passion_view/delegatable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/passion_view/delegatable.rb', line 15

def method_missing(m, *args, &block)
  self.class.prefixes.each do |prefix, method_names|
    next unless m.to_s.start_with?(prefix)

    last_m = m.to_s.gsub(prefix, '').to_sym
    return method_names.inject(resource) do |result, method|
      break if result.nil?

      result.send method
    end&.send(last_m)
  end

  return resource.send(m, *args, &block) if resource.respond_to?(m)

  super
end

Instance Method Details

#respond_to_missing?(m, _) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/passion_view/delegatable.rb', line 32

def respond_to_missing?(m, _)
  resource.respond_to?(m)
end