Class: Ezframe::TypeBase

Inherits:
Object show all
Defined in:
lib/ezframe/column_type.rb

Direct Known Subclasses

CheckboxType, SelectType, TextType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr = nil) ⇒ TypeBase



27
28
29
30
# File 'lib/ezframe/column_type.rb', line 27

def initialize(attr = nil)
  @attribute = attr || {}
  @value = @attribute[:default]
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute.



6
7
8
# File 'lib/ezframe/column_type.rb', line 6

def attribute
  @attribute
end

#errorObject

Returns the value of attribute error.



6
7
8
# File 'lib/ezframe/column_type.rb', line 6

def error
  @error
end

#parentObject

Returns the value of attribute parent.



6
7
8
# File 'lib/ezframe/column_type.rb', line 6

def parent
  @parent
end

Class Method Details

.get_class(key) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# 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
  # puts "get_class: #{key_camel}"
  # puts "const_get: #{upper.const_get(key_camel).inspect}"
  if upper.const_defined?(key_camel)
    return upper.const_get(key_camel)
  end
  return nil
end

.type_nameObject



20
21
22
23
24
25
# File 'lib/ezframe/column_type.rb', line 20

def self.type_name
  if /::(\w*)Type/ =~ to_s
    return $1.to_s.to_snake
  end
  to_s.to_snake
end

Instance Method Details

#db_typeObject



49
50
51
# File 'lib/ezframe/column_type.rb', line 49

def db_type
  nil
end

#db_valueObject



53
54
55
# File 'lib/ezframe/column_type.rb', line 53

def db_value
  value
end

#form(opts = {}) ⇒ Object



57
58
59
# File 'lib/ezframe/column_type.rb', line 57

def form(opts = {})
  nil
end

#form_html(opts = {}) ⇒ Object



61
62
63
64
65
# File 'lib/ezframe/column_type.rb', line 61

def form_html(opts = {})
  form_h = form(opts)
  return nil unless form_h
  return Html.convert(form_h)
end

#keyObject



32
33
34
# File 'lib/ezframe/column_type.rb', line 32

def key
  @attribute[:key].to_sym
end

#labelObject



36
37
38
39
# File 'lib/ezframe/column_type.rb', line 36

def label
  return nil if @attribute[:hidden]
  @attribute[:label]
end

#multi_inputs?Boolean



94
95
96
# File 'lib/ezframe/column_type.rb', line 94

def multi_inputs?
  nil
end

#no_edit?Boolean



86
87
88
# File 'lib/ezframe/column_type.rb', line 86

def no_edit?
  return ((@attribute[:hidden] || @attribute[:no_edit]) && !@attribute[:force])
end

#no_view?Boolean



90
91
92
# File 'lib/ezframe/column_type.rb', line 90

def no_view?
  return (@attribute[:hidden] && !@attribute[:force])
end

#normalize(val) ⇒ Object



72
73
74
# File 'lib/ezframe/column_type.rb', line 72

def normalize(val)
  return val
end

#validate(val) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/ezframe/column_type.rb', line 76

def validate(val)
  if !val || val.empty?
    if @attribute[:required] == "true"
      @error = "required"
      return @error
    end
  end  
  return nil
end

#value(_situation = nil) ⇒ Object



41
42
43
# File 'lib/ezframe/column_type.rb', line 41

def value(_situation = nil)
  @value
end

#value=(v) ⇒ Object



45
46
47
# File 'lib/ezframe/column_type.rb', line 45

def value=(v)
  @value = v
end

#view(opts = {}) ⇒ Object



67
68
69
70
# File 'lib/ezframe/column_type.rb', line 67

def view(opts = {})
  return nil if no_view?
  @value
end