Module: Unidom::Common::Concerns::ModelExtension::ClassMethods

Defined in:
app/models/unidom/common/concerns/model_extension.rb

Instance Method Summary collapse

Instance Method Details

#notation_boolean_column(*names) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/models/unidom/common/concerns/model_extension.rb', line 165

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



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/models/unidom/common/concerns/model_extension.rb', line 150

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

#to_id(model) ⇒ Object



146
147
148
# File 'app/models/unidom/common/concerns/model_extension.rb', line 146

def to_id(model)
  model.respond_to?(:id) ? model.id : model
end