Sha256: 565bcc982680f8e5bb3d3211a1e93cff647e28f08cf5faa2ee7e6f35e4128538

Contents?: true

Size: 751 Bytes

Versions: 2

Compression:

Stored size: 751 Bytes

Contents

require 'active_support/concern'

module ConfigureMe
  module Persistence
    extend ActiveSupport::Concern

    included do
      @persisting = false
    end

    module ClassMethods
      def persist_me(persistence_key = nil)
        if ConfigureMe.persistence_klass.nil?
          raise ::RuntimeError, "configure_me - persistence_klass is not set.  Make sure you have an initializer to assign it."
        end
        @persisting = true
      end

      def persisting?
        @persisting
      end

      def persistence_key
        self.config_name
      end
    end

    def persistence_key(name)
      key = "#{self.class.persistence_key}_#{name.to_s}"
      key = @parent.persistence_key(key) unless @parent.nil?
      key
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
configure_me-0.2.1 lib/configure_me/persistence.rb
configure_me-0.1.1 lib/configure_me/persistence.rb