Class: Column
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Column
show all
- Extended by:
- Zena::Acts::Secure
- Includes:
- Property::StoredColumn, RubyLess
- Defined in:
- app/models/column.rb
Constant Summary
collapse
- TYPES_FOR_FORM =
%w{string datetime integer float hash}
- INDICES_FOR_FORM =
%w{string ml_string datetime integer float}
- FIELD_INDICES =
[]
Class Method Summary
collapse
Instance Method Summary
collapse
secure_scope, secure_write_scope, visitor=
#construct_id_map, #secure_result
Class Method Details
.add_field_index(*args) ⇒ Object
Declare a new index table or field
47
48
49
50
51
|
# File 'app/models/column.rb', line 47
def add_field_index(*args)
args.flatten.each do |idx|
FIELD_INDICES << idx
end
end
|
37
38
39
40
41
42
43
44
|
# File 'app/models/column.rb', line 37
def indices_for_form
[
['field',
FIELD_INDICES.map {|i| [i, ".#{i}"]}],
['key/value',
INDICES_FOR_FORM.map {|i| [i, i]}]
]
end
|
27
28
29
30
31
32
33
34
35
|
# File 'app/models/column.rb', line 27
def roles_for_form
if roles = secure(Role) { Role.all(:order => 'name ASC') }
roles.map do |role|
[role.name, role.id]
end
else
[]
end
end
|
Instance Method Details
#export ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'app/models/column.rb', line 63
def export
root = current_site.root_node
{
'ptype' => ptype,
'index' => index,
'comment' => root.unparse_assets(, root, 'comment')
}
end
|
#index_name ⇒ Object
Used to display index name in forms
59
60
61
|
# File 'app/models/column.rb', line 59
def index_name
self.index.to_s.gsub(/\A\./,'')
end
|
#klass ⇒ Object
103
104
105
106
107
108
109
|
# File 'app/models/column.rb', line 103
def klass
if ptype == 'hash'
StringHash
else
nil
end
end
|
#kpath ⇒ Object
54
55
56
|
# File 'app/models/column.rb', line 54
def kpath
@kpath ||= role.kpath
end
|
#merge_hash(orig, value) ⇒ Object
95
96
97
98
99
100
101
|
# File 'app/models/column.rb', line 95
def merge_hash(orig, value)
unless orig.kind_of?(StringHash)
orig = StringHash.from_hash(orig)
end
orig.merge!(value)
return orig
end
|
#type_cast(value) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/models/column.rb', line 72
def type_cast(value)
if value.blank?
return nil
end
if ptype == 'datetime'
if value.kind_of?(Time)
value
elsif value.kind_of?(String)
value.to_utc(_(Zena::Use::Dates::DATETIME), visitor.tz)
else
nil
end
elsif ptype == 'hash'
if value.kind_of?(Hash)
StringHash.from_hash(value)
elsif value.kind_of?(String)
StringHash.from_string(value)
end
else
nil
end
end
|