Sha256: 88e8faf3b09b57e185fb3bc9e267a78d9be4ced953ad5e26ac119d84a204951b

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

module Troo
  module RemoteModelHelpers
    module ClassMethods
      # @param  [Array]
      # @return [Array]
      def with_collection(resources = [])
        resources.map { |resource| new(resource) }
      end

      # @return [Hash]
      def all
        {}
      end

      # @return [Hash]
      def by_board_id
        {}
      end

      # @return [Hash]
      def by_list_id
        {}
      end

      # @return [Hash]
      def by_card_id
        {}
      end

      # @return [Hash]
      def by_member_id
        {}
      end
    end

    module InstanceMethods
      # @return []
      def preprocess
        associations.map do |association|
          associated(association).map { |record| record.preprocess }
        end

        Persistence::Local.persist(self)
      end

      # @return [Ohm::Model]
      def local
        @local ||= local_model.by_external_id(id)
      end

      private

      def associated(association)
        Array(send(association))
      end
    end

    def self.included(receiver)
      receiver.extend(ClassMethods)
      receiver.send(:include, InstanceMethods)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
troo-0.0.15 lib/troo/helpers/remote_model_helpers.rb
troo-0.0.14 lib/troo/helpers/remote_model_helpers.rb
troo-0.0.13 lib/troo/helpers/remote_model_helpers.rb
troo-0.0.12 lib/troo/helpers/remote_model_helpers.rb
troo-0.0.11 lib/troo/helpers/remote_model_helpers.rb