Sha256: 4b6766066287d240a2000f19e06fcc30e7827669a9e73e4dad66870f0e7d68d2

Contents?: true

Size: 769 Bytes

Versions: 9

Compression:

Stored size: 769 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
          evaluate_format_validator_option(pattern_validator.options[: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

9 entries across 9 versions & 2 rubygems

Version Path
simple_form-2.1.3 lib/simple_form/components/pattern.rb
simple_form-2.1.2 lib/simple_form/components/pattern.rb
simple_form-2.1.1 lib/simple_form/components/pattern.rb
simple_form_awesome-2.5.0 lib/simple_form/components/pattern.rb
simple_form_awesome-2.4.0 lib/simple_form/components/pattern.rb
simple_form_awesome-2.3.0 lib/simple_form/components/pattern.rb
simple_form_awesome-2.2.0 lib/simple_form/components/pattern.rb
simple_form-2.1.0 lib/simple_form/components/pattern.rb
simple_form-3.0.0.beta1 lib/simple_form/components/pattern.rb