Class: TypedEAV::Field::Integer
- Inherits:
-
RangeBounded
- Object
- ActiveRecord::Base
- ApplicationRecord
- Base
- RangeBounded
- TypedEAV::Field::Integer
- Defined in:
- app/models/typed_eav/field/integer.rb
Overview
Integer-typed field with optional min/max guards. Declares its own ‘integer_value` storage and `:min`/`:max` `store_accessor`; the `validate :max, comparison:` macro guards against inverted bounds at field-save. `validate_range` is inherited from `Field::RangeBounded`.
Constant Summary
Constants inherited from Base
Constants included from TypedStorage
TypedStorage::DEFAULT_OPERATORS_BY_COLUMN, TypedStorage::FALLBACK_OPERATORS
Instance Method Summary collapse
Methods inherited from Base
#allowed_option_values, #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?
Methods included from TypedStorage
#after_snapshot, #apply_default, #before_snapshot, #read_value, #value_changed?, #write_value
Instance Method Details
#cast(raw) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/typed_eav/field/integer.rb', line 17 def cast(raw) return [nil, false] if raw.nil? str = raw.to_s.strip return [nil, false] if str.empty? bd = BigDecimal(str, exception: false) return [nil, true] if bd.nil? return [nil, true] if bd.frac != 0 [bd.to_i, false] end |
#validate_typed_value(record, val) ⇒ Object
30 31 32 |
# File 'app/models/typed_eav/field/integer.rb', line 30 def validate_typed_value(record, val) validate_range(record, val) end |