Sha256: e71148c672b328eb123fdf06ff55ad8854d54c97c5d984b9deea2d3ab4ca991a

Contents?: true

Size: 1.45 KB

Versions: 18

Compression:

Stored size: 1.45 KB

Contents

module Volt
  module Persistors
    # Implements the base persistor functionality.
    class Base
      def initialize(model)
        @model = model
      end

      def loaded(initial_state = nil)
        @model.change_state_to(:loaded_state, initial_state || :loaded)
      end

      # Method that is called when data on the model changes.
      # @returns [true|Promise] - should return a Promise or true.  On async
      #    persistors, the promise from set and save! will wait on the
      #    Promise.
      def changed(attribute_name)
      end

      def added(model, index)
      end

      # For removed, the default action is to call changed for it
      def removed(attribute_name)
        changed(attribute_name)
      end

      # Called when the model is cleared (all child models removed)
      def clear
      end

      def event_added(event, first, first_for_event)
      end

      def event_removed(event, last, last_for_event)
      end

      # Specify if this collection should auto-generate id's
      def auto_generate_id
        false
      end

      # return true if this persistor is asynchronus and needs to return
      # Promises.
      def async?
        false
      end

      # Find the root for this model
      def root_model
        node = @model

        loop do
          parent = node.parent
          if parent
            node = parent
          else
            break
          end
        end

        node
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
volt-0.9.6 lib/volt/models/persistors/base.rb
volt-0.9.6.pre3 lib/volt/models/persistors/base.rb
volt-0.9.6.pre2 lib/volt/models/persistors/base.rb
volt-0.9.6.pre1 lib/volt/models/persistors/base.rb
volt-0.9.5 lib/volt/models/persistors/base.rb
volt-0.9.5.pre12 lib/volt/models/persistors/base.rb
volt-0.9.5.pre11 lib/volt/models/persistors/base.rb
volt-0.9.5.pre9 lib/volt/models/persistors/base.rb
volt-0.9.5.pre8 lib/volt/models/persistors/base.rb
volt-0.9.5.pre7 lib/volt/models/persistors/base.rb
volt-0.9.5.pre6 lib/volt/models/persistors/base.rb
volt-0.9.5.pre5 lib/volt/models/persistors/base.rb
volt-0.9.5.pre4 lib/volt/models/persistors/base.rb
volt-0.9.5.pre3 lib/volt/models/persistors/base.rb
volt-0.9.5.pre2 lib/volt/models/persistors/base.rb
volt-0.9.5.pre1 lib/volt/models/persistors/base.rb
volt-0.9.4 lib/volt/models/persistors/base.rb
volt-0.9.4.pre5 lib/volt/models/persistors/base.rb