kalkov/rails4_client_side_validations

View on GitHub
lib/rails4_client_side_validations/active_model/format.rb

Summary

Maintainability
A
55 mins
Test Coverage
module Rails4ClientSideValidations::ActiveModel
  module Format
    def client_side_hash(model, attribute, force = nil)
      options = self.options.dup
      if options[:with].respond_to?(:call)
        if force
          options[:with] = options[:with].call(model)
          build_client_side_hash(model, attribute, options)
        else
          return
        end
      elsif options[:without].respond_to?(:call)
        if force
          options[:without] = options[:without].call(model)
          build_client_side_hash(model, attribute, options)
        else
          return
        end
      else
        super
      end
    end

    private

    def message_type
      :invalid
    end
  end
end