Sha256: 9f74d727996eb8b806f8f5b9063ef60c6f6521420de34edcf6c74610eff55281

Contents?: true

Size: 1.63 KB

Versions: 19

Compression:

Stored size: 1.63 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
      else
        supported_types(@type)
      end
    end
    
    def display_type
      return @options_display_type if @options_display_type
      
      if name == @pk
        :primary_key
      else
        supported_types(@type)
      end
    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, :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

19 entries across 19 versions & 1 rubygems

Version Path
bhf-0.10.11 lib/bhf/platform/attribute/column.rb
bhf-0.10.10 lib/bhf/platform/attribute/column.rb
bhf-0.10.9 lib/bhf/platform/attribute/column.rb
bhf-0.9.9 lib/bhf/platform/attribute/column.rb
bhf-0.9.8 lib/bhf/platform/attribute/column.rb
bhf-0.9.7 lib/bhf/platform/attribute/column.rb
bhf-0.9.6 lib/bhf/platform/attribute/column.rb
bhf-0.9.5 lib/bhf/platform/attribute/column.rb
bhf-0.9.4 lib/bhf/platform/attribute/column.rb
bhf-0.9.3 lib/bhf/platform/attribute/column.rb
bhf-0.9.2 lib/bhf/platform/attribute/column.rb
bhf-0.9.1 lib/bhf/platform/attribute/column.rb
bhf-0.9.0 lib/bhf/platform/attribute/column.rb
bhf-0.8.7 lib/bhf/platform/attribute/column.rb
bhf-0.8.6 lib/bhf/platform/attribute/column.rb
bhf-0.8.5 lib/bhf/platform/attribute/column.rb
bhf-0.8.4 lib/bhf/platform/attribute/column.rb
bhf-0.8.3 lib/bhf/platform/attribute/column.rb
bhf-0.8.2 lib/bhf/platform/attribute/column.rb