Class: Ezframe::TypeBase
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attr = nil) ⇒ TypeBase
Returns a new instance of TypeBase.
25
26
27
28
|
# File 'lib/ezframe/column_type.rb', line 25
def initialize(attr = nil)
@attribute = attr || {}
@value = @attribute[:default]
end
|
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
6
7
8
|
# File 'lib/ezframe/column_type.rb', line 6
def attribute
@attribute
end
|
Returns the value of attribute error.
6
7
8
|
# File 'lib/ezframe/column_type.rb', line 6
def error
@error
end
|
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
|
# 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
|
.type_name ⇒ Object
18
19
20
21
22
23
|
# 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
|
Instance Method Details
51
52
53
|
# File 'lib/ezframe/column_type.rb', line 51
def db_type
nil
end
|
55
56
57
|
# File 'lib/ezframe/column_type.rb', line 55
def db_value
value
end
|
59
60
61
|
# File 'lib/ezframe/column_type.rb', line 59
def form(opts = {})
nil
end
|
30
31
32
|
# File 'lib/ezframe/column_type.rb', line 30
def key
@attribute[:key].to_sym
end
|
#label(opts = {}) ⇒ Object
34
35
36
37
|
# 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) ⇒ Object
112
113
114
|
# 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
|
95
96
97
|
# File 'lib/ezframe/column_type.rb', line 95
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[:no_view]) && !@attribute[:force]
end
|
#normalize(val) ⇒ Object
72
73
74
|
# File 'lib/ezframe/column_type.rb', line 72
def normalize(val)
return val
end
|
39
40
41
|
# File 'lib/ezframe/column_type.rb', line 39
def type
@attribute[:type]
end
|
100
101
102
103
104
105
106
107
108
109
110
|
# 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) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# 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) ⇒ Object
43
44
45
|
# File 'lib/ezframe/column_type.rb', line 43
def value(_situation = nil)
@value
end
|
#value=(v) ⇒ Object
47
48
49
|
# File 'lib/ezframe/column_type.rb', line 47
def value=(v)
@value = v
end
|
#view(opts = {}) ⇒ Object
63
64
65
66
67
68
69
70
|
# 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
|