Class: ModelBase
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
#encode_amf
Class Method Details
.admin_group ⇒ Object
15
16
17
|
# File 'lib/mrpin/core/base/model_base.rb', line 15
def self.admin_group
self.name.underscore.split('_').first
end
|
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/mrpin/core/base/model_base.rb', line 70
def self.configure_admin_edit(context, field_name)
case field_name
when :_type, :created_at, :updated_at
context.configure field_name do
visible false
end
else
context.configure field_name
end
end
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/mrpin/core/base/model_base.rb', line 20
def self.configure_admin_list(context, field_name)
model_class = get_class_by_name(context.abstract_model.model_name)
is_mongoid_field = false
is_mongoid_relation_field = false
if model_class.include?(Mongoid::Document)
if model_class.fields.include?(field_name.to_s)
is_mongoid_field = true
end
if model_class.relations.keys.include?(field_name.to_s)
is_mongoid_relation_field = true
end
end
if is_mongoid_field && model_class.fields[field_name.to_s].type == Mongoid::Boolean
context.configure field_name
elsif is_mongoid_relation_field
context.configure field_name
else
case field_name
when :_type, /\Auploader_/
context.configure field_name do
visible false
end
when /_at\z/
context.configure field_name do
pretty_value do
Time.at(value).to_s(:short) unless value.nil?
end
read_only true
end
when /\Aurl_/
context.configure field_name do
pretty_value do
unless value.nil?
UtilsAdmin.tag_img(bindings[:view], value, 25, 25)
end
end
end
else
context.configure field_name do
pretty_value { value }
end
end
end
end
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/mrpin/core/base/model_base.rb', line 82
def self.configure_admin_show(context, field_name)
case field_name
when :_type
context.configure field_name do
visible false
end
when /_at\z/
context.configure field_name do
pretty_value do
Time.at(value).to_s(:short)
end
end
when /\Aurl_/
context.configure field_name do
pretty_value do
UtilsAdmin.tag_img(bindings[:view], value, 100, 100)
end
end
else
context.configure field_name
end
end
|
.filters_for_admin_list(section) ⇒ Object
115
116
117
|
# File 'lib/mrpin/core/base/model_base.rb', line 115
def self.filters_for_admin_list(section)
section.filters []
end
|
.init_scopes ⇒ Object
124
125
126
|
# File 'lib/mrpin/core/base/model_base.rb', line 124
def self.init_scopes
end
|
.sort_by_for_admin_list(section) ⇒ Object
110
111
112
|
# File 'lib/mrpin/core/base/model_base.rb', line 110
def self.sort_by_for_admin_list(section)
section.sort_by :_id
end
|
Instance Method Details
#clone_model ⇒ Object
211
212
213
|
# File 'lib/mrpin/core/base/model_base.rb', line 211
def clone_model
self.class.new(self.as_json)
end
|
#create_info ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/mrpin/core/base/model_base.rb', line 152
def create_info
return nil if class_info.nil?
result = class_info.new
class_info.attributes.each do |attribute_name|
next unless self.respond_to? attribute_name
attribute_value = get_attribute_value(attribute_name)
result.send("#{attribute_name}=", attribute_value)
end
result
end
|
#create_info_with_check ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/mrpin/core/base/model_base.rb', line 169
def create_info_with_check
return nil if class_info.nil?
result = class_info.new
class_info.attributes.each do |attribute_name|
if (self.respond_to?(attribute_name) && self.has_attribute?(attribute_name)) || attribute_name.to_s == 'id'
attribute_value = get_attribute_value(attribute_name)
result.send("#{attribute_name}=", attribute_value)
end
end
result
end
|