Merged master
[arvados.git] / services / api / app / models / arvados_model.rb
index 8ffd8819ea0ad35d8840d1ef3c05f5f6270dd45b..493cf828d165abaf6f6163daae6d714d0e8b8c8f 100644 (file)
@@ -32,16 +32,21 @@ class ArvadosModel < ActiveRecord::Base
   end
 
   def self.kind_class(kind)
-    kind.match(/^arvados\#(.+?)(_list|List)?$/)[1].pluralize.classify.constantize rescue nil
+    kind.match(/^arvados\#(.+)$/)[1].classify.safe_constantize rescue nil
   end
 
   def href
     "#{current_api_base}/#{self.class.to_s.pluralize.underscore}/#{self.uuid}"
   end
 
-  def self.searchable_columns
+  def self.searchable_columns operator
+    textonly_operator = !operator.match(/[<=>]/)
     self.columns.collect do |col|
-      if [:string, :text, :datetime, :integer].index(col.type) && col.name != 'owner_uuid'
+      if col.name == 'owner_uuid'
+        nil
+      elsif [:string, :text].index(col.type)
+        col.name
+      elsif !textonly_operator and [:datetime, :integer].index(col.type)
         col.name
       end
     end.compact
@@ -51,18 +56,18 @@ class ArvadosModel < ActiveRecord::Base
     self.columns.select { |col| col.name == attr.to_s }.first
   end
 
-  def eager_load_associations
-    self.class.columns.each do |col|
-      re = col.name.match /^(.*)_kind$/
-      if (re and
-          self.respond_to? re[1].to_sym and
-          (auuid = self.send((re[1] + '_uuid').to_sym)) and
-          (aclass = self.class.kind_class(self.send(col.name.to_sym))) and
-          (aobject = aclass.where('uuid=?', auuid).first))
-        self.instance_variable_set('@'+re[1], aobject)
-      end
-    end
-  end
+  def eager_load_associations
+    self.class.columns.each do |col|
+      re = col.name.match /^(.*)_kind$/
+      if (re and
+          self.respond_to? re[1].to_sym and
+          (auuid = self.send((re[1] + '_uuid').to_sym)) and
+          (aclass = self.class.kind_class(self.send(col.name.to_sym))) and
+          (aobject = aclass.where('uuid=?', auuid).first))
+        self.instance_variable_set('@'+re[1], aobject)
+      end
+    end
+  end
 
   def self.readable_by user
     uuid_list = [user.uuid, *user.groups_i_can(:read)]
@@ -195,11 +200,15 @@ class ArvadosModel < ActiveRecord::Base
         if k.respond_to?(:uuid_prefix)
           @@prefixes_hash[k.uuid_prefix] = k
         end
-      end      
+      end
     end
     @@prefixes_hash
   end
 
+  def self.uuid_like_pattern
+    "_____-#{uuid_prefix}-_______________"
+  end
+
   def ensure_valid_uuids
     specials = [system_user_uuid, 'd41d8cd98f00b204e9800998ecf8427e+0']