class SakaiInfo::Tool
Attributes
dbrow[R]
layout[R]
order[R]
page_id[R]
registration[R]
site_id[R]
title[R]
Public Class Methods
clear_cache()
click to toggle source
# File lib/sakai-info/tool.rb, line 16 def self.clear_cache @@cache = {} end
count_by_page_id(page_id)
click to toggle source
# File lib/sakai-info/tool.rb, line 37 def self.count_by_page_id(page_id) Tool.query_by_page_id(page_id).count end
find(id)
click to toggle source
# File lib/sakai-info/tool.rb, line 21 def self.find(id) if @@cache[id].nil? row = DB.connect[:sakai_site_tool].where(:tool_id => id).first if row.nil? raise ObjectNotFoundException.new(Tool, id) end @@cache[id] = Tool.new(row) end @@cache[id] end
find_by_page_id(page_id)
click to toggle source
# File lib/sakai-info/tool.rb, line 41 def self.find_by_page_id(page_id) Tool.query_by_page_id(page_id).order(:page_order).all. collect { |row| @@cache[row[:tool_id]] = Tool.new(row) } end
new(dbrow)
click to toggle source
# File lib/sakai-info/tool.rb, line 46 def initialize(dbrow) @dbrow = dbrow @id = dbrow[:tool_id] @title = dbrow[:title] @registration = dbrow[:registration] @order = dbrow[:page_order].to_i @layout = dbrow[:layout_hints] @page_id = dbrow[:page_id] @site_id = dbrow[:site_id] end
query_by_page_id(page_id)
click to toggle source
# File lib/sakai-info/tool.rb, line 33 def self.query_by_page_id(page_id) DB.connect[:sakai_site_tool].where(:page_id => page_id) end
Public Instance Methods
default_serialization()
click to toggle source
serialization
# File lib/sakai-info/tool.rb, line 71 def default_serialization result = { "id" => self.id, "registration" => self.registration, "title" => self.title, "site" => self.site.serialize(:summary), "page_id" => self.page_id, "order" => self.order, "layout" => self.layout, "properties" => self.properties } if result["properties"] == {} result.delete("properties") end if result["layout"].nil? result.delete("layout") end result end
page()
click to toggle source
# File lib/sakai-info/tool.rb, line 58 def page @page ||= Page.find(@page_id) end
properties()
click to toggle source
# File lib/sakai-info/tool.rb, line 66 def properties @properties ||= ToolProperty.find_by_tool_id(@id) end
site()
click to toggle source
# File lib/sakai-info/tool.rb, line 62 def site @site ||= Site.find(@site_id) end
summary_serialization()
click to toggle source
# File lib/sakai-info/tool.rb, line 91 def summary_serialization { "id" => self.id, "registration" => self.registration, "title" => self.title } end