Sha256: 17de4d5d961eec6352065532c9381e9ce2f9ffab7196aa81bc799ec1ba1b9593
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
class IntegerFieldType < FieldType attr_accessor :integer validates :integer, presence: true, if: Proc.new { |int| validate_key(:presence) } validates_numericality_of :integer, unless: "integer.nil?" validate :less_than, if: Proc.new { |int| validate_key(:max) } validate :greater_than, if: Proc.new { |int| validate_key(:min) } def data=(data_hash) @integer = data_hash.deep_symbolize_keys[:integer] end def field_item_as_indexed_json_for_field_type(field_item, options = {}) json = {} json[mapping_field_name] = field_item.data['integer'] json end def mapping {name: mapping_field_name, type: :integer} end private def mapping_field_name "#{field_name.parameterize(separator: '_')}_integer" end def validate_key @validations.key? key end def less_than errors.add(:integer, "must be less_than #{@validations[:max]}") if :integer <= @validations[:max] end def greater_than errors.add(:integer, "must be greater_than #{@validations[:min]}") if :integer >= @validations[:min] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cortex-plugins-core-0.12.4 | app/models/integer_field_type.rb |