Class: TypedEAV::Field::Url
- Inherits:
-
Base
show all
- Defined in:
- app/models/typed_eav/field/url.rb
Constant Summary
collapse
- URL_FORMAT =
/\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/
Constants inherited
from Base
Base::RESERVED_NAMES
ColumnMapping::DEFAULT_OPERATORS_BY_COLUMN, ColumnMapping::FALLBACK_OPERATORS
Instance Method Summary
collapse
Methods inherited from Base
#allowed_option_values, #apply_default_to, #array_field?, #backfill_default!, #clear_option_cache!, #default_value, #default_value=, export_schema, #field_type_name, import_schema, #insert_at, #move_higher, #move_lower, #move_to_bottom, #move_to_top, #optionable?, #read_value, #storage_contract, storage_contract_class, #write_value
Instance Method Details
#cast(raw) ⇒ Object
15
16
17
|
# File 'app/models/typed_eav/field/url.rb', line 15
def cast(raw)
[raw&.to_s&.strip, false]
end
|
19
20
21
|
# File 'app/models/typed_eav/field/url.rb', line 19
def url_format_valid?(val)
URL_FORMAT.match?(val)
end
|
#validate_typed_value(record, val) ⇒ Object
23
24
25
26
27
|
# File 'app/models/typed_eav/field/url.rb', line 23
def validate_typed_value(record, val)
validate_length(record, val)
validate_pattern(record, val) if pattern.present?
record.errors.add(:value, "is not a valid URL") unless url_format_valid?(val)
end
|