Sha256: e47a2fffb362afdc99208a1801f6c48bb53c51486b4b401c9bd06c80d91619ed

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

module ActiveList

  module Definition

    class AttributeColumn < DataColumn

      attr_reader :column, :label_method, :sort_column

      def initialize(table, name, options = {})
        super(table, name, options)
        @label_method = (options[:label_method] || @name).to_sym
        unless @sort_column = options[:sort]
          if @table.model.columns_hash[@label_method.to_s]
            @sort_column = @label_method
          elsif @table.model.columns_hash[@name.to_s]
            @sort_column = @name
          else
            @sort_column = :id
          end
        end
        @column  = @table.model.columns_hash[@label_method.to_s]
      end

      # Code for rows
      def datum_code(record = 'record_of_the_death', child = false)
        code = ""
        if child
          if @options[:children].is_a?(FalseClass)
            code = "nil"
          else
            code = "#{record}.#{table.options[:children]}.#{@options[:children] || @label_method}"
          end
        else
          code = "#{record}.#{@label_method}"
        end
        return code.c
      end

      # Returns the class name of the used model
      def class_name
        return self.table.model.name
      end

      def enumerize?
        self.table.model.send(@label_method).send(:values)
        return true
      rescue
        return false
      end

      def sort_expression
        "#{@table.model.table_name}.#{@sort_column}"
      end

    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
active_list-6.5.1 lib/active_list/definition/attribute_column.rb
active_list-6.5.0 lib/active_list/definition/attribute_column.rb
active_list-6.4.2 lib/active_list/definition/attribute_column.rb
active_list-6.4.1 lib/active_list/definition/attribute_column.rb
active_list-6.4.0 lib/active_list/definition/attribute_column.rb
active_list-6.3.1 lib/active_list/definition/attribute_column.rb
active_list-6.3.0 lib/active_list/definition/attribute_column.rb
active_list-6.2.4 lib/active_list/definition/attribute_column.rb
active_list-6.2.3 lib/active_list/definition/attribute_column.rb
active_list-6.2.1 lib/active_list/definition/attribute_column.rb
active_list-6.2.0 lib/active_list/definition/attribute_column.rb
active_list-6.1.5 lib/active_list/definition/attribute_column.rb
active_list-6.1.4 lib/active_list/definition/attribute_column.rb
active_list-6.1.3 lib/active_list/definition/attribute_column.rb
active_list-6.1.2 lib/active_list/definition/attribute_column.rb