Module: KnowledgeBaseRESTHelpers
- Defined in:
- lib/rbbt/rest/knowledge_base/locate.rb,
lib/rbbt/rest/knowledge_base/render.rb,
lib/rbbt/rest/knowledge_base/helpers.rb
Class Attribute Summary collapse
-
.knowledge_base_dir ⇒ Object
Returns the value of attribute knowledge_base_dir.
-
.syndications ⇒ Object
Returns the value of attribute syndications.
Class Method Summary collapse
Instance Method Summary collapse
- #association_render(pair, database = nil) ⇒ Object
- #association_resources ⇒ Object
- #association_table(associations = nil, options = {}, &block) ⇒ Object
- #get_knowledge_base(name = :user, namespace = nil) ⇒ Object
- #get_matrix(code) ⇒ Object
- #locate_association_template(database) ⇒ Object
- #locate_association_template_from_resource(resource, database = nil) ⇒ Object
- #prepare_entities_for_json(entities) ⇒ Object
- #serialize_entities(obj) ⇒ Object
- #user_kb(user = nil) ⇒ Object
Class Attribute Details
.knowledge_base_dir ⇒ Object
Returns the value of attribute knowledge_base_dir.
7 8 9 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 7 def knowledge_base_dir @knowledge_base_dir end |
.syndications ⇒ Object
Returns the value of attribute syndications.
7 8 9 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 7 def @syndications end |
Class Method Details
.add_syndication(name, kb) ⇒ Object
9 10 11 12 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 9 def (name, kb) @syndications ||= {} @syndications[name] = kb end |
.association_resources ⇒ Object
3 4 5 |
# File 'lib/rbbt/rest/knowledge_base/locate.rb', line 3 def self.association_resources @association_resources ||= [] end |
Instance Method Details
#association_render(pair, database = nil) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/rbbt/rest/knowledge_base/render.rb', line 7 def association_render(pair, database = nil) database ||= pair.database template_file = locate_association_template(database) locals = {:pair => pair, :database => database} render(template_file, locals, nil) end |
#association_resources ⇒ Object
7 8 9 |
# File 'lib/rbbt/rest/knowledge_base/locate.rb', line 7 def association_resources [Rbbt.share.views.find(:lib)] + KnowledgeBaseRESTHelpers.association_resources end |
#association_table(associations = nil, options = {}, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 76 def association_table(associations = nil, = {}, &block) = Misc.add_defaults , :row_ids => :consume, :footer => true associations = yield if block_given? tsv = case associations when Array associations.tsv when TSV associations else TSV.open(tsv) end tsv = tsv.to_double{|v| v.nil? ? nil : v.split(";;") } unless tsv.fields.nil? or tsv.fields.empty? or tsv.type == :double tsv2html tsv, end |
#get_knowledge_base(name = :user, namespace = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 59 def get_knowledge_base(name=:user, namespace = nil) kb = case name.to_s when 'step' step_path = [:step_path] step_path = params[:step_path] if step_path.nil? raise "No step_path" if step_path.nil? step = Workflow.fast_load_step(step_path) step.knowledge_base when "user" user_kb(user) else Genomics.knowledge_base end (namespace and namespace != kb.namespace) ? kb.version(namespace) : kb end |
#get_matrix(code) ⇒ Object
105 106 107 108 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 105 def get_matrix(code) name, study = code.split("@") Study.setup(study).matrix(name) end |
#locate_association_template(database) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rbbt/rest/knowledge_base/locate.rb', line 27 def locate_association_template(database) association_resources.each do |resource| path = locate_association_template_from_resource(resource, database) return path if path and path.exists? end association_resources.each do |resource| path = locate_association_template_from_resource(resource, "Default") return path if path and path.exists? end raise "Template not found for association database: #{ Misc.fingerprint database }" end |
#locate_association_template_from_resource(resource, database = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rbbt/rest/knowledge_base/locate.rb', line 11 def locate_association_template_from_resource(resource, database = nil) if database == "Default" path = resource.association["Default.haml"] if path.exists? return path else return nil end end path = resource.association[database + '.haml'] return path if path.exists? nil end |
#prepare_entities_for_json(entities) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 21 def prepare_entities_for_json(entities) case entities when AnnotatedArray list_hash(entities) when Array entities.inject([]){|acc,e| acc << prepare_entities_for_json(e); acc } when Hash hash = {} entities.each do |key,values| hash[key] = prepare_entities_for_json(values) end hash when String entities end end |
#serialize_entities(obj) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 94 def serialize_entities(obj) case obj when Array obj.collect{|e| serialize_entities(e)} when String e = obj name = e.respond_to?(:name) ? e.name || e : e {:id => e, :name => name, :type => e.base_type, :info => e.info} end end |
#user_kb(user = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rbbt/rest/knowledge_base/helpers.rb', line 38 def user_kb(user = nil) user ||= @user @@user_kbs ||= {} @@user_kbs[user] ||= begin dir = KnowledgeBaseRESTHelpers.knowledge_base_dir.users.common kb = KnowledgeBase.new(dir, Organism.default_code("Hsa")) KnowledgeBaseRESTHelpers..each do |name, new| Log.low "Syndicating database #{ name } for user #{user}" kb.syndicate name, new end if KnowledgeBaseRESTHelpers..any? user_studies[user].each do |study| Study.setup(study) kb.syndicate study, study.knowledge_base end if defined? user_studies kb end end |