Sha256: 8a260f85698e7e5465271b8f5531a8dfba5f65ffddc09f4757be341e09c267e9

Contents?: true

Size: 861 Bytes

Versions: 35

Compression:

Stored size: 861 Bytes

Contents

module Renalware
  class RememberedPreferences
    def initialize(session)
      @session = session
    end

    def persist(model)
      return unless model
      self.class::ATTRIBUTES_TO_REMEMBER.each do |attribute|
        remembered_attributes[attribute] = model.public_send(attribute)
      end
      session[self.class::SESSION_KEY] = remembered_attributes
    end

    def apply_to(model)
      return unless model
      self.class::ATTRIBUTES_TO_REMEMBER.each do |attribute|
        unless model.public_send(:"#{attribute}?")
          model.public_send(:"#{attribute}=", remembered_attributes[attribute])
        end
      end
    end

    protected

    attr_accessor :session

    def remembered_attributes
      @remembered_attributes ||= begin
        session.fetch(self.class::SESSION_KEY, {}).with_indifferent_access
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
renalware-core-2.0.16 lib/renalware/remembered_preferences.rb
renalware-core-2.0.15 lib/renalware/remembered_preferences.rb
renalware-core-2.0.14 lib/renalware/remembered_preferences.rb
renalware-core-2.0.13 lib/renalware/remembered_preferences.rb
renalware-core-2.0.12 lib/renalware/remembered_preferences.rb
renalware-core-2.0.11 lib/renalware/remembered_preferences.rb
renalware-core-2.0.9 lib/renalware/remembered_preferences.rb
renalware-core-2.0.8 lib/renalware/remembered_preferences.rb
renalware-core-2.0.7 lib/renalware/remembered_preferences.rb
renalware-core-2.0.5 lib/renalware/remembered_preferences.rb
renalware-core-2.0.4 lib/renalware/remembered_preferences.rb
renalware-core-2.0.3 lib/renalware/remembered_preferences.rb
renalware-core-2.0.2 lib/renalware/remembered_preferences.rb
renalware-core-2.0.1 lib/renalware/remembered_preferences.rb
renalware-core-2.0.0 lib/renalware/remembered_preferences.rb
renalware-core-2.0.0.pre.rc13 lib/renalware/remembered_preferences.rb
renalware-core-2.0.0.pre.rc11 lib/renalware/remembered_preferences.rb
renalware-core-2.0.0.pre.rc10 lib/renalware/remembered_preferences.rb
renalware-core-2.0.0.pre.rc9 lib/renalware/remembered_preferences.rb
renalware-core-2.0.0.pre.rc8 lib/renalware/remembered_preferences.rb