module Erector::ConditionalClasses

Constants

VERSION

Public Instance Methods

method_missing_with_conditionals(method_name, *args, &block) click to toggle source
# 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