Class: SakaiInfo::Tool
- Inherits:
-
SakaiObject
- Object
- SakaiObject
- SakaiInfo::Tool
- Defined in:
- lib/sakai-info/tool.rb
Instance Attribute Summary collapse
-
#dbrow ⇒ Object
readonly
Returns the value of attribute dbrow.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#page_id ⇒ Object
readonly
Returns the value of attribute page_id.
-
#registration ⇒ Object
readonly
Returns the value of attribute registration.
-
#site_id ⇒ Object
readonly
Returns the value of attribute site_id.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Attributes inherited from SakaiObject
Class Method Summary collapse
- .clear_cache ⇒ Object
- .count_by_page_id(page_id) ⇒ Object
- .find(id) ⇒ Object
- .find_by_page_id(page_id) ⇒ Object
- .query_by_page_id(page_id) ⇒ Object
Instance Method Summary collapse
-
#default_serialization ⇒ Object
serialization.
-
#initialize(dbrow) ⇒ Tool
constructor
A new instance of Tool.
- #page ⇒ Object
- #properties ⇒ Object
- #site ⇒ Object
- #summary_serialization ⇒ Object
Methods inherited from SakaiObject
all_serializations, #dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml
Constructor Details
#initialize(dbrow) ⇒ Tool
Returns a new instance of Tool.
46 47 48 49 50 51 52 53 54 55 56 |
# 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 |
Instance Attribute Details
#dbrow ⇒ Object (readonly)
Returns the value of attribute dbrow.
14 15 16 |
# File 'lib/sakai-info/tool.rb', line 14 def dbrow @dbrow end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
14 15 16 |
# File 'lib/sakai-info/tool.rb', line 14 def layout @layout end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
14 15 16 |
# File 'lib/sakai-info/tool.rb', line 14 def order @order end |
#page_id ⇒ Object (readonly)
Returns the value of attribute page_id.
14 15 16 |
# File 'lib/sakai-info/tool.rb', line 14 def page_id @page_id end |
#registration ⇒ Object (readonly)
Returns the value of attribute registration.
14 15 16 |
# File 'lib/sakai-info/tool.rb', line 14 def registration @registration end |
#site_id ⇒ Object (readonly)
Returns the value of attribute site_id.
14 15 16 |
# File 'lib/sakai-info/tool.rb', line 14 def site_id @site_id end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
14 15 16 |
# File 'lib/sakai-info/tool.rb', line 14 def title @title end |
Class Method Details
.clear_cache ⇒ Object
16 17 18 |
# File 'lib/sakai-info/tool.rb', line 16 def self.clear_cache @@cache = {} end |
.count_by_page_id(page_id) ⇒ Object
37 38 39 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
41 42 43 44 |
# 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 |
Instance Method Details
#default_serialization ⇒ Object
serialization
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# 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 ⇒ Object
58 59 60 |
# File 'lib/sakai-info/tool.rb', line 58 def page @page ||= Page.find(@page_id) end |
#properties ⇒ Object
66 67 68 |
# File 'lib/sakai-info/tool.rb', line 66 def properties @properties ||= ToolProperty.find_by_tool_id(@id) end |
#site ⇒ Object
62 63 64 |
# File 'lib/sakai-info/tool.rb', line 62 def site @site ||= Site.find(@site_id) end |
#summary_serialization ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/sakai-info/tool.rb', line 91 def summary_serialization { "id" => self.id, "registration" => self.registration, "title" => self.title } end |