Sha256: d4ce269342ff51bbbf063e45c7db84e7ca08d2128b1df238183877fbd4f31ce9

Contents?: true

Size: 893 Bytes

Versions: 15

Compression:

Stored size: 893 Bytes

Contents

module ReaderUser

  def self.included(base)
    extend ClassMethods
    base.class_eval do
      has_one :reader, :dependent => :nullify
      attr_accessor :skip_reader_update
      include InstanceMethods
      before_save :update_reader    # there is already a before_update call that hashes the password, so we need to come in before that
    end
  end

  module ClassMethods

  end
  
  module InstanceMethods
    def update_reader
      if !new_record? && self.reader && !self.skip_reader_update
        changed_columns = Reader.user_columns & self.changed
        att = self.attributes.slice(*changed_columns)
        self.reader.send :update_with, att if att.any?
      end
      true
    end
  
    def update_with(att)
      self.skip_reader_update = true
      self.confirm_password = false
      self.update_attributes(att)
      self.skip_reader_update = false
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
radiant-reader-extension-3.0.38 lib/reader_user.rb
radiant-reader-extension-3.0.37 lib/reader_user.rb
radiant-reader-extension-3.0.36 lib/reader_user.rb
radiant-reader-extension-3.0.35 lib/reader_user.rb
radiant-reader-extension-3.0.33 lib/reader_user.rb
radiant-reader-extension-3.0.32 lib/reader_user.rb
radiant-reader-extension-3.0.31 lib/reader_user.rb
radiant-reader-extension-3.0.30 lib/reader_user.rb
radiant-reader-extension-3.0.29 lib/reader_user.rb
radiant-reader-extension-3.0.28 lib/reader_user.rb
radiant-reader-extension-3.0.27 lib/reader_user.rb
radiant-reader-extension-3.0.26 lib/reader_user.rb
radiant-reader-extension-3.0.25 lib/reader_user.rb
radiant-reader-extension-3.0.24 lib/reader_user.rb
radiant-reader-extension-3.0.23 lib/reader_user.rb