Module: Erector::ConditionalClasses

Extended by:
ActiveSupport::Concern
Defined in:
lib/erector/conditional_classes.rb,
lib/erector/conditional_classes/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#method_missing_with_conditionals(method_name, *args, &block) ⇒ Object



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

def method_missing_with_conditionals(method_name, *args, &block)
  if args.last.is_a?(Hash) && args.last.has_key?(:if)
    should_render = args.last.delete(:if)
    should_render = should_render.call if should_render.respond_to?(:call)

    unless should_render
      # hacky: we set the block at this level
      # so even if bail out because we shouldn't render the class
      # we still get expected behavior on the final member of a chain
      @inside_renderer = block if block_given?
      _render
      return self
    end
  end

  method_missing_without_conditionals(method_name, *args, &block)
end