Sha256: 81caf3a7989a79d7fcbfb147c75ff69aa399967fd86dd5bd2b707f8cb2c579c8

Contents?: true

Size: 695 Bytes

Versions: 16

Compression:

Stored size: 695 Bytes

Contents

module Shamu
  module Services

    # Lazily look up an associated resource
    class LazyAssociation < Delegator

      # ============================================================================
      # @!group Attributes
      #

      # @!attribute
      # @return [Object] the primary key id of the association. Not delegated so
      #     it is safe to use and will not trigger an unnecessary fetch.
      attr_reader :id

      #
      # @!endgroup Attributes

      def initialize( id, &block )
        @id = id
        @block = block
      end

      def __getobj__
        return @association if defined? @association

        @association = @block.call
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
shamu-0.0.21 lib/shamu/services/lazy_association.rb
shamu-0.0.20 lib/shamu/services/lazy_association.rb
shamu-0.0.19 lib/shamu/services/lazy_association.rb
shamu-0.0.18 lib/shamu/services/lazy_association.rb
shamu-0.0.17 lib/shamu/services/lazy_association.rb
shamu-0.0.15 lib/shamu/services/lazy_association.rb
shamu-0.0.14 lib/shamu/services/lazy_association.rb
shamu-0.0.13 lib/shamu/services/lazy_association.rb
shamu-0.0.11 lib/shamu/services/lazy_association.rb
shamu-0.0.9 lib/shamu/services/lazy_association.rb
shamu-0.0.8 lib/shamu/services/lazy_association.rb
shamu-0.0.7 lib/shamu/services/lazy_association.rb
shamu-0.0.5 lib/shamu/services/lazy_association.rb
shamu-0.0.4 lib/shamu/services/lazy_association.rb
shamu-0.0.3 lib/shamu/services/lazy_association.rb
shamu-0.0.2 lib/shamu/services/lazy_association.rb