Sha256: b855fd218bb4fbea196651fdbd230735ce3784de7d42774f97481d39341c8e35

Contents?: true

Size: 663 Bytes

Versions: 4

Compression:

Stored size: 663 Bytes

Contents

module Troo
  module Persistence
    module ClassMethods
      def for(resource, options = {})
        new(resource, options).persist
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

    def persist
      return local   if local_identical?
      return updated if local_exists?
      return created
    end

    private

    def updated
      local.update(remote) && local
    end

    def local_identical?
      return false unless local_exists?
      return false if local_data != remote
      true
    end

    def local_data
      local.external_attributes
    end

    def local_exists?
      !!local
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
troo-0.0.7 lib/troo/models/persistence.rb
troo-0.0.6 lib/troo/models/persistence.rb
troo-0.0.5 lib/troo/models/persistence.rb
troo-0.0.4 lib/troo/models/persistence.rb