Module: Unidom::Common::Concerns::NotationColumn::ClassMethods
- Defined in:
- app/models/unidom/common/concerns/notation_column.rb
Instance Method Summary collapse
-
#notation_boolean_column(*names) ⇒ Object
定义标注字段的 boolean 型的列。如: class YourModel < ApplicationRecord include Unidom::Common::Concerns::NotationColumn notation_boolean_column :still_alive end 则为 YourModel 的实例生成2个方法:still_alive? 和 still_alive=。 model = YourModel.new still_alive: true model.still_alive? # true model.still_alive = false model.still_alive? # false.
-
#notation_column(*names) ⇒ Object
定义 JSON 类型的列。如: notation_column :given_name, :family_name.
Instance Method Details
#notation_boolean_column(*names) ⇒ Object
定义标注字段的 boolean 型的列。如: class YourModel < ApplicationRecord
include Unidom::Common::Concerns::NotationColumn
notation_boolean_column :still_alive
end 则为 YourModel 的实例生成2个方法:still_alive? 和 still_alive=。 model = YourModel.new still_alive: true model.still_alive? # true model.still_alive = false model.still_alive? # false
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/unidom/common/concerns/notation_column.rb', line 52 def notation_boolean_column(*names) names.each do |name| name = name.to_s instance_eval do define_method("#{name}?") do notation.try(:[], 'columns').try(:[], name) end define_method("#{name}=") do |value| notation['columns'] ||= {} notation['columns'][name] = value end end end end |
#notation_column(*names) ⇒ Object
定义 JSON 类型的列。如: notation_column :given_name, :family_name
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/unidom/common/concerns/notation_column.rb', line 26 def notation_column(*names) names.each do |name| name = name.to_s instance_eval do define_method(name) do notation.try(:[], 'columns').try(:[], name) end define_method("#{name}=") do |value| notation['columns'] ||= {} notation['columns'][name] = value end end end end |