Class ItemProper
In: app/models/item_proper.rb
Parent: Item

テーブルのカラムに対応する項目のモデル。

Methods

Included Modules

Condition Picker

Constants

PRIVATE_COLUMN = %w[id]
HIDDEN_COLUMN = %w[domain_id created_at updated_at created_by updated_by created_in updated_in]
FOREIGN_KEYS = %w|company organization person post group|

Public Instance methods

カレンダー参照を行うかどうかを判定する。

[Source]

     # File app/models/item_proper.rb, line 183
183:   def calendar?
184:     input_type == "picker" && input_parameter == "calendar"
185:   end

checkbox 形式を利用するかどうか判定する。

[Source]

     # File app/models/item_proper.rb, line 188
188:   def checkbox?
189:     input_type == "checkbox"
190:   end

ユーザーの言語での名前を返す。

[Source]

     # File app/models/item_proper.rb, line 122
122:   def human_name
123:     column = model_class.columns_hash[column_name]
124:     unless column
125:       logger.warn "WARN:Item\#human_name: column not found: #{model_class}\##{column_name}"
126:       return name
127:     end
128:     if name.blank?
129:       logger.warn("WARN:Item\#human_name: name is blank: #{model_class}\##{column_name}")
130:       return column.human_name
131:     elsif name == column.name.humanize
132:       logger.warn("WARN:Item\#human_name: name is not translated: #{model_class}\##{column_name}")
133:       return column.human_name
134:     end
135:     return name
136:   end

InputOption 参照を行う場合はその種類を文字列で返す。 さもなくば false を返す。

[Source]

     # File app/models/item_proper.rb, line 177
177:   def option_category
178:     return input_parameter if %w|select radio|.include?(input_type) && !input_parameter.blank?
179:     return false
180:   end

並び替えを指定する文字列または false を返す。

[Source]

     # File app/models/item_proper.rb, line 155
155:   def order
156:     return false if direction.blank? || direction =~ /none/i
157:     "#{column_name} #{direction}"
158:   end

[Source]

     # File app/models/item_proper.rb, line 117
117:   def picker_field(it, name)
118:     detail? ? "#{picked_atom}#{id}_#{name}" : "#{picked_atom}#{id}"
119:   end

外部参照を行うカラムに対応している場合はそのクラスを返す。 さもなくば false を返す。

[Source]

     # File app/models/item_proper.rb, line 162
162:   def reference
163:     if input_type == "picker" && !input_parameter.blank? && input_parameter != "calendar"
164:       return picked_atom.classify.constantize
165:     end
166:     if /(?!:[a-z])([a-z0-9]+)_id\z/ =~ column_name
167:       name = $1
168:       if FOREIGN_KEYS.include?(name)
169:         return name.classify.constantize
170:       end
171:     end
172:     return false
173:   end

入力が必須かどうかを判定する。

[Source]

     # File app/models/item_proper.rb, line 139
139:   def required?
140:     return true if validates_presence?
141:     column = model_class.columns_hash[column_name]
142:     unless column
143:       logger.error("ERROR:Item\#required?: column not found: #{model_class}\##{column_name}")
144:       return false
145:     end
146:     return column.required?
147:   end

(権限が許せば)インスタンスに属性を設定する。

[Source]

     # File app/models/item_proper.rb, line 150
150:   def set_attributes(x, attr)
151:     x.__send__("#{column_name}=", attr[column_name.to_sym]) if writable?
152:   end

対象 it の表示に適したデータを返す。 直接値を表示する以外に次のパターンが用意されている:

  • input_type が ‘checkbox’ の場合
  • input_parameter による指定1(特定のモデル経由)
  • input_parameter による指定2(InputOptions経由)
  • column_name の末尾による判定

[Source]

     # File app/models/item_proper.rb, line 198
198:   def to_data(it)
199:     value = it.__send__(column_name)
200:     case input_type
201:     when "checkbox"
202:       on, off = input_parameter.split(",")
203:       on  ||= "ON"
204:       off ||= ""
205:       return value ? on : off
206:     end
207:     if c = option_category
208:       if name = InputOption.option_name(c, value)
209:         return name
210:       end
211:       logger.warn("WARNING: option not found: #{input_parameter}/#{value}")
212:     elsif r = reference
213:       return refer(value, r)
214:     elsif calendar?
215:       if /(\d{4})[\/\-]?(\d{2})[\/\-]?(\d{2})/ =~ value
216:         return "#{$1}/#{$2}/#{$3}"
217:       end
218:       logger.warn("WARNING: invalid date: #{value}")
219:     end
220:     return value
221:   end

種類の名前を返す。

[Source]

     # File app/models/item_proper.rb, line 113
113:   def type_name
114:     s_("Item|Proper")
115:   end

[Validate]