Module: EasyModel::ColumnForActiveRecord
- Defined in:
- lib/easy_model/column_for_active_record.rb
Overview
テーブルに存在しないカラムを定義する機能を提供する.
詳細
attr_accessor による属性定義とは異なり, データ型及びデフォルト値を指定することが可能.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#easy_model_attribute_names ⇒ Object
属性名の配列.
-
#easy_model_attributes ⇒ Object
属性名と値を保持するハッシュ.
Class Method Details
.included(base) ⇒ Object
13 14 15 |
# File 'lib/easy_model/column_for_active_record.rb', line 13 def self.included(base) base.extend(EasyModel::ColumnForActiveRecord::ClassMethods) end |
Instance Method Details
#easy_model_attribute_names ⇒ Object
属性名の配列.
戻り値
EasyModel::ColumnForActiveRecord::ClassMethods#column で定義した属性名を文字列配列として返す.
23 24 25 |
# File 'lib/easy_model/column_for_active_record.rb', line 23 def easy_model_attribute_names self.class.easy_model_attribute_names end |
#easy_model_attributes ⇒ Object
属性名と値を保持するハッシュ.
戻り値
=> 値 であるハッシュ.
33 34 35 36 37 |
# File 'lib/easy_model/column_for_active_record.rb', line 33 def easy_model_attributes self.class.easy_model_attribute_names.reduce({}) do |map, name| map.tap{map[name] = send(name)} end end |