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.34 lib/cm_admin/models/field.rb
cm-admin-1.5.33 lib/cm_admin/models/field.rb
cm-admin-1.5.32 lib/cm_admin/models/field.rb
cm-admin-1.5.31 lib/cm_admin/models/field.rb
cm-admin-1.5.30 lib/cm_admin/models/field.rb
cm-admin-1.5.29 lib/cm_admin/models/field.rb
cm-admin-1.5.28 lib/cm_admin/models/field.rb
cm-admin-1.5.10 lib/cm_admin/models/field.rb
cm-admin-1.5.27 lib/cm_admin/models/field.rb
cm-admin-1.5.26 lib/cm_admin/models/field.rb
cm-admin-1.5.25 lib/cm_admin/models/field.rb
cm-admin-1.5.23 lib/cm_admin/models/field.rb
cm-admin-1.5.22 lib/cm_admin/models/field.rb
cm-admin-1.5.21 lib/cm_admin/models/field.rb
cm-admin-1.5.20 lib/cm_admin/models/field.rb
cm-admin-1.5.11 lib/cm_admin/models/field.rb
cm-admin-1.5.9 lib/cm_admin/models/field.rb
cm-admin-1.5.8 lib/cm_admin/models/field.rb
cm-admin-1.5.7 lib/cm_admin/models/field.rb
cm-admin-1.5.6 lib/cm_admin/models/field.rb