Sha256: f6fd0e562a4b3cd13f379d24d6910b1d5da7826ce45abbd8fb695272f9af020d

Contents?: true

Size: 666 Bytes

Versions: 14

Compression:

Stored size: 666 Bytes

Contents

module Rubyfocus
	module IDRef
		module ClassMethods
			def idref *names
				names.each do |name|
					name_id = "#{name}_id".to_sym
					attr_accessor name_id
					define_method(name) do
						return document && (id_value = send(name_id)) && document.find(id_value)
					end

					define_method("#{name}=") do |o|
						if o.nil?
							self.send("#{name}_id=", nil)
						elsif o.respond_to?(:id)
							self.send("#{name}_id=", o.id)
						else
							raise ArgumentError, "#{self.class}##{name}= called with argument #{o}, which does not respond to :id."
						end
					end
				end
			end
		end

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rubyfocus-0.5.16 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.15 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.14 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.13 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.12 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.11 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.9 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.6 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.5 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.4 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.3 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.2 lib/rubyfocus/includes/idref.rb
rubyfocus-0.5.1 lib/rubyfocus/includes/idref.rb
rubyfocus-0.4.0 lib/rubyfocus/includes/idref.rb