Sha256: 607385c0ea2510c72da30d063fd1fd21c72381fa0ac46ffb306b81f787ec474e

Contents?: true

Size: 788 Bytes

Versions: 6

Compression:

Stored size: 788 Bytes

Contents

module SimpleForm
  module Components
    # Needs to be enabled in order to do automatic lookups.
    module Pattern
      def pattern
        input_html_options[:pattern] ||= pattern_source
        nil
      end

      private

      def pattern_source
        pattern = options[:pattern]
        if pattern.is_a?(String)
          pattern
        elsif (pattern_validator = find_pattern_validator) && (with = pattern_validator.options[:with])
          evaluate_format_validator_option(with).source
        end
      end

      def find_pattern_validator
        find_validator(:format)
      end

      def evaluate_format_validator_option(option)
        if option.respond_to?(:call)
          option.call(object)
        else
          option
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
simple_form-3.0.4 lib/simple_form/components/pattern.rb
simple_form-3.0.3 lib/simple_form/components/pattern.rb
simple_form-3.0.2 lib/simple_form/components/pattern.rb
simple_form-3.0.1 lib/simple_form/components/pattern.rb
simple_form-3.0.0 lib/simple_form/components/pattern.rb
simple_form-3.0.0.rc lib/simple_form/components/pattern.rb