Sha256: acd5372f8179382c748690bbcfc4bf95649124ff402193ff79f96aa42189d028

Contents?: true

Size: 697 Bytes

Versions: 6

Compression:

Stored size: 697 Bytes

Contents

module ContentsCore
  class ItemString < Item
    alias_attribute :data, :data_string

    validate :on_validate

    def init
      self.data = self.name.gsub( /-/, ' ' ).humanize
      self
    end

    def on_validate
      if self.block.validations[self.name]
        if self.block.validations[self.name] == 'required'
          self.errors.add( :base, "#{self.name} is required" ) if self.data_string.blank?
        end
      end
    end

    def update_data( value )
      self.data = ActionController::Base.helpers.sanitize( value, tags: [] )
      self.save
    end

    def self.permitted_attributes
      [ :data_string ]
    end

    def self.type_name
      'string'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contents_core-0.2.5 app/models/contents_core/item_string.rb
contents_core-0.2.4 app/models/contents_core/item_string.rb
contents_core-0.2.2 app/models/contents_core/item_string.rb
contents_core-0.2.0 app/models/contents_core/item_string.rb
contents_core-0.1.9 app/models/contents_core/item_string.rb
contents_core-0.1.8 app/models/contents_core/item_string.rb