Sha256: 97c50ee9e9bfd95c30ed776db77126158494425276457f8e57d439d16d04fd00

Contents?: true

Size: 742 Bytes

Versions: 7

Compression:

Stored size: 742 Bytes

Contents

# frozen_string_literal: true

class Acfs::Resource
  # Provides method to check for loading state of resources.
  # A resource that is created but not yet fetched will be loaded
  # after running {Acfs::Global#run Acfs.run}.
  #
  # @example
  #   user = User.find 5
  #   user.loaded? # => false
  #   Acfs.run
  #   user.loaded? # => true
  #
  module Loadable
    extend ActiveSupport::Concern

    # @api public
    #
    # Check if model is loaded or if request is still queued.
    #
    # @return [Boolean] True if resource is loaded, false otherwise.
    #
    def loaded?
      @loaded.nil? ? false : @loaded
    end

    # @api private
    #
    # Mark model as loaded.
    #
    def loaded!
      @loaded = true
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
acfs-2.0.0 lib/acfs/resource/loadable.rb
acfs-1.7.0 lib/acfs/resource/loadable.rb
acfs-1.6.0 lib/acfs/resource/loadable.rb
acfs-1.5.1 lib/acfs/resource/loadable.rb
acfs-1.5.0 lib/acfs/resource/loadable.rb
acfs-1.4.0 lib/acfs/resource/loadable.rb
acfs-1.3.4 lib/acfs/resource/loadable.rb