Sha256: 810a58ba199faf87c4a49ab6e1c18f2f1419e4eae8071a436a05c756aababb7d

Contents?: true

Size: 803 Bytes

Versions: 13

Compression:

Stored size: 803 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(ActiveModel::Validations::FormatValidator)
      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

13 entries across 13 versions & 3 rubygems

Version Path
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.4/lib/simple_form/components/pattern.rb
simple_form-2.0.4 lib/simple_form/components/pattern.rb
simple_form-2.0.3 lib/simple_form/components/pattern.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/lib/simple_form/components/pattern.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/lib/simple_form/components/pattern.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/lib/simple_form/components/pattern.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/lib/simple_form/components/pattern.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/simple_form-2.0.2/lib/simple_form/components/pattern.rb
simple_form-2.0.2 lib/simple_form/components/pattern.rb
ehoch_simple_form-2.0.2.dev lib/simple_form/components/pattern.rb
simple_form-2.0.1 lib/simple_form/components/pattern.rb
simple_form-2.0.0 lib/simple_form/components/pattern.rb
simple_form-2.0.0.rc lib/simple_form/components/pattern.rb