class Bhf::Platform::Attribute::Column

Attributes

info[R]
name[R]
title[R]
type[R]

Public Class Methods

new(props, options = {}) click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 6
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

Public Instance Methods

db_name() click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 59
def db_name
  name
end
display_type() click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 35
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
form_type() click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 23
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
macro() click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 19
def macro
  :column
end
reflection() click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 55
def reflection
  false
end
reorderble() click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 63
def reorderble
  true
end
show_type() click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 51
def show_type
  @options_show_type || display_type
end
type_ignore_emtpy?() click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 47
def type_ignore_emtpy?
  display_type == :boolean || display_type == :toggle
end

Private Instance Methods

group_types(type_sym) click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 79
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
supported_types(check_type) click to toggle source
# File lib/bhf/platform/attribute/column.rb, line 69
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