class Ezframe::TypeBase

Attributes

attribute[RW]
error[RW]
parent[RW]

Public Class Methods

get_class(key) click to toggle source
# File lib/ezframe/column_type.rb, line 8
def self.get_class(key)
  return nil unless key
  upper = Object.const_get("Ezframe")
  key_camel = "#{key}_type".to_camel
  if upper.const_defined?(key_camel)
    return upper.const_get(key_camel)
  end
  return nil
end
new(attr = nil) click to toggle source
# File lib/ezframe/column_type.rb, line 25
def initialize(attr = nil)
  @attribute = attr || {}
  @value = @attribute[:default]
end
type_name() click to toggle source
# File lib/ezframe/column_type.rb, line 18
def self.type_name
  if /::(\w*)Type/ =~ to_s
    return $1.to_s.to_snake
  end
  to_s.to_snake
end

Public Instance Methods

db_type() click to toggle source
# File lib/ezframe/column_type.rb, line 51
def db_type
  nil
end
db_value() click to toggle source
# File lib/ezframe/column_type.rb, line 55
def db_value
  value
end
form(opts = {}) click to toggle source
# File lib/ezframe/column_type.rb, line 59
def form(opts = {})
  nil
end
key() click to toggle source
# File lib/ezframe/column_type.rb, line 30
def key
  @attribute[:key].to_sym
end
label(opts = {}) click to toggle source
# File lib/ezframe/column_type.rb, line 34
def label(opts = {})
  return nil if @attribute[:hidden] && !opts[:force]
  @attribute[:label]
end
make_error_box(name) click to toggle source
# File lib/ezframe/column_type.rb, line 112
def make_error_box(name)
  Ht.div(id: "error-box-#{name}", class: %w[error-box hide], child: "")
end
multi_inputs?() click to toggle source

複数のinputを持っているか?

# File lib/ezframe/column_type.rb, line 95
def multi_inputs?
  nil
end
no_edit?() click to toggle source
# File lib/ezframe/column_type.rb, line 86
def no_edit?
  return ((@attribute[:hidden] || @attribute[:no_edit]) && !@attribute[:force])
end
no_view?() click to toggle source
# File lib/ezframe/column_type.rb, line 90
def no_view?
  return (@attribute[:hidden] || @attribute[:no_view]) && !@attribute[:force]
end
normalize(val) click to toggle source
# File lib/ezframe/column_type.rb, line 72
def normalize(val)
  return val
end
type() click to toggle source
# File lib/ezframe/column_type.rb, line 39
def type
  @attribute[:type]
end
use_view_format(format_a, val) click to toggle source

フォーマットに従って表示する

# File lib/ezframe/column_type.rb, line 100
def use_view_format(format_a, val)
  return nil unless val
  if format_a.is_a?(String)
    return format_a % val
  else
    fmt_a = format_a.clone
    pattern = fmt_a.shift
    value_a = fmt_a.map {|key| val.send(key) }
    return pattern % value_a
  end
end
validate(val) click to toggle source
# File lib/ezframe/column_type.rb, line 76
def validate(val)
  if !val || val.to_s.empty?
    if @attribute[:required] == "true"
      @error = "required"
      return @error
    end
  end  
  return nil
end
value(_situation = nil) click to toggle source
# File lib/ezframe/column_type.rb, line 43
def value(_situation = nil)
  @value
end
value=(v) click to toggle source
# File lib/ezframe/column_type.rb, line 47
def value=(v)
  @value = v
end
view(opts = {}) click to toggle source
# File lib/ezframe/column_type.rb, line 63
def view(opts = {})
  return nil if no_view?
  if @attribute[:view_format]
    return use_view_format(@attribute[:view_format], @value)
  else
    @value
  end
end