Sha256: 492656128c3c28c61f1a21caf89b528e29109d4ca83ca944f9d5ecfaa31db260
Contents?: true
Size: 1.31 KB
Versions: 30
Compression:
Stored size: 1.31 KB
Contents
module Her module Model # TODO: make PR to Her project # This patch fixes the detection of changed attributes module Attributes extend ActiveSupport::Concern module ClassMethods # Define the attributes that will be used to track dirty attributes and validations # # @param [Array] attributes # @example # class User # include Her::Model # attributes :name, :email # end def attributes(*attributes) define_attribute_methods attributes attributes.each do |attribute| attribute = attribute.to_sym unless instance_methods.include?(:"#{attribute}=") define_method("#{attribute}=") do |value| @attributes[:"#{attribute}"] = nil unless @attributes.include?(:"#{attribute}") self.send(:"#{attribute}_will_change!") if @attributes[:"#{attribute}"] != value @attributes[:"#{attribute}"] = value end end unless instance_methods.include?(:"#{attribute}?") define_method("#{attribute}?") do @attributes.include?(:"#{attribute}") && @attributes[:"#{attribute}"].present? end end end end end end end end
Version data entries
30 entries across 30 versions & 1 rubygems