Sha256: b8c424ee53e7723214f98f3911e6d0cf0e350ddea4ba512aaa5857e9b823c8cd

Contents?: true

Size: 637 Bytes

Versions: 5

Compression:

Stored size: 637 Bytes

Contents

module EditableComponents
  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.type_name
      'string'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
editable_components-0.1.6 app/models/editable_components/item_string.rb
editable_components-0.1.4 app/models/editable_components/item_string.rb
editable_components-0.1.3 app/models/editable_components/item_string.rb
editable_components-0.1.2 app/models/editable_components/item_string.rb
editable_components-0.1.0 app/models/editable_components/item_string.rb