Sha256: 917cf9e13ccb5357773bf1bf2a2e16212c08f551039184bc7e0c9ee969cc5d7e

Contents?: true

Size: 1021 Bytes

Versions: 36

Compression:

Stored size: 1021 Bytes

Contents

require_relative 'utils/associations'

module CmAdmin
  module Models
    class Field
      include Utils::Associations

      attr_accessor :field_name, :label, :header, :field_type, :format, :precision, :height,
        :width, :helper_method, :preview, :custom_link, :prefix, :suffix, :tag_class,
        :display_if, :association_name, :association_type, :col_size

      def initialize(field_name, attributes = {})
        @field_name = field_name
        set_default_values
        attributes.each do |key, value|
          self.send("#{key.to_s}=", value)
        end
        self.height = 50 if self.field_type == :image && self.height.nil?
        self.width = 50 if self.field_type == :image && self.width.nil?
        self.display_if = lambda { |arg| return true } if self.display_if.nil?

        validation_for_association
      end

      def set_default_values
        self.precision = 2
        self.tag_class = {}
        self.col_size = nil
        self.field_type = :string
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
cm-admin-1.5.1 lib/cm_admin/models/field.rb
cm-admin-1.5.0 lib/cm_admin/models/field.rb
cm-admin-1.4.9 lib/cm_admin/models/field.rb
cm-admin-1.4.8 lib/cm_admin/models/field.rb
cm-admin-1.4.7 lib/cm_admin/models/field.rb
cm-admin-1.4.6 lib/cm_admin/models/field.rb
cm-admin-1.4.5 lib/cm_admin/models/field.rb
cm-admin-1.4.4 lib/cm_admin/models/field.rb
cm-admin-1.4.3 lib/cm_admin/models/field.rb
cm-admin-1.4.2 lib/cm_admin/models/field.rb
cm-admin-1.4.1 lib/cm_admin/models/field.rb
cm-admin-1.4.0 lib/cm_admin/models/field.rb
cm-admin-1.3.9 lib/cm_admin/models/field.rb
cm-admin-1.3.8 lib/cm_admin/models/field.rb
cm-admin-1.3.7 lib/cm_admin/models/field.rb
cm-admin-1.3.6 lib/cm_admin/models/field.rb