Sha256: d08e74d07042525c6838bf4e5d30c1efb69dd6c10e62913b851e04562d79c621

Contents?: true

Size: 1.8 KB

Versions: 20

Compression:

Stored size: 1.8 KB

Contents

module Bhf::Platform::Attribute
  class Column

    attr_reader :name, :title, :info, :type

    def initialize(props, options = {})
      @name = props.name
      @title = options[:title]
      @info = options[:info]
      @type = props.type

      @options_form_type = options[:form_type].to_sym if options[:form_type]
      @options_display_type = options[:display_type].to_sym if options[:display_type]
      @options_show_type = options[:show_type].to_sym if options[:show_type]

      @pk = options[:primary_key]
    end

    def macro
      :column
    end

    def form_type
      return @options_form_type if @options_form_type

      if name == @pk || name == 'updated_at' || name == 'created_at'
        :static
      elsif name == 'type'
        :type
      else
        supported_types(@type)
      end
    end

    def display_type
      return @options_display_type if @options_display_type

      if name == @pk
        :primary_key
      elsif name == 'type'
        :type
      else
        supported_types(@type)
      end
    end

    def type_ignore_emtpy?
      display_type == :boolean || display_type == :toggle
    end

    def show_type
      @options_show_type || display_type
    end

    def reflection
      false
    end

    def db_name
      name
    end

    def reorderble
      true
    end

    private

      def supported_types(check_type)
        if [:boolean, :toggle, :text, :array, :hash].include?(check_type)
          check_type
        elsif type_sym = group_types(check_type)
          type_sym
        else
          :string
        end
      end

      def group_types(type_sym)
        return :date if [:date, :datetime, :timestamp, :time, :year].include?(type_sym)
        return :number if [:integer, :float].include?(type_sym)
        return :file if type_sym == :file
      end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
bhf-1.0.0.beta16 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta15 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta14 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta13 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta12 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta11 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta10 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta9 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta8 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta7 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta6 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta5 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta4 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta3 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta2 lib/bhf/platform/attribute/column.rb
bhf-1.0.0.beta1 lib/bhf/platform/attribute/column.rb
bhf-0.10.17 lib/bhf/platform/attribute/column.rb
bhf-0.10.16 lib/bhf/platform/attribute/column.rb
bhf-0.10.15 lib/bhf/platform/attribute/column.rb
bhf-0.10.14 lib/bhf/platform/attribute/column.rb