lib/ruby_reportable/report.rb
def valid?(options = {})
      options = {:input => {}}.merge(options)
      errors = []

      # initial sandbox
      sandbox = _source(options)

      # add in inputs
      sandbox[:inputs] = options[:input]

      validity = @filters.map do |filter_name, filter|

        # find input for given filter
        sandbox[:input] = options[:input][filter[:key]] if options[:input].is_a?(Hash)

        filter_validity = filter[:valid].nil? || sandbox.instance_eval(&filter[:valid])

        if filter_validity == false
          # Ignore an empty filter unless it's required
          if !sandbox[:input].to_s.blank?
            errors << "#{filter_name} is invalid."
            false
          else
            if sandbox[:input].to_s.blank? && !filter[:require].blank?
              errors << "#{filter_name} is required."
              false
            else
              true
            end
          end
        elsif filter_validity == true
          if sandbox[:input].to_s.blank? && !filter[:require].blank?
            errors << "#{filter_name} is required."
            false
          else
            true
          end
        elsif !filter_validity.nil? && !filter_validity[:status].nil? && filter_validity[:status] == false
          # Ignore an empty filter unless it's required or the error is forced.
          if !sandbox[:input].to_s.blank? || filter_validity[:force_error] == true
            errors << filter_validity[:errors]
            false
          else
            if sandbox[:input].to_s.blank? && !filter[:require].blank?
              errors << "#{filter_name} is required."
              false
            else
              true
            end
          end
        end
      end

      return {:status => !validity.include?(false), :errors => errors}

    end
def valid?(options = {})
      options = {:input => {}}.merge(options)
      errors = []

      # initial sandbox
      sandbox = _source(options)

      # add in inputs
      sandbox[:inputs] = options[:input]

      validity = @filters.map do |filter_name, filter|

        # find input for given filter
        sandbox[:input] = options[:input][filter[:key]] if options[:input].is_a?(Hash)

        filter_validity = filter[:valid].nil? || sandbox.instance_eval(&filter[:valid])

        if filter_validity == false
          # Ignore an empty filter unless it's required
          if !sandbox[:input].to_s.blank?
            errors << "#{filter_name} is invalid."
            false
          else
            if sandbox[:input].to_s.blank? && !filter[:require].blank?
              errors << "#{filter_name} is required."
              false
            else
              true
            end
          end
        elsif filter_validity == true
          if sandbox[:input].to_s.blank? && !filter[:require].blank?
            errors << "#{filter_name} is required."
            false
          else
            true
          end
        elsif !filter_validity.nil? && !filter_validity[:status].nil? && filter_validity[:status] == false
          # Ignore an empty filter unless it's required or the error is forced.
          if !sandbox[:input].to_s.blank? || filter_validity[:force_error] == true
            errors << filter_validity[:errors]
            false
          else
            if sandbox[:input].to_s.blank? && !filter[:require].blank?
              errors << "#{filter_name} is required."
              false
            else
              true
            end
          end
        end
      end

      return {:status => !validity.include?(false), :errors => errors}

    end
end def run