Sha256: 14db67907ef10751e1cd9581f043dc516129974ee68eb47598b2c75334ab1fce

Contents?: true

Size: 944 Bytes

Versions: 71

Compression:

Stored size: 944 Bytes

Contents

module Concerns
  module Storable
    extend ActiveSupport::Concern

    included do
      has_many :stores, as: :storable, dependent: :destroy

      after_save do
        @store_collections.keys.each { |c| store(c).save } if @store_collections
      end
    end

    def storable?
      true
    end

    def store(collection = :default)
      @store_collections = {} unless @store_collections

      unless @store_collections[collection.to_sym]
        @store_collections[collection.to_sym] = Concerns::Storable::Collection.new(
          self, collection, self.class.store_config
        )
      end

      @store_collections[collection.to_sym]
    end

    module ClassMethods
      def storable_field(name, type, default = nil)
        delegate name, "#{name}=", to: :store
        store_config.add name, type, default
      end

      def store_config
        @store_config ||= Concerns::Storable::Config.new
      end
    end
  end
end

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
udongo-7.9.0 app/models/concerns/storable.rb
udongo-7.8.1 app/models/concerns/storable.rb
udongo-7.8.0 app/models/concerns/storable.rb
udongo-7.7.2 app/models/concerns/storable.rb
udongo-7.7.1 app/models/concerns/storable.rb
udongo-7.7.0 app/models/concerns/storable.rb
udongo-7.6.2 app/models/concerns/storable.rb
udongo-7.6.1 app/models/concerns/storable.rb
udongo-7.6.0 app/models/concerns/storable.rb
udongo-7.5.1 app/models/concerns/storable.rb
udongo-7.5.0 app/models/concerns/storable.rb
udongo-7.4.2 app/models/concerns/storable.rb
udongo-7.4.1 app/models/concerns/storable.rb
udongo-7.4.0 app/models/concerns/storable.rb
udongo-7.3.5 app/models/concerns/storable.rb
udongo-7.3.4 app/models/concerns/storable.rb
udongo-7.3.3 app/models/concerns/storable.rb
udongo-7.3.2 app/models/concerns/storable.rb
udongo-7.3.1 app/models/concerns/storable.rb
udongo-7.2.1 app/models/concerns/storable.rb