Sha256: ad9c68bf3c438b28079b13c76c1b886f487a8ebcd5dafa9722f5b1b122280edd

Contents?: true

Size: 633 Bytes

Versions: 3

Compression:

Stored size: 633 Bytes

Contents

module Persistent
  module Settings
    module Persistance
      def load_from_persistance!
        self.all.each do |setting|
          self.send("#{setting.var}=", setting.value)
        end
      end

      def load_from_persistance
        load_from_persistance! if ready?
      end

      def persist(getter, value)
        setting = self.where(:var => getter).last
        if setting
          setting.update_attribute(:value, value)
        else
          self.create(:var => getter, :value => value)
        end
      end

      def read_from_persistance(key)
        self.find_by_var(key).value
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
persistent_settings-1.5.0 lib/persistent/settings/persistance.rb
persistent_settings-1.4.0 lib/persistent/settings/persistance.rb
persistent_settings-1.3.0 lib/persistent/settings/persistance.rb