# Use this module to add necessary attributes methods that ActiveModel::AttributeMethods doesn't add # An ATTRIBUTES constant must be on the model before including this module # Attributes specified in ATTRIBUTES will be serialized if any ActiveModel::Serializers are used # Any attributes that shouldn't be serialized can still be set with another attr_accessor, but won't show up in # module CellSet module Attributes extend ActiveSupport::Concern extend ActiveModel::Naming include ActiveModel::AttributeMethods included do self.send(:attr_accessor, *self::ATTRIBUTES) if self.private_methods.include?(:define_attribute_method) self.send(:define_attribute_method, self::ATTRIBUTES) end end module ClassMethods def human_attribute_name(attr, options = {}) attr end def lookup_ancestors [self] end end def initialize(attrs = {}) @errors = ActiveModel::Errors.new(self) attrs.each do |name, value| send("#{name}=", value) if value end super(attrs) end def attributes self.class::ATTRIBUTES.inject(ActiveSupport::HashWithIndifferentAccess.new) do |result, key| result[key] = read_attribute_for_validation(key) result end end def attributes=(attrs) attrs.each_pair {|k, v| send("#{k}=", v)} end def clear_attribute(attr) send("#{attr}=", nil) end def has_attribute?(attr) self.class::ATTRIBUTES.include?(attr) end def read_attribute_for_validation(key) send(key) end end end