lib/thingfish/metastore/pggraph.rb
changeset 3 5b4ee98d698c
parent 1 60b437614edd
child 7 f0ef12e25a2f
equal deleted inserted replaced
2:58b5d17f0d53 3:5b4ee98d698c
    22 	# Load Sequel extensions/plugins
    22 	# Load Sequel extensions/plugins
    23 	Sequel.extension :migration
    23 	Sequel.extension :migration
    24 
    24 
    25 
    25 
    26 	# Package version
    26 	# Package version
    27 	VERSION = '0.1.0'
    27 	VERSION = '0.1.1'
    28 
    28 
    29 	# Version control revision
    29 	# Version control revision
    30 	REVISION = %q$Revision$
    30 	REVISION = %q$Revision$
    31 
    31 
    32 	# The data directory that contains migration files.
    32 	# The data directory that contains migration files.
   173 
   173 
   174 	### Fetch the value of the metadata associated with the given +key+ for the
   174 	### Fetch the value of the metadata associated with the given +key+ for the
   175 	### specified +oid+.
   175 	### specified +oid+.
   176 	def fetch_value( oid, key )
   176 	def fetch_value( oid, key )
   177 		metadata = self.model[ oid ] or return nil
   177 		metadata = self.model[ oid ] or return nil
   178 		return metadata.send( key )
   178 		key = key.to_sym
       
   179 		return metadata[ key ] || metadata.user_metadata[ key ]
   179 	end
   180 	end
   180 
   181 
   181 
   182 
   182 	### Fetch UUIDs related to the given +oid+.
   183 	### Fetch UUIDs related to the given +oid+.
   183 	def fetch_related_oids( oid )
   184 	def fetch_related_oids( oid )
   197 		ds = self.omit_related_resources( ds, options )
   198 		ds = self.omit_related_resources( ds, options )
   198 		ds = self.apply_search_criteria( ds, options )
   199 		ds = self.apply_search_criteria( ds, options )
   199 		ds = self.apply_search_order( ds, options )
   200 		ds = self.apply_search_order( ds, options )
   200 		ds = self.apply_search_direction( ds, options )
   201 		ds = self.apply_search_direction( ds, options )
   201 		ds = self.apply_search_limit( ds, options )
   202 		ds = self.apply_search_limit( ds, options )
       
   203 
       
   204 		self.log.debug "Dataset for search is: %s" % [ ds.sql ]
   202 
   205 
   203 		return ds.map {|row| row[:id] }
   206 		return ds.map {|row| row[:id] }
   204 	end
   207 	end
   205 
   208 
   206 
   209 
   274 	### Apply the search :order from the specified +options+ to the collection in
   277 	### Apply the search :order from the specified +options+ to the collection in
   275 	### +ds+ and return the modified dataset.
   278 	### +ds+ and return the modified dataset.
   276 	def apply_search_order( ds, options )
   279 	def apply_search_order( ds, options )
   277 		if options[:order]
   280 		if options[:order]
   278 			columns = Array( options[:order] )
   281 			columns = Array( options[:order] )
   279 			ds = ds.order( columns.map(&:to_sym) )
   282 			self.log.debug "  ordering results by columns: %p" % [ columns ]
       
   283 			ds = ds.order_metadata( columns )
   280 		end
   284 		end
   281 
   285 
   282 		return ds
   286 		return ds
   283 	end
   287 	end
   284 
   288