Sha256: 8ef4b774dd8a515073f0b0a99ede03e50cec68bfbbc9b4dd1f6a22e97884450e

Contents?: true

Size: 1005 Bytes

Versions: 3

Compression:

Stored size: 1005 Bytes

Contents

module Iowa
	class Association
	
		def initialize(association)
			@association = association
		end

		def association
			@association
		end

		def test(object)
			true
		end
	end

	class PathAssociation < Association
		def get(object,cache = false)
			myval = object.cached_associations[@association]
			if cache
				usecache = true
				usecache = false unless myval
				if myval.respond_to?(:empty?)
					usecache = false if myval.empty?
				end
			end
			if cache and usecache
				myval
			else
				object.cached_associations[@association] = object.valueForKeyPath(@association)
			end
		end
	
		def set(object, val)
			object.takeValueForKeyPath(val, @association)
		end

		def test(object)
			object.existsKeyPath?(@association)
		end
	end

	class LiteralAssociation < Association

		def get(object = nil, cache = false)
			unless @association.is_a?(Proc)
				@association
			else
				@association.call(object.send(:binding))
			end
		end
	
		def set(object, val)
			@association = val
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
IOWA-1.0.3 microprojects/LRUCache/src/iowa/Association.rb
IOWA-1.0.2 microprojects/LRUCache/src/iowa/Association.rb
IOWA-1.0.0 microprojects/LRUCache/src/iowa/Association.rb